From 872008d130c1b4f7e8721a0f177636ac9b157de6 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 19 Aug 2020 09:34:40 +0200 Subject: - Implement GradleDokkaSourceSetBuilder#isDocumented to enable/disable source sets - Let KotlinSourceSetGist#isMain use provider API to be evaluated more lazily --- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 25 ++++++++++++++++------ .../dokka/gradle/GradleDokkaSourceSetBuilder.kt | 5 +++++ .../dokka/gradle/checkDependentSourceSets.kt | 25 ++++++++++++++++++++++ .../dokka/gradle/kotlin/KotlinSourceSetGist.kt | 12 +++++------ .../gradle/sourceSetKotlinGistConfiguration.kt | 15 +++++++------ .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 4 ++++ 6 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt (limited to 'runners/gradle-plugin/src/main/kotlin') 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 00bd43d7..08ed7d70 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 @@ -2,35 +2,46 @@ package org.jetbrains.dokka.gradle import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.internal.plugins.DslObject +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Nested import org.jetbrains.dokka.DokkaBootstrapImpl import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.build -import org.jetbrains.dokka.gradle.kotlin.isMainSourceSet open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) { - @get:Nested + @get:Internal val dokkaSourceSets: NamedDomainObjectContainer = project.container(GradleDokkaSourceSetBuilder::class.java, GradleDokkaSourceSetBuilderFactory()) .also { container -> DslObject(this).extensions.add("dokkaSourceSets", container) project.kotlinOrNull?.sourceSets?.all { kotlinSourceSet -> - if (project.isMainSourceSet(kotlinSourceSet)) { - container.register(kotlinSourceSet.name) { dokkaSourceSet -> - dokkaSourceSet.configureWithKotlinSourceSet(kotlinSourceSet) - } + container.register(kotlinSourceSet.name) { dokkaSourceSet -> + dokkaSourceSet.configureWithKotlinSourceSet(kotlinSourceSet) } } } + // 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 + get() = dokkaSourceSets + .toList() + .also(::checkSourceSetDependencies) + .filter { it.isDocumented.getSafe() } + override fun buildDokkaConfiguration(): DokkaConfigurationImpl { return DokkaConfigurationImpl( outputDir = outputDirectory.getSafe(), cacheRoot = cacheRoot.getSafe(), offlineMode = offlineMode.getSafe(), failOnWarning = failOnWarning.getSafe(), - sourceSets = dokkaSourceSets.build(), + sourceSets = documentedDokkaSourceSets.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 927df80c..b0686011 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 @@ -32,6 +32,11 @@ open class GradleDokkaSourceSetBuilder constructor( @Internal val sourceSetID: DokkaSourceSetID = DokkaSourceSetID(project, name) + @Input + @get:JvmName("getIsDocumented") + val isDocumented: Property = project.objects.safeProperty() + .safeConvention(true) + @Classpath @Optional val classpath: ConfigurableFileCollection = project.files() 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 new file mode 100644 index 00000000..8d2f70fd --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt @@ -0,0 +1,25 @@ +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.DokkaSourceSetID + +// TODO NOW: Test +internal fun checkSourceSetDependencies(sourceSets: List) { + checkSourceSetDependencies(sourceSets.associateBy { it.sourceSetID }) +} + +private fun checkSourceSetDependencies(sourceSets: Map) { + sourceSets.values.forEach { sourceSet -> + sourceSet.dependentSourceSets.getSafe().forEach { dependentSourceSetID -> + val dependentSourceSet = requireNotNull(sourceSets[dependentSourceSetID]) { + "Dokka source set ${sourceSet.name}: Cannot find dependent source set $dependentSourceSetID" + } + + if (sourceSet.isDocumented.getSafe() && dependentSourceSet.isDocumented.getSafe().not()) { + throw IllegalArgumentException( + "Dokka source set: ${sourceSet.name}: " + + "Documented source set cannot depend on undocumented source set $dependentSourceSetID" + ) + } + } + } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt index c534b24e..619910ed 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt @@ -8,18 +8,18 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet internal data class KotlinSourceSetGist( val name: String, - val platform: KotlinPlatformType, - val isMain: Boolean, - val classpath: FileCollection, + val platform: Provider, + val isMain: Provider, + val classpath: Provider, val sourceRoots: FileCollection, val dependentSourceSetNames: Provider>, ) internal fun Project.gistOf(sourceSet: KotlinSourceSet): KotlinSourceSetGist = KotlinSourceSetGist( name = sourceSet.name, - platform = platformOf(sourceSet), - isMain = isMainSourceSet(sourceSet), - classpath = classpathOf(sourceSet).filter { it.exists() }, + platform = project.provider { platformOf(sourceSet) }, + isMain = project.provider { isMainSourceSet(sourceSet) }, + classpath = project.provider { classpathOf(sourceSet).filter { it.exists() } }, // TODO: Needs to respect filters. // We probably need to change from "sourceRoots" to support "sourceFiles" // https://github.com/Kotlin/dokka/issues/1215 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 dff61f68..fee86094 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,13 +14,16 @@ internal fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSetGist(source sourceSetNames.map { sourceSetName -> DokkaSourceSetID(sourceSetName) } } + this.isDocumented by sourceSet.isMain this.sourceRoots.from(sourceSet.sourceRoots) this.classpath.from(sourceSet.classpath) - this.platform by Platform.fromString(sourceSet.platform.name) - this.dependentSourceSets.set(dependentSourceSetIds) - this.displayName by sourceSet.name.substringBeforeLast( - delimiter = "Main", - missingDelimiterValue = sourceSet.platform.name - ) + this.platform by sourceSet.platform.map { Platform.fromString(it.name) } + this.dependentSourceSets by dependentSourceSetIds + this.displayName by sourceSet.platform.map { platform -> + sourceSet.name.substringBeforeLast( + delimiter = "Main", + missingDelimiterValue = platform.name + ) + } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index fc07962d..14b2a045 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -24,6 +24,10 @@ internal infix fun HasMultipleValues.by(values: Iterable) { this.set(values) } +internal infix fun HasMultipleValues.by(values: Provider>) { + this.set(values) +} + internal fun parsePath(path: String): Path = Path.path(path) internal val Project.kotlinOrNull: KotlinProjectExtension? -- cgit