diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-30 23:06:03 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-06 17:59:15 +0200 |
commit | b0e8622f374f6499058b0f083367b4a54512b702 (patch) | |
tree | 0fa641dc26bf1e7ed6497ee2340999e8ecc505ad /runners/gradle-plugin/src/main/kotlin | |
parent | b0b418334535adc60ee80c3df1b2293dfcaad071 (diff) | |
download | dokka-b0e8622f374f6499058b0f083367b4a54512b702.tar.gz dokka-b0e8622f374f6499058b0f083367b4a54512b702.tar.bz2 dokka-b0e8622f374f6499058b0f083367b4a54512b702.zip |
Enforce workspace unique SourceSetID
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
6 files changed, 113 insertions, 40 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index 3bd0b6ab..c9693467 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -169,4 +169,4 @@ class ConfigurationExtractor(private val project: Project) { val dependentSourceSets: List<String>, val platform: String ) : Serializable -}
\ No newline at end of file +} 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 ead0f90a..823206e3 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 @@ -19,7 +19,7 @@ open class DokkaCollectorTask : DefaultTask() { @TaskAction fun collect() { - val passesConfigurations = getProjects(project).filter { it.name in modules }.flatMap { + val sourceSets = getProjects(project).filter { it.name in modules }.flatMap { val tasks = try { it.tasks.withType(DokkaTask::class.java) } catch (e: UnknownTaskException) { @@ -30,11 +30,11 @@ open class DokkaCollectorTask : DefaultTask() { val initial = GradleDokkaConfigurationImpl().apply { outputDir = outputDirectory - cacheRoot = passesConfigurations.first().cacheRoot - format = passesConfigurations.first().format + cacheRoot = sourceSets.first().cacheRoot + format = sourceSets.first().format } - configuration = passesConfigurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl -> + configuration = sourceSets.fold(initial) { acc, it: GradleDokkaConfigurationImpl -> if(acc.format != it.format || acc.cacheRoot != it.cacheRoot) throw IllegalStateException("Dokka task configurations differ on core arguments (format, cacheRoot)") acc.sourceSets = acc.sourceSets + it.sourceSets diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt new file mode 100644 index 00000000..3fadb4fd --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt @@ -0,0 +1,10 @@ +@file:Suppress("FunctionName") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.Project +import org.jetbrains.dokka.DokkaSourceSetID + +internal fun DokkaSourceSetID(project: Project, sourceSetName: String): DokkaSourceSetID { + return DokkaSourceSetID(moduleName = project.path, sourceSetName = sourceSetName) +} 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 e27357c9..aac7e2a0 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 @@ -7,11 +7,9 @@ import org.gradle.api.file.FileCollection import org.gradle.api.internal.plugins.DslObject import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.* -import org.jetbrains.dokka.DokkaBootstrap +import org.jetbrains.dokka.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot -import org.jetbrains.dokka.DokkaException -import org.jetbrains.dokka.Platform import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance import org.jetbrains.dokka.gradle.ConfigurationExtractor.PlatformData @@ -183,10 +181,7 @@ open class DokkaTask : DefaultTask(), Configurable { val defaultModulesConfiguration = configuredDokkaSourceSets .map { configureDefault(it, globalConfig) }.takeIf { it.isNotEmpty() } ?: listOf( - configureDefault( - configureDokkaSourceSet(GradleDokkaSourceSet("main")), - null - ) + configureDefault(configureDokkaSourceSet(GradleDokkaSourceSet("main", project)), null) ).takeIf { project.isNotMultiplatformProject() } ?: emptyList() if (defaultModulesConfiguration.isEmpty()) { @@ -288,28 +283,25 @@ open class DokkaTask : DefaultTask(), Configurable { protected fun mergeUserConfigurationAndPlatformData( userConfig: GradleDokkaSourceSet, autoConfig: PlatformData - ) = - userConfig.copy().apply { - sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) - dependentSourceSets.addAll(userConfig.dependentSourceSets.union(autoConfig.dependentSourceSets).distinct()) - classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() - if (userConfig.platform == null && autoConfig.platform != "") - platform = autoConfig.platform - } + ) = userConfig.copy().apply { + sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) + dependentSourceSets.addAll(userConfig.dependentSourceSets) + dependentSourceSets.addAll(autoConfig.dependentSourceSets.map { DokkaSourceSetID(project, it) }) + classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() + if (userConfig.platform == null && autoConfig.platform != "") + platform = autoConfig.platform + } protected fun configureDefault( config: GradleDokkaSourceSet, globalConfig: GradleDokkaSourceSet? ): GradleDokkaSourceSet { - if (config.moduleName.isBlank()) { - config.moduleName = project.name + if (config.moduleDisplayName.isBlank()) { + config.moduleDisplayName = project.name } - if (config.sourceSetID.isBlank()) { - config.sourceSetID = config.moduleName + "/" + config.name - } - config.dependentSourceSets = config.dependentSourceSets.map { config.moduleName + "/" + it }.toMutableList() + if (config.displayName.isBlank()) { - config.displayName = config.sourceSetID.substringBeforeLast("Main", config.platform.toString()) + config.displayName = config.name.substringBeforeLast("Main", config.platform.toString()) } config.classpath = (config.classpath as List<Any>).map { it.toString() }.distinct() // Workaround for Groovy's GStringImpl diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index a28416d6..7b2d05a6 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -1,13 +1,19 @@ +@file:Suppress("FunctionName") + package org.jetbrains.dokka.gradle +import com.android.build.gradle.api.AndroidSourceSet import groovy.lang.Closure import org.gradle.api.Action +import org.gradle.api.Project import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional import org.gradle.util.ConfigureUtil import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.* import org.jetbrains.dokka.DokkaDefaults +import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.Platform import java.io.File import java.io.Serializable @@ -15,6 +21,8 @@ import java.net.URL import java.util.concurrent.Callable import kotlin.reflect.KMutableProperty import kotlin.reflect.full.memberProperties +import org.gradle.api.tasks.SourceSet as GradleSourceSet +import org.jetbrains.kotlin.gradle.model.SourceSet as KotlinSourceSet class GradleSourceRootImpl : SourceRoot, Serializable { override var path: String = "" @@ -25,64 +33,113 @@ class GradleSourceRootImpl : SourceRoot, Serializable { override fun toString(): String = path } -open class GradleDokkaSourceSet(@Transient val name: String = "") : DokkaSourceSet { +open class GradleDokkaSourceSet constructor( + @Transient val name: String, + @Transient internal val project: Project +) : DokkaSourceSet { + @Input @Optional override var classpath: List<String> = emptyList() + @Input - override var moduleName: String = "" + override var moduleDisplayName: String = "" + @Input override var displayName: String = "" - @Input - override var sourceSetID: String = "" + + @get:Internal + override val sourceSetID: DokkaSourceSetID = DokkaSourceSetID(project, name) + @Input override var sourceRoots: MutableList<SourceRoot> = mutableListOf() + @Input - override var dependentSourceSets: MutableList<String> = mutableListOf() + override var dependentSourceSets: MutableSet<DokkaSourceSetID> = mutableSetOf() + @Input override var samples: List<String> = emptyList() + @Input override var includes: List<String> = emptyList() + @Input override var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic + @Input override var includeRootPackage: Boolean = DokkaDefaults.includeRootPackage + @Input override var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented + @Input override var skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages + @Input override var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated + @Input override var jdkVersion: Int = DokkaDefaults.jdkVersion + @Input override var sourceLinks: MutableList<SourceLinkDefinition> = mutableListOf() + @Input override var perPackageOptions: MutableList<PackageOptions> = mutableListOf() + @Input override var externalDocumentationLinks: MutableList<ExternalDocumentationLink> = mutableListOf() + @Input @Optional override var languageVersion: String? = null + @Input @Optional override var apiVersion: String? = null + @Input override var noStdlibLink: Boolean = DokkaDefaults.noStdlibLink + @Input override var noJdkLink: Boolean = DokkaDefaults.noJdkLink + @Input var noAndroidSdkLink: Boolean = false + @Input override var suppressedFiles: List<String> = emptyList() + @Input override var analysisPlatform: Platform = DokkaDefaults.analysisPlatform + @Input @Optional var platform: String? = null + @Transient var collectKotlinTasks: (() -> List<Any?>?)? = null + fun DokkaSourceSetID(sourceSetName: String): DokkaSourceSetID { + return DokkaSourceSetID(project, sourceSetName) + } + + fun dependsOn(sourceSet: GradleSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) + } + + fun dependsOn(sourceSet: DokkaSourceSet) { + dependsOn(sourceSet.sourceSetID) + } + + fun dependsOn(sourceSetName: String) { + dependsOn(DokkaSourceSetID(sourceSetName)) + } + + fun dependsOn(sourceSetID: DokkaSourceSetID) { + dependentSourceSets.add(sourceSetID) + } + fun kotlinTasks(taskSupplier: Callable<List<Any>>) { collectKotlinTasks = { taskSupplier.call() } } @@ -136,6 +193,18 @@ open class GradleDokkaSourceSet(@Transient val name: String = "") : DokkaSourceS } } +fun GradleDokkaSourceSet.dependsOn(sourceSet: KotlinSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + +fun GradleDokkaSourceSet.dependsOn(sourceSet: org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + +fun GradleDokkaSourceSet.dependsOn(sourceSet: AndroidSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + class GradleSourceLinkDefinitionImpl : SourceLinkDefinition, Serializable { override var path: String = "" override var url: String = "" @@ -174,16 +243,16 @@ class GradlePackageOptionsImpl : PackageOptions, Serializable { } internal fun GradleDokkaSourceSet.copy(): GradleDokkaSourceSet { - val newObj = GradleDokkaSourceSet(this.name) + val newObj = GradleDokkaSourceSet(this.name, this.project) this::class.memberProperties.forEach { field -> if (field is KMutableProperty<*>) { - val value = field.getter.call(this) - if (value is Collection<*>) { - field.setter.call(newObj, value.toMutableList()) - } else { - field.setter.call(newObj, field.getter.call(this)) + when (val value = field.getter.call(this)) { + is List<*> -> field.setter.call(newObj, value.toMutableList()) + is Set<*> -> field.setter.call(newObj, value.toMutableSet()) + else -> field.setter.call(newObj, field.getter.call(this)) } + } } return newObj -}
\ No newline at end of file +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index 92d63a40..a92f5475 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -53,7 +53,9 @@ open class DokkaPlugin : Plugin<Project> { project.tasks.create(DOKKA_TASK_NAME, taskClass) } project.tasks.withType(taskClass) { task -> - task.dokkaSourceSets = project.container(GradleDokkaSourceSet::class.java) + task.dokkaSourceSets = project.container(GradleDokkaSourceSet::class.java) { name -> + GradleDokkaSourceSet(name, project) + } task.dokkaRuntime = runtimeConfiguration task.pluginsClasspathConfiguration = pluginsConfiguration task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath |