Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkingBad committed Jan 7, 2022
1 parent 0ae0222 commit be5060c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 67 deletions.
4 changes: 1 addition & 3 deletions core/src/main/kotlin/utilities/json.kt
Expand Up @@ -31,9 +31,7 @@ internal class TypeReference<T> private constructor(
@PublishedApi
internal fun toJsonString(value: Any): String = objectMapper.writeValueAsString(value)

@PublishedApi
internal inline fun <reified T : Any> parseJson(json: String): T = parseJson(json, TypeReference())

inline fun <reified T : Any> parseJson(json: String): T = parseJson(json, TypeReference())

@PublishedApi
internal fun <T : Any> parseJson(json: String, typeReference: TypeReference<T>): T =
Expand Down
Expand Up @@ -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!")
Expand Down Expand Up @@ -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!")
Expand Down
10 changes: 0 additions & 10 deletions plugins/all-modules-page/out/index.md

This file was deleted.

48 changes: 0 additions & 48 deletions runners/cli/src/main/kotlin/cli/JsonMapperForCLI.kt

This file was deleted.

16 changes: 14 additions & 2 deletions runners/cli/src/main/kotlin/cli/main.kt
Expand Up @@ -404,11 +404,24 @@ fun parseLinks(links: List<String>): List<ExternalDocumentationLink> {
}
}


/**
* 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 initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguration = if (globalArguments.json != null) {
val jsonContent = Paths.get(checkNotNull(globalArguments.json)).toFile().readText()
val globals: GlobalDokkaConfiguration = parseJson(jsonContent)
val dokkaConfigurationImpl = DokkaConfigurationImpl(jsonContent)
dokkaConfigurationImpl.run {
dokkaConfigurationImpl.apply {
sourceSets.forEach {
it.perPackageOptions.cast<MutableList<DokkaConfiguration.PackageOptions>>().addAll(globals.perPackageOptions ?: emptyList())
}
Expand All @@ -425,7 +438,6 @@ fun initializeConfiguration(globalArguments: GlobalArguments): DokkaConfiguratio
it.externalDocumentationLinks.cast<MutableSet<ExternalDocumentationLink>>().addAll(defaultLinks(it))
}
}
dokkaConfigurationImpl
} else {
globalArguments
}
Expand Down
5 changes: 3 additions & 2 deletions runners/cli/src/test/kotlin/cli/CliTest.kt
Expand Up @@ -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)
Expand Down

0 comments on commit be5060c

Please sign in to comment.