From 8cd28416817dfd7d28bb66b28e849d97cc09012b Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 27 Aug 2020 15:50:40 +0200 Subject: Let module name be configurable withing `AbstractDokkaTask` and remove concept of `moduleDisplayName` --- README.md | 4 +- core/src/main/kotlin/configuration.kt | 8 +-- core/src/main/kotlin/defaultConfiguration.kt | 4 +- core/src/main/kotlin/model/CompositeSourceSetID.kt | 2 +- .../kotlin/utilities/DokkaConfigurationJsonTest.kt | 8 +-- .../testRunner/TestDokkaConfigurationBuilder.kt | 39 ++++++++------ .../jetbrains/dokka/it/cli/CliIntegrationTest.kt | 3 +- .../gradle/projects/it-basic/build.gradle.kts | 2 +- .../dokka/it/gradle/BasicGradleIntegrationTest.kt | 2 +- integration-tests/maven/projects/it-maven/pom.xml | 2 +- .../kotlin/allModulePage/MultimodulePageCreator.kt | 1 - .../parseModuleAndPackageDocumentationFragments.kt | 4 +- .../documentables/DefaultDocumentableMerger.kt | 25 ++++----- .../DeprecatedDocumentableFilterTransformer.kt | 2 +- .../ModuleAndPackageDocumentationReader.kt | 6 +-- .../pages/samples/SamplesTransformer.kt | 6 +-- .../DefaultDescriptorToDocumentableTranslator.kt | 31 ++++++++--- .../psi/DefaultPsiToDocumentableTranslator.kt | 2 +- .../kotlin/linkableContent/LinkableContentTest.kt | 10 ++-- ...seModuleAndPackageDocumentationFragmentsTest.kt | 33 +++++++----- .../renderers/html/HtmlRenderingOnlyTestBase.kt | 3 -- .../renderers/html/SourceSetDependentHintTest.kt | 3 -- .../kotlin/signatures/DivergentSignatureTest.kt | 14 ++--- .../src/test/kotlin/signatures/SignatureTest.kt | 3 +- ...textModuleAndPackageDocumentationReaderTest1.kt | 49 +++++++---------- ...textModuleAndPackageDocumentationReaderTest2.kt | 63 ---------------------- ...textModuleAndPackageDocumentationReaderTest3.kt | 15 +++--- ...ackageDocumentationTransformerFunctionalTest.kt | 4 +- .../ReportUndocumentedTransformerTest.kt | 6 +-- .../src/test/kotlin/renderers/gfm/DivergentTest.kt | 3 -- .../renderers/gfm/GfmRenderingOnlyTestBase.kt | 2 +- .../renderers/gfm/SourceSetDependentHintTest.kt | 3 -- runners/cli/src/main/kotlin/cli/main.kt | 39 +++++++------- runners/gradle-plugin/MIGRATION.md | 2 +- .../jetbrains/dokka/gradle/AbstractDokkaTask.kt | 4 ++ .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 1 + .../jetbrains/dokka/gradle/DokkaMultiModuleTask.kt | 4 +- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 3 +- .../dokka/gradle/GradleDokkaSourceSetBuilder.kt | 40 +++----------- .../GradleDokkaSourceSetBuilderExtensions.kt | 17 ++++++ .../gradle/GradleDokkaSourceSetBuilderFactory.kt | 9 ++++ .../dokka/gradle/dokkaSourceSetIDFactory.kt | 11 ++-- .../jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt | 6 --- .../gradle/ConfigureWithKotlinSourceSetGistTest.kt | 2 - .../dokka/gradle/DokkaCollectorTaskTest.kt | 2 + .../dokka/gradle/DokkaConfigurationJsonTest.kt | 1 - .../gradle/DokkaConfigurationSerializableTest.kt | 1 - .../dokka/gradle/DokkaMultiModuleTaskTest.kt | 2 + .../dokka/gradle/GradleDokkaSourceSetBuilder.kt | 11 ++++ .../gradle/GradleDokkaSourceSetBuilderTest.kt | 39 ++++---------- .../gradle/KotlinDslDokkaTaskConfigurationTest.kt | 6 +-- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 9 +--- 52 files changed, 246 insertions(+), 325 deletions(-) delete mode 100644 plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest2.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderExtensions.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderFactory.kt create mode 100644 runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt diff --git a/README.md b/README.md index 19aff3b6..ed2d38c2 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,6 @@ dokkaHtml { cacheRoot.set(file("default")) dokkaSourceSets { configureEach { // Or source set name, for single-platform the default source sets are `main` and `test` - moduleDisplayName.set("data") // Used when configuring source sets manually for declaring which source sets this one depends on dependsOn("otherSourceSetName") @@ -407,7 +406,7 @@ The available configuration options are shown below: false - data + data some/out/dir @@ -556,7 +555,6 @@ Dokka supports the following command line arguments: * `-globalSrcLink` - source links added to all source sets * `-sourceSet` - (repeatable) - configuration for a single source set. Following this argument, you can pass other arguments: * `-moduleName` - (required) - module name used as a part of source set ID when declaring dependent source sets - * `-moduleDisplayName` - displayed module name * `-sourceSetName` - source set name as a part of source set ID when declaring dependent source sets * `-displayName` - source set name displayed in the generated documentation * `-src` - list of source files or directories separated by `;` diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 2aa252e1..9a1ff602 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -9,6 +9,7 @@ import java.io.Serializable import java.net.URL object DokkaDefaults { + val moduleName: String = "root" val outputDir = File("./dokka") const val format: String = "html" val cacheRoot: File? = null @@ -58,12 +59,13 @@ interface DokkaConfigurationBuilder { fun Iterable>.build(): List = this.map { it.build() } + data class DokkaSourceSetID( - val moduleName: String, + val scopeId: String, val sourceSetName: String ) : Serializable { override fun toString(): String { - return "$moduleName/$sourceSetName" + return "$scopeId/$sourceSetName" } } @@ -72,6 +74,7 @@ fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(jso fun DokkaConfiguration.toJsonString(): String = toJsonString(this) interface DokkaConfiguration : Serializable { + val moduleName: String val outputDir: File val cacheRoot: File? val offlineMode: Boolean @@ -84,7 +87,6 @@ interface DokkaConfiguration : Serializable { interface DokkaSourceSet : Serializable { val sourceSetID: DokkaSourceSetID val displayName: String - val moduleDisplayName: String val classpath: List val sourceRoots: Set val dependentSourceSets: Set diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index 8bd2d976..3fcc7aac 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -5,6 +5,7 @@ import java.io.File import java.net.URL data class DokkaConfigurationImpl( + override val moduleName: String = DokkaDefaults.moduleName, override val outputDir: File = DokkaDefaults.outputDir, override val cacheRoot: File? = DokkaDefaults.cacheRoot, override val offlineMode: Boolean = DokkaDefaults.offlineMode, @@ -12,12 +13,11 @@ data class DokkaConfigurationImpl( override val pluginsClasspath: List = emptyList(), override val pluginsConfiguration: Map = emptyMap(), override val modules: List = emptyList(), - override val failOnWarning: Boolean = DokkaDefaults.failOnWarning + override val failOnWarning: Boolean = DokkaDefaults.failOnWarning, ) : DokkaConfiguration data class DokkaSourceSetImpl( - override val moduleDisplayName: String, override val displayName: String = DokkaDefaults.sourceSetDisplayName, override val sourceSetID: DokkaSourceSetID, override val classpath: List = emptyList(), diff --git a/core/src/main/kotlin/model/CompositeSourceSetID.kt b/core/src/main/kotlin/model/CompositeSourceSetID.kt index 3c1cf7de..9f38dafb 100644 --- a/core/src/main/kotlin/model/CompositeSourceSetID.kt +++ b/core/src/main/kotlin/model/CompositeSourceSetID.kt @@ -14,7 +14,7 @@ data class CompositeSourceSetID( } val merged = DokkaSourceSetID( - moduleName = children.map { it.moduleName }.reduce { acc, s -> "$acc+$s" }, + scopeId = children.map { it.scopeId }.reduce { acc, s -> "$acc+$s" }, sourceSetName = children.map { it.sourceSetName }.reduce { acc, s -> "$acc+$s" } ) diff --git a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt index 8efc84c6..ba33ab92 100644 --- a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt +++ b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt @@ -9,11 +9,11 @@ class DokkaConfigurationJsonTest { @Test fun `simple configuration toJsonString then parseJson`() { val configuration = DokkaConfigurationImpl( + moduleName = "moduleName", outputDir = File("customOutputDir"), pluginsClasspath = listOf(File("plugins/customPlugin.jar")), sourceSets = listOf( DokkaSourceSetImpl( - moduleDisplayName = "customModuleDisplayName", sourceRoots = setOf(File("customSourceRoot")), sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName") ) @@ -29,13 +29,13 @@ class DokkaConfigurationJsonTest { fun `parse simple configuration json`() { val json = """ { + "moduleName": "moduleName", "outputDir": "customOutputDir", "pluginsClasspath": [ "plugins/customPlugin.jar" ], "sourceSets": [ { - "moduleDisplayName": "customModuleDisplayName", "sourceSetID": { - "moduleName": "customModuleName", + "scopeId": "customModuleName", "sourceSetName": "customSourceSetName" }, "sourceRoots": [ "customSourceRoot" ], @@ -48,11 +48,11 @@ class DokkaConfigurationJsonTest { val parsedConfiguration = DokkaConfigurationImpl(json) assertEquals( DokkaConfigurationImpl( + moduleName = "moduleName", outputDir = File("customOutputDir"), pluginsClasspath = listOf(File("plugins/customPlugin.jar")), sourceSets = listOf( DokkaSourceSetImpl( - moduleDisplayName = "customModuleDisplayName", sourceRoots = setOf(File("customSourceRoot")), sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"), classpath = listOf(File("classpath/custom1.jar"), File("classpath/custom2.jar")) diff --git a/core/test-api/src/main/kotlin/testApi/testRunner/TestDokkaConfigurationBuilder.kt b/core/test-api/src/main/kotlin/testApi/testRunner/TestDokkaConfigurationBuilder.kt index 5bf7e52d..f6cb99db 100644 --- a/core/test-api/src/main/kotlin/testApi/testRunner/TestDokkaConfigurationBuilder.kt +++ b/core/test-api/src/main/kotlin/testApi/testRunner/TestDokkaConfigurationBuilder.kt @@ -16,6 +16,13 @@ annotation class DokkaConfigurationDsl @DokkaConfigurationDsl class TestDokkaConfigurationBuilder { + + var moduleName: String = "root" + set(value) { + check(lazySourceSets.isEmpty()) { "Cannot set moduleName after adding source sets" } + field = value + } + var outputDir: String = "out" var format: String = "html" var offlineMode: Boolean = false @@ -23,12 +30,13 @@ class TestDokkaConfigurationBuilder { var pluginsClasspath: List = emptyList() var pluginsConfigurations: Map = emptyMap() var failOnWarning: Boolean = false - private val sourceSets = mutableListOf() + private val lazySourceSets = mutableListOf>() fun build() = DokkaConfigurationImpl( + moduleName = moduleName, outputDir = File(outputDir), cacheRoot = cacheRoot?.let(::File), offlineMode = offlineMode, - sourceSets = sourceSets.toList(), + sourceSets = lazySourceSets.map { it.value }.toList(), pluginsClasspath = pluginsClasspath, pluginsConfiguration = pluginsConfigurations, modules = emptyList(), @@ -36,28 +44,29 @@ class TestDokkaConfigurationBuilder { ) fun sourceSets(block: SourceSetsBuilder.() -> Unit) { - sourceSets.addAll(SourceSetsBuilder().apply(block)) + lazySourceSets.addAll(SourceSetsBuilder(moduleName).apply(block)) } - fun add(sourceSet: DokkaSourceSetImpl) { - sourceSets.add(sourceSet) + fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): Lazy { + val lazySourceSet = lazy { DokkaSourceSetBuilder(moduleName).apply(block).build() } + lazySourceSets.add(lazySourceSet) + return lazySourceSet } -} -@DokkaConfigurationDsl -class SourceSetsBuilder : ArrayList() { - fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): DokkaConfiguration.DokkaSourceSet = - DokkaSourceSetBuilder().apply(block).build().apply(::add) + fun unattachedSourceSet(block: DokkaSourceSetBuilder.() -> Unit): DokkaSourceSetImpl { + return DokkaSourceSetBuilder(moduleName).apply(block).build() + } } -fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): DokkaSourceSetImpl { - return DokkaSourceSetBuilder().apply(block).build() +@DokkaConfigurationDsl +class SourceSetsBuilder(val moduleName: String) : ArrayList>() { + fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): Lazy = + lazy { DokkaSourceSetBuilder(moduleName).apply(block).build() }.apply(::add) } @DokkaConfigurationDsl class DokkaSourceSetBuilder( - var moduleName: String = "root", - var moduleDisplayName: String? = null, + private val moduleName: String, var name: String = "main", var displayName: String = "JVM", var classpath: List = emptyList(), @@ -81,7 +90,6 @@ class DokkaSourceSetBuilder( var sourceLinks: List = emptyList() ) { fun build() = DokkaSourceSetImpl( - moduleDisplayName = moduleDisplayName ?: moduleName, displayName = displayName, sourceSetID = DokkaSourceSetID(moduleName, name), classpath = classpath.map(::File), @@ -107,7 +115,6 @@ class DokkaSourceSetBuilder( } val defaultSourceSet = DokkaSourceSetImpl( - moduleDisplayName = "DEFAULT", displayName = "DEFAULT", sourceSetID = DokkaSourceSetID("DEFAULT", "DEFAULT"), classpath = emptyList(), diff --git a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt index 6510c044..aabc30c1 100644 --- a/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt +++ b/integration-tests/cli/src/integrationTest/kotlin/org/jetbrains/dokka/it/cli/CliIntegrationTest.kt @@ -34,10 +34,9 @@ class CliIntegrationTest : AbstractCliIntegrationTest() { "java", "-jar", cliJarFile.path, "-outputDir", dokkaOutputDir.path, "-pluginsClasspath", basePluginJarFile.path, + "-moduleName", "Basic Project", "-sourceSet", buildString { - append(" -moduleName it-cli") - append(" -moduleDisplayName CLI-Example") append(" -sourceSetName cliMain") append(" -src ${File(projectDir, "src").path}") append(" -jdkVersion 8") diff --git a/integration-tests/gradle/projects/it-basic/build.gradle.kts b/integration-tests/gradle/projects/it-basic/build.gradle.kts index 21187561..2769677f 100644 --- a/integration-tests/gradle/projects/it-basic/build.gradle.kts +++ b/integration-tests/gradle/projects/it-basic/build.gradle.kts @@ -15,9 +15,9 @@ dependencies { } tasks.withType { + moduleName.set("Basic Project") dokkaSourceSets { configureEach { - moduleDisplayName.set("Basic Project") suppressedFiles.from(file("src/main/kotlin/it/suppressedByPath")) perPackageOption { prefix.set("it.suppressedByPackage") diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt index 1265d675..f3bcfd59 100644 --- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt +++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt @@ -84,7 +84,7 @@ class BasicGradleIntegrationTest(override val versions: BuildVersions) : Abstrac assertTrue( allHtmlFiles().any { file -> "Basic Project" in file.readText() }, - "Expected configured moduleDisplayName to be present in html" + "Expected configured moduleName to be present in html" ) assertTrue( diff --git a/integration-tests/maven/projects/it-maven/pom.xml b/integration-tests/maven/projects/it-maven/pom.xml index 350701f9..80620c82 100644 --- a/integration-tests/maven/projects/it-maven/pom.xml +++ b/integration-tests/maven/projects/it-maven/pom.xml @@ -91,7 +91,7 @@ false - Maven Integration Test Module + Maven Integration Test Module ${project.basedir}/output diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt index d1832cbc..a87d4319 100644 --- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt +++ b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt @@ -16,7 +16,6 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.pages.PageCreator import org.jetbrains.dokka.utilities.DokkaLogger -import java.io.File class MultimodulePageCreator( val context: DokkaContext diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt index 6155af52..e66b7612 100644 --- a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt +++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/parseModuleAndPackageDocumentationFragments.kt @@ -37,9 +37,9 @@ private fun parseModuleAndPackageDocFragment( } val name = classifierAndName.getOrNull(1)?.trim().orEmpty() - if (name.contains(Regex("\\s"))) { + if (classifier == Package && name.contains(Regex("\\s"))) { throw IllegalModuleAndPackageDocumentation( - source, "Module/Package name cannot contain whitespace in '$firstLine'" + source, "Package name cannot contain whitespace in '$firstLine'" ) } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index c8e4f565..17ead667 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -10,20 +10,15 @@ internal object DefaultDocumentableMerger : DocumentableMerger { override fun invoke(modules: Collection, context: DokkaContext): DModule { - val projectName = - modules.fold(modules.first().name) { acc, module -> acc.commonPrefixWith(module.name) } - .takeIf { it.isNotEmpty() } - ?: "project" - return modules.reduce { left, right -> val list = listOf(left, right) DModule( - name = projectName, + name = modules.map { it.name }.distinct().joinToString("|"), packages = merge( list.flatMap { it.packages }, DPackage::mergeWith ), - documentation = list.map { it.documentation }.flatMap { it.entries }.associate { (k,v) -> k to v }, + documentation = list.map { it.documentation }.flatMap { it.entries }.associate { (k, v) -> k to v }, expectPresentInSet = list.firstNotNullResult { it.expectPresentInSet }, sourceSets = list.flatMap { it.sourceSets }.toSet() ).mergeExtras(left, right) @@ -61,7 +56,7 @@ fun DFunction.mergeWith(other: DFunction): DFunction = copy( receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, modifier = modifier + other.modifier, sourceSets = sourceSets + other.sourceSets, @@ -72,7 +67,7 @@ fun DProperty.mergeWith(other: DProperty): DProperty = copy( receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, modifier = modifier + other.modifier, sourceSets = sourceSets + other.sourceSets, @@ -104,7 +99,7 @@ fun DClass.mergeWith(other: DClass): DClass = copy( supertypes = supertypes + other.supertypes, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets ).mergeExtras(this, other) @@ -122,7 +117,7 @@ fun DEnum.mergeWith(other: DEnum): DEnum = copy( supertypes = supertypes + other.supertypes, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets ).mergeExtras(this, other) @@ -143,7 +138,7 @@ fun DObject.mergeWith(other: DObject): DObject = copy( supertypes = supertypes + other.supertypes, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets ).mergeExtras(this, other) @@ -157,7 +152,7 @@ fun DInterface.mergeWith(other: DInterface): DInterface = copy( supertypes = supertypes + other.supertypes, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets ).mergeExtras(this, other) @@ -173,7 +168,7 @@ fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy( companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, documentation = documentation + other.documentation, expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet, - sources = sources+ other.sources, + sources = sources + other.sources, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets, generics = merge(generics + other.generics, DTypeParameter::mergeWith) @@ -197,4 +192,4 @@ fun DTypeAlias.mergeWith(other: DTypeAlias): DTypeAlias = copy( underlyingType = underlyingType + other.underlyingType, visibility = visibility + other.visibility, sourceSets = sourceSets + other.sourceSets -).mergeExtras(this, other) \ No newline at end of file +).mergeExtras(this, other) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt index 66156832..6a6231c5 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt @@ -249,4 +249,4 @@ class DeprecatedDocumentableFilterTransformer(val context: DokkaContext) : PreMe } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt index e712d6e5..e126d05f 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt @@ -65,11 +65,7 @@ private class ContextModuleAndPackageDocumentationReader( override fun get(module: DModule): SourceSetDependent { return findDocumentationNodes(module.sourceSets) { fragment -> - fragment.classifier == Classifier.Module && ( - /* Match fragment name against module name or distinct module displayName */ - fragment.name == module.name || - fragment.name == module.sourceSets.map { it.moduleDisplayName }.distinct().singleOrNull() - ) + fragment.classifier == Classifier.Module && (fragment.name == module.name) } } diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index 2099cab5..ca239d83 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -62,12 +62,12 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { private fun ContentNode.addSample( contentPage: ContentPage, - platform: DokkaSourceSet, + sourceSet: DokkaSourceSet, fqName: String, analysis: Map ): ContentNode { - val facade = analysis[platform]?.facade - ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleDisplayName}") } + val facade = analysis[sourceSet]?.facade + ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${sourceSet.sourceSetID}") } val psiElement = fqNameToPsiElement(facade, fqName) ?: return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") } val imports = diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 18b05df4..8e5a1927 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -70,7 +70,15 @@ class DefaultDescriptorToDocumentableTranslator( DRIWithPlatformInfo(DRI.topLevel, emptyMap()) ) } - }.let { DModule(sourceSet.moduleDisplayName, it, emptyMap(), null, setOf(sourceSet)) } + }.let { + DModule( + name = context.configuration.moduleName, + packages = it, + documentation = emptyMap(), + expectPresentInSet = null, + sourceSets = setOf(sourceSet) + ) + } } } @@ -557,7 +565,9 @@ private class DokkaDescriptorVisitor( private fun ClassDescriptor.resolveClassDescriptionData(): ClassInfo { fun toTypeConstructor(kt: KotlinType) = - TypeConstructor(DRI.from(kt.constructor.declarationDescriptor as DeclarationDescriptor), kt.arguments.map { it.toProjection() }) + TypeConstructor( + DRI.from(kt.constructor.declarationDescriptor as DeclarationDescriptor), + kt.arguments.map { it.toProjection() }) tailrec fun buildAncestryInformation( supertypes: Collection, @@ -753,13 +763,22 @@ private class DokkaDescriptorVisitor( private fun ValueArgument.childrenAsText() = this.safeAs()?.children?.map { it.text }.orEmpty() - private data class AncestryLevel(val level: Int, val superclass: TypeConstructor?, val interfaces: List) + private data class AncestryLevel( + val level: Int, + val superclass: TypeConstructor?, + val interfaces: List + ) - private data class ClassInfo(val ancestry: List, val docs: SourceSetDependent){ + private data class ClassInfo(val ancestry: List, val docs: SourceSetDependent) { val supertypes: List get() = ancestry.firstOrNull { it.level == 0 }?.let { - listOfNotNull(it.superclass?.let { TypeConstructorWithKind(it, KotlinClassKindTypes.CLASS) }) + it.interfaces.map { TypeConstructorWithKind(it, KotlinClassKindTypes.INTERFACE) } - }.orEmpty() + listOfNotNull(it.superclass?.let { + TypeConstructorWithKind( + it, + KotlinClassKindTypes.CLASS + ) + }) + it.interfaces.map { TypeConstructorWithKind(it, KotlinClassKindTypes.INTERFACE) } + }.orEmpty() val allImplementedInterfaces: List get() = ancestry.flatMap { it.interfaces }.distinct() diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index c1ed4a08..30e46404 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -68,7 +68,7 @@ class DefaultPsiToDocumentableTranslator( context.logger ) return DModule( - sourceSet.moduleDisplayName, + context.configuration.moduleName, psiFiles.mapNotNull { it.safeAs() }.groupBy { it.packageName }.map { (packageName, psiFiles) -> val dri = DRI(packageName = packageName) DPackage( diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 952780c7..25400ca5 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -26,9 +26,9 @@ class LinkableContentTest : AbstractCoreTest() { val includesDir = getTestDataDir("linkable/includes").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" sourceSets { sourceSet { - moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() @@ -37,7 +37,6 @@ class LinkableContentTest : AbstractCoreTest() { includes = listOf(Paths.get("$includesDir/include2.md").toString()) } sourceSet { - moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() @@ -65,9 +64,10 @@ class LinkableContentTest : AbstractCoreTest() { val testDataDir = getTestDataDir("linkable/sources").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" + sourceSets { sourceSet { - moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("$testDataDir/jsMain/kotlin") sourceLinks = listOf( @@ -80,7 +80,6 @@ class LinkableContentTest : AbstractCoreTest() { name = "js" } sourceSet { - moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("$testDataDir/jvmMain/kotlin") sourceLinks = listOf( @@ -130,16 +129,15 @@ class LinkableContentTest : AbstractCoreTest() { val testDataDir = getTestDataDir("linkable/samples").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" sourceSets { sourceSet { - moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("$testDataDir/jsMain/kotlin") name = "js" samples = listOf("$testDataDir/jsMain/resources/Samples.kt") } sourceSet { - moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("$testDataDir/jvmMain/kotlin") name = "jvm" diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt index 17f9631a..a2c2f97d 100644 --- a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt +++ b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt @@ -98,20 +98,29 @@ class ParseModuleAndPackageDocumentationFragmentsTest { } @Test - fun `white space in module name fails`() { - val exception = assertThrows { - parseModuleAndPackageDocumentationFragments( - source( - """ - # Module My Module - """.trimIndent() - ) + fun `white space in module name is supported`() { + val fragment = parseModuleAndPackageDocumentationFragments( + source( + """ + # Module My Module + Documentation for my module + """.trimIndent() ) - } + ) - assertTrue( - "Module My Module" in exception.message.orEmpty(), - "Expected problematic statement in error message" + assertEquals( + Module, fragment.single().classifier, + "Expected module being parsec" + ) + + assertEquals( + "My Module", fragment.single().name, + "Expected module name with white spaces being parsed" + ) + + assertEquals( + "Documentation for my module", fragment.single().documentation, + "Expected documentation being available" ) } diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt index 4f55695d..8426923d 100644 --- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt @@ -21,14 +21,12 @@ import java.io.File abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase() { protected val js = defaultSourceSet.copy( - "root", "JS", defaultSourceSet.sourceSetID.copy(sourceSetName = "js"), analysisPlatform = Platform.js, sourceRoots = setOf(File("pl1")) ) protected val jvm = defaultSourceSet.copy( - "root", "JVM", defaultSourceSet.sourceSetID.copy(sourceSetName = "jvm"), @@ -36,7 +34,6 @@ abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase() { sourceRoots = setOf(File("pl1")) ) protected val native = defaultSourceSet.copy( - "root", "NATIVE", defaultSourceSet.sourceSetID.copy(sourceSetName = "native"), analysisPlatform = Platform.native, diff --git a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt index 77ba390e..4fd349e4 100644 --- a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt @@ -14,21 +14,18 @@ import java.io.File class SourceSetDependentHintTest : HtmlRenderingOnlyTestBase() { private val pl1 = defaultSourceSet.copy( - "root", "pl1", defaultSourceSet.sourceSetID.copy(sourceSetName = "pl1"), analysisPlatform = Platform.js, sourceRoots = setOf(File("pl1")) ) private val pl2 = defaultSourceSet.copy( - "root", "pl2", defaultSourceSet.sourceSetID.copy(sourceSetName = "pl2"), analysisPlatform = Platform.jvm, sourceRoots = setOf(File("pl1")) ) private val pl3 = defaultSourceSet.copy( - "root", "pl3", defaultSourceSet.sourceSetID.copy(sourceSetName = "pl3"), analysisPlatform = Platform.native, diff --git a/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt index 7635ab05..2e8e0ef3 100644 --- a/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt @@ -16,9 +16,9 @@ class DivergentSignatureTest : AbstractCoreTest() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" sourceSets { sourceSet { - moduleName = "example" displayName = "js" name = "js" analysisPlatform = "js" @@ -27,7 +27,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "jvm" name = "jvm" analysisPlatform = "jvm" @@ -36,7 +35,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "common" name = "common" analysisPlatform = "common" @@ -68,9 +66,9 @@ class DivergentSignatureTest : AbstractCoreTest() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" sourceSets { sourceSet { - moduleName = "example" displayName = "js" name = "js" analysisPlatform = "js" @@ -79,7 +77,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "jvm" name = "jvm" analysisPlatform = "jvm" @@ -88,7 +85,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "common" name = "common" analysisPlatform = "common" @@ -120,9 +116,9 @@ class DivergentSignatureTest : AbstractCoreTest() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() val configuration = dokkaConfiguration { + moduleName = "example" sourceSets { sourceSet { - moduleName = "example" displayName = "js" name = "js" analysisPlatform = "js" @@ -131,7 +127,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "jvm" name = "jvm" analysisPlatform = "jvm" @@ -140,7 +135,6 @@ class DivergentSignatureTest : AbstractCoreTest() { } } sourceSet { - moduleName = "example" displayName = "common" name = "common" analysisPlatform = "common" @@ -172,4 +166,4 @@ class DivergentSignatureTest : AbstractCoreTest() { private val Element.brief: String get() = children().select(".brief-with-platform-tags").text() -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index 1c3842c4..5a4b614f 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -329,16 +329,15 @@ class SignatureTest : AbstractCoreTest() { fun `type with an actual typealias`() { val configuration = dokkaConfiguration { + moduleName = "test" sourceSets { sourceSet { - moduleName = "test" name = "common" sourceRoots = listOf("src/main/kotlin/common/Test.kt") classpath = listOf(commonStdlibPath!!) externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) } sourceSet { - moduleName = "test" name = "jvm" dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt index e04e751c..51a5e85a 100644 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt @@ -12,13 +12,11 @@ import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import testApi.testRunner.dokkaConfiguration -import testApi.testRunner.sourceSet +import testApi.testRunner.TestDokkaConfigurationBuilder class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAndPackageDocumentationReaderTest() { - private val includeSourceSetA by lazy { temporaryDirectory.resolve("includeA.md").toFile() } private val includeSourceSetB by lazy { temporaryDirectory.resolve("includeB.md").toFile() } @@ -51,40 +49,31 @@ class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAnd ) } - private val sourceSetA by lazy { - sourceSet { - moduleName = "moduleA" - name = "sourceSetA" - includes = listOf(includeSourceSetA.canonicalPath) - } + private val configurationBuilder = TestDokkaConfigurationBuilder().apply { + moduleName = "moduleA" } - private val sourceSetB by lazy { - sourceSet { - moduleName = "moduleB" - name = "sourceSetB" - includes = listOf(includeSourceSetB.canonicalPath) - } + private val sourceSetA by configurationBuilder.sourceSet { + name = "sourceSetA" + includes = listOf(includeSourceSetA.canonicalPath) } - private val sourceSetB2 by lazy { - sourceSet { - moduleName = "moduleB" - name = "sourceSetB2" - includes = emptyList() - } + + private val sourceSetB by configurationBuilder.sourceSet { + name = "sourceSetB" + includes = listOf(includeSourceSetB.canonicalPath) + } + + + private val sourceSetB2 by configurationBuilder.sourceSet { + name = "sourceSetB2" + includes = emptyList() } private val context by lazy { DokkaContext.create( - configuration = dokkaConfiguration { - sourceSets { - add(sourceSetA) - add(sourceSetB) - add(sourceSetB2) - } - }, + configuration = configurationBuilder.build(), logger = TestLogger(DokkaConsoleLogger), pluginOverrides = emptyList() ) @@ -121,7 +110,9 @@ class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAnd @Test fun `assert moduleA with unknown source set`() { - val documentation = reader[DModule("moduleA", sourceSets = setOf(sourceSet { name = "unknown" }))] + val documentation = reader[ + DModule("moduleA", sourceSets = setOf(configurationBuilder.unattachedSourceSet { name = "unknown" })) + ] assertEquals( emptyMap(), documentation, "Expected no documentation received for module with unknown sourceSet" diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest2.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest2.kt deleted file mode 100644 index e209a170..00000000 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest2.kt +++ /dev/null @@ -1,63 +0,0 @@ -package transformers - -import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationReader -import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.utilities.DokkaConsoleLogger -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import testApi.testRunner.dokkaConfiguration -import testApi.testRunner.sourceSet - - -class ContextModuleAndPackageDocumentationReaderTest2: AbstractContextModuleAndPackageDocumentationReaderTest() { - - private val include by lazy { temporaryDirectory.resolve("include.md").toFile() } - - @BeforeEach - fun materializeInclude() { - include.writeText( - """ - # Module MyModuleDisplayName - Matching: moduleDisplayName - - # Module myModuleName - Matching: moduleName - """.trimIndent() - ) - } - - private val sourceSet by lazy { - sourceSet { - moduleName = "myModuleName" - moduleDisplayName = "MyModuleDisplayName" - includes = listOf(include.canonicalPath) - } - } - - private val context by lazy { - DokkaContext.create( - configuration = dokkaConfiguration { - sourceSets { - add(sourceSet) - } - }, - logger = DokkaConsoleLogger, - pluginOverrides = emptyList() - ) - } - - private val reader by lazy { ModuleAndPackageDocumentationReader(context) } - - - @Test - fun `module matches for moduleName and moduleDisplayName`() { - val documentation = reader[DModule("myModuleName", sourceSets = setOf(sourceSet))] - assertEquals(1, documentation.keys.size, "Expected only one entry from sourceSet") - assertEquals(sourceSet, documentation.keys.single(), "Expected only one entry from sourceSet") - assertEquals( - listOf("Matching: moduleDisplayName", "Matching: moduleName"), documentation.texts - ) - } -} diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt index e1b9d199..a557379b 100644 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest3.kt @@ -7,6 +7,7 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import testApi.testRunner.TestDokkaConfigurationBuilder import testApi.testRunner.dokkaConfiguration import testApi.testRunner.sourceSet import kotlin.test.assertEquals @@ -28,19 +29,15 @@ class ContextModuleAndPackageDocumentationReaderTest3 : AbstractContextModuleAnd ) } - private val sourceSet by lazy { - sourceSet { - includes = listOf(include.canonicalPath) - } + private val configurationBuilder = TestDokkaConfigurationBuilder() + + private val sourceSet by configurationBuilder.sourceSet { + includes = listOf(include.canonicalPath) } private val context by lazy { DokkaContext.create( - configuration = dokkaConfiguration { - sourceSets { - add(sourceSet) - } - }, + configuration = configurationBuilder.build(), logger = DokkaConsoleLogger, pluginOverrides = emptyList() ) diff --git a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt index 2d356a81..68e41ad1 100644 --- a/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ModuleAndPackageDocumentationTransformerFunctionalTest.kt @@ -35,9 +35,9 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( """.trimIndent() ) val configuration = dokkaConfiguration { + moduleName = "moduleA" sourceSets { sourceSet { - moduleName = "moduleA" name = "commonMain" displayName = "common" analysisPlatform = "common" @@ -45,7 +45,6 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( includes = listOf(include.canonicalPath) } sourceSet { - moduleName = "moduleA" name = "jsMain" displayName = "js" analysisPlatform = "js" @@ -54,7 +53,6 @@ class ModuleAndPackageDocumentationTransformerFunctionalTest : AbstractCoreTest( includes = listOf(include.canonicalPath) } sourceSet { - moduleName = "moduleA" name = "jvmMain" displayName = "jvm" analysisPlatform = "jvm" diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index 72948372..265baa42 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -484,7 +484,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { fun `multiplatform undocumented class gets reported`() { val configuration = dokkaConfiguration { sourceSets { - val commonMain = sourceSet { + val commonMain by sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() name = "commonMain" @@ -527,7 +527,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { fun `multiplatform undocumented class does not get reported if expect is documented`() { val configuration = dokkaConfiguration { sourceSets { - val commonMain = sourceSet { + val commonMain by sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() name = "commonMain" @@ -569,7 +569,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { fun `multiplatform undocumented function gets reported`() { val configuration = dokkaConfiguration { sourceSets { - val commonMain = sourceSet { + val commonMain by sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() name = "commonMain" diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt index cd9b9dfc..dee43b1d 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt @@ -12,21 +12,18 @@ import java.io.File class DivergentTest : GfmRenderingOnlyTestBase() { private val js = defaultSourceSet.copy( - "root", "js", DokkaSourceSetID("root", "js"), analysisPlatform = Platform.js, sourceRoots = setOf(File("pl1")) ) private val jvm = defaultSourceSet.copy( - "root", "jvm", DokkaSourceSetID("root", "jvm"), analysisPlatform = Platform.jvm, sourceRoots = setOf(File("pl1")) ) private val native = defaultSourceSet.copy( - "root", "native", DokkaSourceSetID("root", "native"), analysisPlatform = Platform.native, diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt index 35c2da3d..a118a20e 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt @@ -21,7 +21,7 @@ abstract class GfmRenderingOnlyTestBase : RenderingOnlyTestBase() { DokkaBase().externalLocationProviderFactory to { ::DefaultExternalLocationProviderFactory }, GfmPlugin().gfmPreprocessors to { _ -> RootCreator }, - testConfiguration = DokkaConfigurationImpl() + testConfiguration = DokkaConfigurationImpl(moduleName = "root") ) override val renderedContent: String by lazy { diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt index de473db0..93edd001 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt @@ -12,21 +12,18 @@ import java.io.File class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { private val pl1 = defaultSourceSet.copy( - "root", "pl1", DokkaSourceSetID("root", "pl1"), analysisPlatform = Platform.js, sourceRoots = setOf(File("pl1")) ) private val pl2 = defaultSourceSet.copy( - "root", "pl2", DokkaSourceSetID("root", "pl2"), analysisPlatform = Platform.jvm, sourceRoots = setOf(File("pl1")) ) private val pl3 = defaultSourceSet.copy( - "root", "pl3", DokkaSourceSetID("root", "pl3"), analysisPlatform = Platform.native, diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 069ef166..9f7755f6 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -2,13 +2,11 @@ package org.jetbrains.dokka import kotlinx.cli.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet.* import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.jetbrains.dokka.utilities.cast import java.io.* import java.net.MalformedURLException import java.net.URL -import java.nio.file.Files import java.nio.file.Paths class GlobalArguments(args: Array) : DokkaConfiguration { @@ -17,6 +15,14 @@ class GlobalArguments(args: Array) : DokkaConfiguration { val json: String? by parser.argument(ArgType.String, description = "Json file name").optional() + private val _moduleName = parser.option( + ArgType.String, + description = "Name of the documentation module", + fullName = "moduleName" + ).required() + + override val moduleName: String by _moduleName + override val outputDir by parser.option(ArgTypeFile, description = "Output directory path") .default(DokkaDefaults.outputDir) @@ -26,7 +32,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { ) override val sourceSets by parser.option( - ArgTypeArgument, + ArgTypeArgument(_moduleName), description = "Single dokka source set", fullName = "sourceSet" ).multiple() @@ -68,7 +74,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { ).delimiter(";") val helpSourceSet by parser.option( - ArgTypeHelpSourceSet, + ArgTypeHelpSourceSet(_moduleName), description = "Prints help for single -sourceSet" ) @@ -103,21 +109,10 @@ class GlobalArguments(args: Array) : DokkaConfiguration { } } -private fun parseSourceSet(args: Array): DokkaConfiguration.DokkaSourceSet { +private fun parseSourceSet(moduleName: String, args: Array): DokkaConfiguration.DokkaSourceSet { val parser = ArgParser("sourceSet", prefixStyle = ArgParser.OptionPrefixStyle.JVM) - val moduleName by parser.option( - ArgType.String, - description = "Name of the documentation module", - fullName = "moduleName" - ).required() - - val moduleDisplayName by parser.option( - ArgType.String, - description = "Name of the documentation module" - ) - val sourceSetName by parser.option( ArgType.String, description = "Name of the source set" @@ -218,7 +213,6 @@ private fun parseSourceSet(args: Array): DokkaConfiguration.DokkaSourceS parser.parse(args) return object : DokkaConfiguration.DokkaSourceSet { - override val moduleDisplayName = moduleDisplayName ?: moduleName override val displayName = displayName override val sourceSetID = DokkaSourceSetID(moduleName, sourceSetName) override val classpath = classpath.toMutableList() @@ -281,17 +275,20 @@ object ArgTypeSourceLinkDefinition : ArgType(true) { +data class ArgTypeArgument(val moduleName: CLIEntity) : + ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): DokkaConfiguration.DokkaSourceSet = - parseSourceSet(value.split(" ").filter { it.isNotBlank() }.toTypedArray()) + parseSourceSet(moduleName.value, value.split(" ").filter { it.isNotBlank() }.toTypedArray()) override val description: kotlin.String get() = "" } // Workaround for printing nested parsers help -object ArgTypeHelpSourceSet : ArgType(false) { - override fun convert(value: kotlin.String, name: kotlin.String): Any = Any().also { parseSourceSet(arrayOf("-h")) } +data class ArgTypeHelpSourceSet(val moduleName: CLIEntity) : ArgType(false) { + override fun convert(value: kotlin.String, name: kotlin.String): Any = Any().also { + parseSourceSet(moduleName.value, arrayOf("-h")) + } override val description: kotlin.String get() = "" diff --git a/runners/gradle-plugin/MIGRATION.md b/runners/gradle-plugin/MIGRATION.md index 555ce66e..527c3e66 100644 --- a/runners/gradle-plugin/MIGRATION.md +++ b/runners/gradle-plugin/MIGRATION.md @@ -68,7 +68,7 @@ tasks.dokkaHtml.configure { #### Properties ```kotlin /* 0.10.x */ moduleName = "myModule" -/* 1.4.x */ moduleDisplayName.set("myModule") +/* 1.4.x */ /* Use AbstractDokkaTask#moduleName instead */ /* 0.10.x */ includeNonPublic = false /* 1.4.x */ includeNonPublic.set(false) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt index 89308e2a..b4800124 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt @@ -24,6 +24,10 @@ abstract class AbstractDokkaTask( private val bootstrapClass: KClass = DokkaBootstrap::class ) : DefaultTask() { + @Input + val moduleName: Property = project.objects.safeProperty() + .safeConvention(project.name) + @OutputDirectory val outputDirectory: Property = project.objects.safeProperty() .safeConvention(defaultDokkaOutputDirectory()) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt index 532e9e84..cd53398a 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt @@ -11,6 +11,7 @@ abstract class DokkaCollectorTask : AbstractDokkaParentTask() { override fun buildDokkaConfiguration(): DokkaConfigurationImpl { val initialDokkaConfiguration = DokkaConfigurationImpl( +