aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/configuration.kt
diff options
context:
space:
mode:
authorAndrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com>2022-01-12 15:04:59 +0100
committerGitHub <noreply@github.com>2022-01-12 17:04:59 +0300
commit6b729257b89ff5a19a52045efa386349feec0bc6 (patch)
tree790ca1fc300466496dc18e045997d4818b7a50e1 /core/src/main/kotlin/configuration.kt
parentb30db0aeafd5663dce3d3020f3dde6599ec368f3 (diff)
downloaddokka-6b729257b89ff5a19a52045efa386349feec0bc6.tar.gz
dokka-6b729257b89ff5a19a52045efa386349feec0bc6.tar.bz2
dokka-6b729257b89ff5a19a52045efa386349feec0bc6.zip
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
Diffstat (limited to 'core/src/main/kotlin/configuration.kt')
-rw-r--r--core/src/main/kotlin/configuration.kt29
1 files changed, 29 insertions, 0 deletions
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<PackageOptionsImpl>?,
+ val externalDocumentationLinks: List<ExternalDocumentationLinkImpl>?,
+ val sourceLinks: List<SourceLinkDefinitionImpl>?
+)
+
+fun GlobalDokkaConfiguration(json: String): GlobalDokkaConfiguration = parseJson(json)
+
+fun DokkaConfiguration.apply(globals: GlobalDokkaConfiguration): DokkaConfiguration = this.apply {
+ sourceSets.forEach {
+ it.perPackageOptions.cast<MutableList<DokkaConfiguration.PackageOptions>>().addAll(globals.perPackageOptions ?: emptyList())
+ }
+
+ sourceSets.forEach {
+ it.externalDocumentationLinks.cast<MutableSet<DokkaConfiguration.ExternalDocumentationLink>>().addAll(globals.externalDocumentationLinks ?: emptyList())
+ }
+
+ sourceSets.forEach {
+ it.sourceLinks.cast<MutableSet<SourceLinkDefinitionImpl>>().addAll(globals.sourceLinks ?: emptyList())
+ }
+}
+
fun DokkaConfiguration.toJsonString(): String = toJsonString(this)
fun <T : ConfigurableBlock> T.toJsonString(): String = toJsonString(this)