-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug utility for manually overriding the Dokka configuration JSON (
#3915) * Add debug utility for manually overriding the Dokka configuration JSON Being able to make minor manual modifications to the Dokka configuration is exceptionally useful for local debugging.
- Loading branch information
Showing
2 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/OverrideJsonConfigTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
package org.jetbrains.dokka.gradle | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.paths.shouldExist | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldContain | ||
import org.intellij.lang.annotations.Language | ||
import org.jetbrains.dokka.gradle.internal.DokkaConstants.DOKKA_VERSION | ||
import org.jetbrains.dokka.gradle.utils.* | ||
import kotlin.io.path.readText | ||
|
||
/** | ||
* Test [org.jetbrains.dokka.gradle.tasks.DokkaGenerateTask.overrideJsonConfig]. | ||
*/ | ||
class OverrideJsonConfigTest : FunSpec({ | ||
|
||
context("Json Config Override:") { | ||
val project = createProject() | ||
|
||
test("override works") { | ||
|
||
project.runner | ||
.addArguments( | ||
":dokkaGenerateModuleHtml", | ||
"--rerun", | ||
) | ||
.build { | ||
output shouldContain "w: [:dokkaGenerateModuleHtml] Overriding DokkaConfiguration with manualJsonConfig" | ||
|
||
val actualDokkaConfigJson = | ||
project.file("build/tmp/dokkaGenerateModuleHtml/dokka-configuration.json") | ||
|
||
actualDokkaConfigJson.shouldExist() | ||
actualDokkaConfigJson.readText() shouldBe dokkaConfOverrideJson | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private fun createProject(): GradleProjectTest = gradleKtsProjectTest("OverrideJsonConfigTest") { | ||
|
||
buildGradleKts = """ | ||
|plugins { | ||
| kotlin("jvm") version embeddedKotlinVersion | ||
| id("org.jetbrains.dokka") version "$DOKKA_VERSION" | ||
|} | ||
| | ||
|tasks.dokkaGenerateModuleHtml { | ||
| overrideJsonConfig.set( | ||
| providers.fileContents(layout.projectDirectory.file("dokka-config.json")).asText | ||
| ) | ||
|} | ||
| | ||
""".trimMargin() | ||
|
||
createKotlinFile("src/main/kotlin/Foo.kt", "class Foo") | ||
|
||
createFile("dokka-config.json", dokkaConfOverrideJson) | ||
} | ||
|
||
@Language("json") | ||
private val dokkaConfOverrideJson = """ | ||
|{ | ||
| "moduleName": "Overridden", | ||
| "moduleVersion": null, | ||
| "outputDir": "blah-blah-override-output", | ||
| "cacheRoot": null, | ||
| "offlineMode": false, | ||
| "sourceSets": [ | ||
| ], | ||
| "pluginsClasspath": [ | ||
| ], | ||
| "pluginsConfiguration": [ | ||
| ], | ||
| "modules": [ | ||
| ], | ||
| "failOnWarning": false, | ||
| "delayTemplateSubstitution": false, | ||
| "suppressObviousFunctions": true, | ||
| "includes": [ | ||
| ], | ||
| "suppressInheritedMembers": false, | ||
| "finalizeCoroutines": false | ||
|} | ||
""".trimMargin() |