diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-19 09:34:40 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-20 16:36:30 +0200 |
commit | 872008d130c1b4f7e8721a0f177636ac9b157de6 (patch) | |
tree | 0d81a95cea36ec753c8a5c778f6460e597f55dea /runners/gradle-plugin | |
parent | b9a1b3380a0bb8a64f3c7f257374cd4a6b2f3cfe (diff) | |
download | dokka-872008d130c1b4f7e8721a0f177636ac9b157de6.tar.gz dokka-872008d130c1b4f7e8721a0f177636ac9b157de6.tar.bz2 dokka-872008d130c1b4f7e8721a0f177636ac9b157de6.zip |
- Implement GradleDokkaSourceSetBuilder#isDocumented to enable/disable source sets
- Let KotlinSourceSetGist#isMain use provider API to be evaluated more lazily
Diffstat (limited to 'runners/gradle-plugin')
8 files changed, 77 insertions, 29 deletions
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<GradleDokkaSourceSetBuilder> = 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<GradleDokkaSourceSetBuilder> + 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<Boolean> = project.objects.safeProperty<Boolean>() + .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<GradleDokkaSourceSetBuilder>) { + checkSourceSetDependencies(sourceSets.associateBy { it.sourceSetID }) +} + +private fun checkSourceSetDependencies(sourceSets: Map<DokkaSourceSetID, GradleDokkaSourceSetBuilder>) { + 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<KotlinPlatformType>, + val isMain: Provider<Boolean>, + val classpath: Provider<FileCollection>, val sourceRoots: FileCollection, val dependentSourceSetNames: Provider<Set<String>>, ) 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 <T> HasMultipleValues<in T>.by(values: Iterable<T>) { this.set(values) } +internal infix fun <T> HasMultipleValues<in T>.by(values: Provider<out Iterable<T>>) { + this.set(values) +} + internal fun parsePath(path: String): Path = Path.path(path) internal val Project.kotlinOrNull: KotlinProjectExtension? diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt index 13ba9622..49db0eb6 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt @@ -26,7 +26,7 @@ class ConfigureWithKotlinSourceSetGistTest { val gist = KotlinSourceSetGist( name = "customName", platform = KotlinPlatformType.common, - isMain = true, + isMain = project.provider { true }, classpath = project.files(f1Jar, f2Jar), sourceRoots = project.files(customSourceRoot), dependentSourceSetNames = project.provider { setOf("customRootSourceSet") } @@ -68,7 +68,7 @@ class ConfigureWithKotlinSourceSetGistTest { val gist = KotlinSourceSetGist( name = "customMain", platform = KotlinPlatformType.common, - isMain = true, + isMain = project.provider { true }, classpath = project.files(), sourceRoots = project.files(), dependentSourceSetNames = project.provider { emptySet() } diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt index 1996bb16..eff0726f 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt @@ -37,7 +37,7 @@ class KotlinSourceSetGistTest { ) assertTrue( - mainSourceSetGist.isMain, + mainSourceSetGist.isMain.getSafe(), "Expected main sources to be marked as 'isMain'" ) @@ -57,7 +57,7 @@ class KotlinSourceSetGistTest { val testSourceSetGist = project.gistOf(testSourceSet) assertFalse( - testSourceSetGist.isMain, + testSourceSetGist.isMain.getSafe(), "Expected test source set not being marked as 'isMain'" ) @@ -204,32 +204,32 @@ class KotlinSourceSetGistTest { ) assertTrue( - commonMainSourceSetGist.isMain, + commonMainSourceSetGist.isMain.getSafe(), "Expected commonMain to be marked with 'isMain'" ) assertTrue( - jvmMainSourceSetGist.isMain, + jvmMainSourceSetGist.isMain.getSafe(), "Expected jvmMain to be marked with 'isMain'" ) assertTrue( - macosMainSourceSetGist.isMain, + macosMainSourceSetGist.isMain.getSafe(), "Expected macosMain to be marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["commonTest"]).isMain, + project.gistOf(kotlin.sourceSets["commonTest"]).isMain.getSafe(), "Expected commonTest not being marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["jvmTest"]).isMain, + project.gistOf(kotlin.sourceSets["jvmTest"]).isMain.getSafe(), "Expected jvmTest not being marked with 'isMain'" ) assertFalse( - project.gistOf(kotlin.sourceSets["macosTest"]).isMain, + project.gistOf(kotlin.sourceSets["macosTest"]).isMain.getSafe(), "Expected macosTest not being marked with 'isMain'" ) |