Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions dokka-aws/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
*/
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.LocalDate

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.kotlin.jvm)
}

Expand All @@ -18,6 +20,16 @@ description = "Custom Dokka plugin for AWS Kotlin SDK API docs"
dependencies {
compileOnly(libs.dokka.base)
compileOnly(libs.dokka.core)

testImplementation(libs.jsoup)
testImplementation(libs.junit.jupiter)
testImplementation(libs.kotest.assertions.core.jvm)
testImplementation(libs.kotlin.test.junit5)
}

tasks.test {
useJUnitPlatform()
dependsOn(tasks.dokkaHtml)
}

tasks.withType<KotlinCompile> {
Expand All @@ -31,3 +43,29 @@ tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}

tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
val sdkVersion: String by project
moduleVersion.set(sdkVersion)

val year = LocalDate.now().year
val pluginConfigMap = mapOf(
"org.jetbrains.dokka.base.DokkaBase" to """
{
"customStyleSheets": [
"${rootProject.file("docs/dokka-presets/css/logo-styles.css")}",
"${rootProject.file("docs/dokka-presets/css/aws-styles.css")}"
],
"customAssets": [
"${rootProject.file("docs/dokka-presets/assets/logo-icon.svg")}",
"${rootProject.file("docs/dokka-presets/assets/aws_logo_white_59x35.png")}",
"${rootProject.file("docs/dokka-presets/scripts/accessibility.js")}"
],
"footerMessage": "© $year, Amazon Web Services, Inc. or its affiliates. All rights reserved.",
"separateInheritedMembers" : true,
"templatesDir": "${rootProject.file("docs/dokka-presets/templates")}"
}
""",
)
pluginsMapConfiguration.set(pluginConfigMap)
}
55 changes: 55 additions & 0 deletions dokka-aws/src/test/kotlin/aws/sdk/kotlin/dokka/DokkaAwsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.dokka

import org.jsoup.Jsoup
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import java.io.File
import kotlin.test.assertTrue

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DokkaAwsTest {
val dokkaOutputDir = File("build/dokka")

@AfterAll
fun cleanup() {
if (dokkaOutputDir.exists()) {
try {
dokkaOutputDir.deleteRecursively()
println("Successfully deleted dokka folder")
} catch (e: Exception) {
println("Failed to delete dokka folder: ${e.message}")
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness: We shouldn't delete the docs after the test run. Firstly, they're created by Gradle and we shouldn't be messing with Gradle's scope during our tests. More importantly, it makes debugging failures pretty difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That make sense, I will remove cleanup part.
Btw the test not pass is because api ref doc analytic not merged yet.


@Test
fun testLoadScripts() {
val testFile = File("build/dokka/html/index.html")

assumeTrue(
testFile.exists(),
"Skipping test: test file does not exist",
)

val document = Jsoup.parse(testFile, "UTF-8")

val expectedScripts = listOf(
"awshome_s_code.js",
)

val scripts = document.head().select("script[src]")

expectedScripts.forEach { expectedScript ->
assertTrue(
scripts.any { it.attr("src").endsWith(expectedScript) },
"Expected script $expectedScript not found",
)
}
}
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kotlinx-benchmark-version = "0.4.12"
kotlinx-serialization-version = "1.7.3"
mockk-version = "1.13.13"
slf4j-version = "2.0.16"
jsoup-version = "1.19.1"

[libraries]
aws-kotlin-repo-tools-build-support = { module="aws.sdk.kotlin.gradle:build-support", version.ref = "aws-kotlin-repo-tools-version" }
Expand Down Expand Up @@ -111,6 +112,8 @@ smithy-aws-smoke-test-model = { module = "software.amazon.smithy:smithy-aws-smok
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-version" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-version" }

jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup-version" }

kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest-version" }
kotest-assertions-core-jvm = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest-version" }
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest-version" }
Expand Down
Loading