Skip to content

Commit

Permalink
Move initialization of global arguments to extension function in core…
Browse files Browse the repository at this point in the history
… module
  • Loading branch information
BarkingBad committed Jan 11, 2022
1 parent e7725ec commit 6b49872
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 15 additions & 0 deletions core/src/main/kotlin/configuration.kt
Expand Up @@ -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
Expand Down Expand Up @@ -100,6 +101,20 @@ data class GlobalDokkaConfiguration(

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)

Expand Down
13 changes: 1 addition & 12 deletions runners/cli/src/main/kotlin/cli/main.kt
Expand Up @@ -408,19 +408,8 @@ fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguratio
val jsonContent = Paths.get(checkNotNull(globalArguments.json)).toFile().readText()
val globals = GlobalDokkaConfiguration(jsonContent)
val dokkaConfigurationImpl = DokkaConfigurationImpl(jsonContent)
dokkaConfigurationImpl.apply {
sourceSets.forEach {
it.perPackageOptions.cast<MutableList<DokkaConfiguration.PackageOptions>>().addAll(globals.perPackageOptions ?: emptyList())
}

sourceSets.forEach {
it.externalDocumentationLinks.cast<MutableSet<ExternalDocumentationLink>>().addAll(globals.externalDocumentationLinks ?: emptyList())
}

sourceSets.forEach {
it.sourceLinks.cast<MutableSet<SourceLinkDefinitionImpl>>().addAll(globals.sourceLinks ?: emptyList())
}

dokkaConfigurationImpl.apply(globals).apply {
sourceSets.forEach {
it.externalDocumentationLinks.cast<MutableSet<ExternalDocumentationLink>>().addAll(defaultLinks(it))
}
Expand Down

0 comments on commit 6b49872

Please sign in to comment.