diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 46b338d2419..f298a5d415d 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -86,6 +86,20 @@ data class DokkaSourceSetID( fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(json) +/** + * Global options are applied to all packages and modules and overwrite package configuration. + * + * These are handy if we have multiple sourcesets sharing the same global options as it reduces the size of the boilerplate. + * Otherwise, the user would be enforced to repeat all these options per each sourceset. + */ +data class GlobalDokkaConfiguration( + val perPackageOptions: List?, + val externalDocumentationLinks: List?, + val sourceLinks: List? +) + +fun GlobalDokkaConfiguration(json: String): GlobalDokkaConfiguration = parseJson(json) + fun DokkaConfiguration.toJsonString(): String = toJsonString(this) fun T.toJsonString(): String = toJsonString(this) diff --git a/core/src/main/kotlin/utilities/json.kt b/core/src/main/kotlin/utilities/json.kt index 211037d6c35..d3762f6d745 100644 --- a/core/src/main/kotlin/utilities/json.kt +++ b/core/src/main/kotlin/utilities/json.kt @@ -34,7 +34,6 @@ internal fun toJsonString(value: Any): String = objectMapper.writeValueAsString( @PublishedApi internal inline fun parseJson(json: String): T = parseJson(json, TypeReference()) - @PublishedApi internal fun parseJson(json: String, typeReference: TypeReference): T = objectMapper.readValue(json, typeReference.jackson) diff --git a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt index 4234e9b1473..b94df32a316 100644 --- a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt +++ b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt @@ -264,7 +264,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() { @Test - fun json() { + fun `should accept json as input configuration`() { val dokkaOutputDir = File(projectDir, "output") assertTrue(dokkaOutputDir.mkdirs()) val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!") @@ -303,7 +303,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() { * make sure that global settings apply to dokka context. */ @Test - fun jsonWithGlobals() { + fun `global settings should overwrite package options in configuration`() { val dokkaOutputDir = File(projectDir, "output") assertTrue(dokkaOutputDir.mkdirs()) val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!") diff --git a/plugins/all-modules-page/out/index.md b/plugins/all-modules-page/out/index.md deleted file mode 100644 index 5c9593f62f5..00000000000 --- a/plugins/all-modules-page/out/index.md +++ /dev/null @@ -1,10 +0,0 @@ -/ - -# Sample project - -Sample documentation with [external link](https://www.google.pl) - -## All modules: - -| Name | -|---| diff --git a/runners/cli/src/main/kotlin/cli/JsonMapperForCLI.kt b/runners/cli/src/main/kotlin/cli/JsonMapperForCLI.kt deleted file mode 100644 index 33bfd9fc041..00000000000 --- a/runners/cli/src/main/kotlin/cli/JsonMapperForCLI.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.jetbrains.dokka - -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.databind.DeserializationFeature -import com.fasterxml.jackson.databind.SerializerProvider -import com.fasterxml.jackson.databind.module.SimpleModule -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import java.io.File - -// THIS IS COPIED FROM BASE SINCE IT NEEDS TO BE INSTANTIATED ON THE SAME CLASS LOADER AS PLUGINS - -private val objectMapper = run { - val module = SimpleModule().apply { - addSerializer(FileSerializer) - } - jacksonObjectMapper() - .registerModule(module) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) -} - -@PublishedApi -internal class TypeReference private constructor( - internal val jackson: com.fasterxml.jackson.core.type.TypeReference -) { - companion object { - internal inline operator fun invoke(): TypeReference = TypeReference(jacksonTypeRef()) - } -} - -inline fun parseJson(json: String): T = parseJson(json, TypeReference()) - -@PublishedApi -internal fun parseJson(json: String, typeReference: TypeReference): T = - objectMapper.readValue(json, typeReference.jackson) - -private object FileSerializer : StdScalarSerializer(File::class.java) { - override fun serialize(value: File, g: JsonGenerator, provider: SerializerProvider) { - g.writeString(value.path) - } -} - -data class GlobalDokkaConfiguration( - val perPackageOptions: List?, - val externalDocumentationLinks: List?, - val sourceLinks: List? -) diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index e8b79146356..b5e1d2a3fdc 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -406,9 +406,9 @@ fun parseLinks(links: List): List { fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguration = if (globalArguments.json != null) { val jsonContent = Paths.get(checkNotNull(globalArguments.json)).toFile().readText() - val globals: GlobalDokkaConfiguration = parseJson(jsonContent) + val globals = GlobalDokkaConfiguration(jsonContent) val dokkaConfigurationImpl = DokkaConfigurationImpl(jsonContent) - dokkaConfigurationImpl.run { + dokkaConfigurationImpl.apply { sourceSets.forEach { it.perPackageOptions.cast>().addAll(globals.perPackageOptions ?: emptyList()) } @@ -425,7 +425,6 @@ fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguratio it.externalDocumentationLinks.cast>().addAll(defaultLinks(it)) } } - dokkaConfigurationImpl } else { globalArguments } diff --git a/runners/cli/src/test/kotlin/cli/CliTest.kt b/runners/cli/src/test/kotlin/cli/CliTest.kt index 4ed2e6dc472..5910e938712 100644 --- a/runners/cli/src/test/kotlin/cli/CliTest.kt +++ b/runners/cli/src/test/kotlin/cli/CliTest.kt @@ -3,13 +3,14 @@ package org.jetbrains.dokka import junit.framework.Assert.assertTrue import org.junit.Test import java.lang.IllegalStateException +import java.nio.file.Paths import kotlin.test.assertEquals class CliIntegrationTest { @Test - fun testGlobalArgs() { - val jsonPath = javaClass.getResource("/my-file.json")?.path ?: throw IllegalStateException("No JSON found!") + fun `should apply global settings to all source sets`() { + val jsonPath = Paths.get(javaClass.getResource("/my-file.json")?.toURI() ?: throw IllegalStateException("No JSON found!")).toFile().toString() val globalArguments = GlobalArguments(arrayOf(jsonPath)) val configuration = initializeConfiguration(globalArguments)