From 6b729257b89ff5a19a52045efa386349feec0bc6 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com> Date: Wed, 12 Jan 2022 15:04:59 +0100 Subject: Add global settings to JSON dokka cli input (#2292) * Add global settings to JSON dokka cli input * Apply requested changes * Move initialization of global arguments to extension function in core module --- core/src/main/kotlin/configuration.kt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'core/src/main/kotlin/configuration.kt') diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 46b338d2..038a5bb7 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import org.jetbrains.dokka.plugability.ConfigurableBlock +import org.jetbrains.dokka.utilities.cast import org.jetbrains.dokka.utilities.parseJson import org.jetbrains.dokka.utilities.toJsonString import java.io.File @@ -86,6 +87,34 @@ 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.apply(globals: GlobalDokkaConfiguration): DokkaConfiguration = this.apply { + sourceSets.forEach { + it.perPackageOptions.cast>().addAll(globals.perPackageOptions ?: emptyList()) + } + + sourceSets.forEach { + it.externalDocumentationLinks.cast>().addAll(globals.externalDocumentationLinks ?: emptyList()) + } + + sourceSets.forEach { + it.sourceLinks.cast>().addAll(globals.sourceLinks ?: emptyList()) + } +} + fun DokkaConfiguration.toJsonString(): String = toJsonString(this) fun T.toJsonString(): String = toJsonString(this) -- cgit