aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/main/kotlin
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-03-13 10:46:33 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2020-03-23 13:57:07 +0100
commitc09bde34ff729ef9b1f3bea602fb53cd4e6dca42 (patch)
tree3a744a16c133b813ab1849761aef1ec3544f401f /runners/gradle-plugin/src/main/kotlin
parentcedf8b7594deef2cd26e981865daa8aae0155520 (diff)
downloaddokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.tar.gz
dokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.tar.bz2
dokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.zip
Gradle Task supporting multimodular projects
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt56
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt37
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt36
3 files changed, 104 insertions, 25 deletions
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
new file mode 100644
index 00000000..f4fa7aaa
--- /dev/null
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt
@@ -0,0 +1,56 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.Project
+import org.gradle.api.UnknownTaskException
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.TaskAction
+import org.gradle.kotlin.dsl.getByName
+import java.lang.IllegalStateException
+
+open class DokkaCollectorTask : DefaultTask() {
+
+ @Input
+ var modules: List<String> = emptyList()
+
+ @Input
+ var outputDirectory: String = ""
+
+ private lateinit var configuration: GradleDokkaConfigurationImpl
+
+ @TaskAction
+ fun collect() {
+ val passesConfigurations = getProjects(project).filter { it.name in modules }.map {
+ val task = try {
+ it.tasks.getByName(DOKKA_TASK_NAME, DokkaTask::class)
+ } catch (e: UnknownTaskException) {
+ throw IllegalStateException("No dokka task declared in module ${it.name}")
+ }
+ task.getConfiguration()
+ }
+
+ val initial = GradleDokkaConfigurationImpl().apply {
+ outputDir = outputDirectory
+ cacheRoot = passesConfigurations.first().cacheRoot
+ format = passesConfigurations.first().format
+ generateIndexPages = passesConfigurations.first().generateIndexPages
+ }
+
+ configuration = passesConfigurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl ->
+ if(acc.format != it.format || acc.generateIndexPages != it.generateIndexPages || acc.cacheRoot != it.cacheRoot)
+ throw IllegalStateException("Dokka task configurations differ on core arguments (format, generateIndexPages, cacheRoot)")
+ acc.passesConfigurations = acc.passesConfigurations + it.passesConfigurations
+ acc.pluginsClasspath = (acc.pluginsClasspath + it.pluginsClasspath).distinct()
+ acc
+ }
+ project.tasks.getByName(DOKKA_TASK_NAME).setProperty("config", configuration)
+ }
+
+ init {
+ finalizedBy(project.tasks.getByName(DOKKA_TASK_NAME))
+ }
+
+ private fun getProjects(project: Project): Set<Project> =
+ project.subprojects + project.subprojects.flatMap { getProjects(it) }
+
+} \ No newline at end of file
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 65b0f4b3..4f7b88c4 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
@@ -8,7 +8,6 @@ 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.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder
import org.jetbrains.dokka.DokkaConfiguration.SourceRoot
import org.jetbrains.dokka.Platform
@@ -76,10 +75,11 @@ open class DokkaTask : DefaultTask() {
@Nested get() = DslObject(this).extensions.getByType(GradlePassConfigurationImpl::class.java)
internal set(value) = DslObject(this).extensions.add(CONFIGURATION_EXTENSION_NAME, value)
+ var config: GradleDokkaConfigurationImpl? = null
+
// Configure Dokka with closure in Gradle Kotlin DSL
fun configuration(action: Action<in GradlePassConfigurationImpl>) = action.execute(configuration)
-
private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks(configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) }
private val configExtractor = ConfigurationExtractor(project)
@@ -133,6 +133,10 @@ open class DokkaTask : DefaultTask() {
@TaskAction
fun generate() {
+ generateForConfig(config ?: getConfiguration())
+ }
+
+ internal fun generateForConfig(configuration: GradleDokkaConfigurationImpl) {
outputDiagnosticInfo = true
val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false"
System.setProperty(COLORS_ENABLED_PROPERTY, "false")
@@ -146,20 +150,6 @@ open class DokkaTask : DefaultTask() {
val gson = GsonBuilder().setPrettyPrinting().create()
- val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME }
- val passConfigurationList = collectConfigurations()
- .map { defaultPassConfiguration(it, globalConfig) }
-
- val configuration = GradleDokkaConfigurationImpl().apply {
- outputDir = outputDirectory
- format = outputFormat
- generateIndexPages = true
- cacheRoot = cacheRoot
- impliedPlatforms = impliedPlatforms
- passesConfigurations = passConfigurationList
- pluginsClasspath = pluginsConfiguration.resolve().toList()
- }
-
bootstrapProxy.configure(
BiConsumer { level, message ->
when (level) {
@@ -180,6 +170,21 @@ open class DokkaTask : DefaultTask() {
}
}
+ internal fun getConfiguration(): GradleDokkaConfigurationImpl {
+ val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME }
+ val defaultModulesConfiguration = collectConfigurations()
+ .map { defaultPassConfiguration(it, globalConfig) }
+ return GradleDokkaConfigurationImpl().apply {
+ outputDir = outputDirectory
+ format = outputFormat
+ generateIndexPages = true
+ cacheRoot = cacheRoot
+ impliedPlatforms = impliedPlatforms
+ passesConfigurations = defaultModulesConfiguration
+ pluginsClasspath = pluginsConfiguration.resolve().toList()
+ }
+ }
+
private fun collectConfigurations() =
if (this.isMultiplatformProject()) collectMultiplatform() else listOf(collectSinglePlatform(configuration))
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 f4ffdab6..4efc5010 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
@@ -10,9 +10,10 @@ import java.util.*
internal const val CONFIGURATION_EXTENSION_NAME = "configuration"
internal const val MULTIPLATFORM_EXTENSION_NAME = "multiplatform"
+internal const val DOKKA_TASK_NAME = "dokka"
+internal const val DOKKA_COLLECTOR_TASK_NAME = "dokkaCollector"
open class DokkaPlugin : Plugin<Project> {
- private val taskName = "dokka"
override fun apply(project: Project) {
loadDokkaVersion()
@@ -20,33 +21,50 @@ open class DokkaPlugin : Plugin<Project> {
val pluginsConfiguration = project.configurations.create("dokkaPlugins").apply {
defaultDependencies { it.add(project.dependencies.create("org.jetbrains.dokka:dokka-base:${DokkaVersion.version}")) }
}
- addTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
+ addDokkaTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
+ addDokkaCollectorTasks(project, DokkaCollectorTask::class.java)
}
- private fun loadDokkaVersion() = DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
+ private fun loadDokkaVersion() =
+ DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
private fun addConfiguration(project: Project) =
project.configurations.create("dokkaRuntime").apply {
- defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) }
+ defaultDependencies { dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) }
}
- private fun addTasks(
+ private fun addDokkaTasks(
project: Project,
runtimeConfiguration: Configuration,
pluginsConfiguration: Configuration,
taskClass: Class<out DokkaTask>
) {
- if(GradleVersion.current() >= GradleVersion.version("4.10")) {
- project.tasks.register(taskName, taskClass)
+ if (GradleVersion.current() >= GradleVersion.version("4.10")) {
+ project.tasks.register(DOKKA_TASK_NAME, taskClass)
} else {
- project.tasks.create(taskName, taskClass)
+ project.tasks.create(DOKKA_TASK_NAME, taskClass)
}
project.tasks.withType(taskClass) { task ->
task.multiplatform = project.container(GradlePassConfigurationImpl::class.java)
task.configuration = GradlePassConfigurationImpl()
task.dokkaRuntime = runtimeConfiguration
task.pluginsConfiguration = pluginsConfiguration
- task.outputDirectory = File(project.buildDir, taskName).absolutePath
+ task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath
+ }
+ }
+
+ private fun addDokkaCollectorTasks(
+ project: Project,
+ taskClass: Class<out DokkaCollectorTask>
+ ) {
+ if (GradleVersion.current() >= GradleVersion.version("4.10")) {
+ project.tasks.register(DOKKA_COLLECTOR_TASK_NAME, taskClass)
+ } else {
+ project.tasks.create(DOKKA_COLLECTOR_TASK_NAME, taskClass)
+ }
+ project.tasks.withType(taskClass) { task ->
+ task.modules = emptyList()
+ task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath
}
}
}