From 2bc04cda14f5dc35e9e0593f4e574eb076f437d8 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Mon, 14 Feb 2022 18:52:51 +0100 Subject: [PATCH] Fix loading empty properties by CLI json parser. --- core/src/main/kotlin/defaultConfiguration.kt | 6 +++--- runners/cli/src/main/kotlin/cli/main.kt | 2 +- runners/cli/src/test/kotlin/cli/CliTest.kt | 13 +++++++++++++ .../resources/my-file-no-sourceset-options.json | 13 +++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 runners/cli/src/test/resources/my-file-no-sourceset-options.json diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index d4f92f3341..3ab1782c79 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -42,9 +42,9 @@ data class DokkaSourceSetImpl( override val skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages, override val skipDeprecated: Boolean = DokkaDefaults.skipDeprecated, override val jdkVersion: Int = DokkaDefaults.jdkVersion, - override val sourceLinks: Set = emptySet(), - override val perPackageOptions: List = emptyList(), - override val externalDocumentationLinks: Set = emptySet(), + override val sourceLinks: Set = mutableSetOf(), + override val perPackageOptions: List = mutableListOf(), + override val externalDocumentationLinks: Set = mutableSetOf(), override val languageVersion: String? = null, override val apiVersion: String? = null, override val noStdlibLink: Boolean = DokkaDefaults.noStdlibLink, diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 4768828b89..c2a68d68bf 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -288,7 +288,7 @@ private fun parseSourceSet(moduleName: String, args: Array): DokkaConfig override val jdkVersion = jdkVersion override val sourceLinks = sourceLinks.toMutableSet() override val analysisPlatform = analysisPlatform - override val perPackageOptions = parsePerPackageOptions(perPackageOptions) + override val perPackageOptions = parsePerPackageOptions(perPackageOptions).toMutableList() override val externalDocumentationLinks = parseLinks(externalDocumentationLinks).toMutableSet() override val languageVersion = languageVersion override val apiVersion = apiVersion diff --git a/runners/cli/src/test/kotlin/cli/CliTest.kt b/runners/cli/src/test/kotlin/cli/CliTest.kt index 5910e93871..967003dca8 100644 --- a/runners/cli/src/test/kotlin/cli/CliTest.kt +++ b/runners/cli/src/test/kotlin/cli/CliTest.kt @@ -27,4 +27,17 @@ class CliIntegrationTest { } + @Test + fun `should not fail when no sourceset options are specified`() { + val jsonPath = Paths.get(javaClass.getResource("/my-file-no-sourceset-options.json")?.toURI() ?: throw IllegalStateException("No JSON found!")).toFile().toString() + val globalArguments = GlobalArguments(arrayOf(jsonPath)) + + val configuration = initializeConfiguration(globalArguments) + + configuration.sourceSets.forEach { + assertTrue(it.perPackageOptions.isEmpty()) + assertTrue(it.sourceLinks.isEmpty()) + assertTrue(it.externalDocumentationLinks.size == 2) // there are default values, java and kotlin stdlibs + } + } } diff --git a/runners/cli/src/test/resources/my-file-no-sourceset-options.json b/runners/cli/src/test/resources/my-file-no-sourceset-options.json new file mode 100644 index 0000000000..3a8643d1fd --- /dev/null +++ b/runners/cli/src/test/resources/my-file-no-sourceset-options.json @@ -0,0 +1,13 @@ +{ + "outputDir": "build/docs", + "sourceSets": [ + { + "moduleDisplayName": "Sample", + "sourceSetID": { + "scopeId": "sample", + "sourceSetName": "main" + }, + "sourceRoots": ["sample"] + } + ] +}