From d2085c1049b3d27cc907b60605c43b832ae8d469 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 20 Aug 2020 10:03:36 +0200 Subject: Implement tests for enhanced KotlinSourceSetGist mechanism --- .../src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 7 +++---- .../org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt | 5 ++--- .../org/jetbrains/dokka/gradle/checkDependentSourceSets.kt | 9 ++++----- .../kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt | 7 ++++++- .../jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) (limited to 'runners/gradle-plugin/src/main/kotlin/org') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index 08ed7d70..e63863b3 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -22,18 +22,17 @@ open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { } } - // TODO NOW: Test /** * Only contains source sets that are marked with `isDocumented`. * Non documented source sets are not relevant for Gradle's UP-TO-DATE mechanism, as well * as task dependency graph. */ @get:Nested - protected val documentedDokkaSourceSets: List + protected val unsuppressedSourceSets: List get() = dokkaSourceSets .toList() .also(::checkSourceSetDependencies) - .filter { it.isDocumented.getSafe() } + .filterNot { it.suppress.getSafe() } override fun buildDokkaConfiguration(): DokkaConfigurationImpl { return DokkaConfigurationImpl( @@ -41,7 +40,7 @@ open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { cacheRoot = cacheRoot.getSafe(), offlineMode = offlineMode.getSafe(), failOnWarning = failOnWarning.getSafe(), - sourceSets = documentedDokkaSourceSets.build(), + sourceSets = unsuppressedSourceSets.build(), pluginsConfiguration = pluginsConfiguration.getSafe(), pluginsClasspath = plugins.resolve().toList() ) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt index b0686011..3b26e1e9 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt @@ -33,9 +33,8 @@ open class GradleDokkaSourceSetBuilder constructor( val sourceSetID: DokkaSourceSetID = DokkaSourceSetID(project, name) @Input - @get:JvmName("getIsDocumented") - val isDocumented: Property = project.objects.safeProperty() - .safeConvention(true) + val suppress: Property = project.objects.safeProperty() + .safeConvention(false) @Classpath @Optional diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt index 8d2f70fd..989ad10a 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt @@ -2,7 +2,6 @@ package org.jetbrains.dokka.gradle import org.jetbrains.dokka.DokkaSourceSetID -// TODO NOW: Test internal fun checkSourceSetDependencies(sourceSets: List) { checkSourceSetDependencies(sourceSets.associateBy { it.sourceSetID }) } @@ -11,13 +10,13 @@ private fun checkSourceSetDependencies(sourceSets: Map sourceSet.dependentSourceSets.getSafe().forEach { dependentSourceSetID -> val dependentSourceSet = requireNotNull(sourceSets[dependentSourceSetID]) { - "Dokka source set ${sourceSet.name}: Cannot find dependent source set $dependentSourceSetID" + "Dokka source set \"${sourceSet.name}\": Cannot find dependent source set \"$dependentSourceSetID\"" } - if (sourceSet.isDocumented.getSafe() && dependentSourceSet.isDocumented.getSafe().not()) { + if (sourceSet.suppress.getSafe().not() && dependentSourceSet.suppress.getSafe()) { throw IllegalArgumentException( - "Dokka source set: ${sourceSet.name}: " + - "Documented source set cannot depend on undocumented source set $dependentSourceSetID" + "Dokka source set: \"${sourceSet.name}\": " + + "Unsuppressed source set cannot depend on suppressed source set \"$dependentSourceSetID\"" ) } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt index 2c1eba5b..15989217 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt @@ -7,7 +7,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation internal fun Project.isMainSourceSet(sourceSet: KotlinSourceSet): Boolean { - return allCompilationsOf(sourceSet).any { compilation -> isMainCompilation(compilation) } + return isMainSourceSet(allCompilationsOf(sourceSet)) +} + +internal fun isMainSourceSet(compilations: List): Boolean { + if (compilations.isEmpty()) return true + return compilations.any { compilation -> isMainCompilation(compilation) } } private fun isMainCompilation(compilation: KotlinCompilation): Boolean { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt index fee86094..a7231f04 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt @@ -14,7 +14,7 @@ internal fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSetGist(source sourceSetNames.map { sourceSetName -> DokkaSourceSetID(sourceSetName) } } - this.isDocumented by sourceSet.isMain + this.suppress by sourceSet.isMain.map { !it } this.sourceRoots.from(sourceSet.sourceRoots) this.classpath.from(sourceSet.classpath) this.platform by sourceSet.platform.map { Platform.fromString(it.name) } -- cgit