aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/main/kotlin
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-10 10:56:50 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-13 14:23:08 +0200
commitc3eeb211bc51e19e1dc76c2fad4993bcf4999f5d (patch)
tree25eb536ef4384bb95c8da7d8655d0ef1419171a8 /runners/gradle-plugin/src/main/kotlin
parent171f7faed806c9c744d16cf6fafa10f0edcc69b4 (diff)
downloaddokka-c3eeb211bc51e19e1dc76c2fad4993bcf4999f5d.tar.gz
dokka-c3eeb211bc51e19e1dc76c2fad4993bcf4999f5d.tar.bz2
dokka-c3eeb211bc51e19e1dc76c2fad4993bcf4999f5d.zip
Implement `AbstractDokkaTask` to suport DokkaMultimoduleTask
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt51
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt50
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt66
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt7
4 files changed, 88 insertions, 86 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt
new file mode 100644
index 00000000..673148c1
--- /dev/null
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.attributes.Usage
+import org.gradle.api.tasks.Classpath
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.TaskAction
+import org.jetbrains.dokka.DokkaBootstrap
+import org.jetbrains.dokka.plugability.Configurable
+
+abstract class AbstractDokkaTask : DefaultTask(), Configurable {
+ @Input
+ var outputDirectory: String = defaultDokkaOutputDirectory().absolutePath
+
+ @Input
+ override val pluginsConfiguration: Map<String, String> = mutableMapOf()
+
+ @Classpath
+ val plugins: Configuration = project.configurations.create("${name}Plugin").apply {
+ defaultDependencies { dependencies ->
+ dependencies.add(project.dokkaArtifacts.dokkaBase)
+ }
+ attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
+ isCanBeConsumed = false
+ }
+
+ @Classpath
+ val runtime = project.configurations.create("${name}Runtime").apply {
+ defaultDependencies { dependencies ->
+ dependencies.add(project.dokkaArtifacts.dokkaCore)
+ }
+ }
+
+ @TaskAction
+ protected fun run() {
+ val kotlinColorsEnabledBefore = System.getProperty(DokkaTask.COLORS_ENABLED_PROPERTY) ?: "false"
+ System.setProperty(DokkaTask.COLORS_ENABLED_PROPERTY, "false")
+ try {
+ generate()
+ } finally {
+ System.setProperty(DokkaTask.COLORS_ENABLED_PROPERTY, kotlinColorsEnabledBefore)
+ }
+ }
+
+ protected abstract fun generate()
+
+ protected fun DokkaBootstrap(bootstrapClassFQName: String): DokkaBootstrap {
+ return DokkaBootstrap(runtime, bootstrapClassFQName)
+ }
+}
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt
index dd0a5d04..46e13826 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt
@@ -15,55 +15,31 @@ import org.jetbrains.dokka.plugability.Configurable
import java.net.URLClassLoader
import java.util.function.BiConsumer
-open class DokkaMultimoduleTask : DefaultTask(), Configurable {
+open class DokkaMultimoduleTask : AbstractDokkaTask(), Configurable {
@Input
var documentationFileName: String = "README.md"
- @Input
- var outputDirectory: String = defaultDokkaOutputDirectory().absolutePath
@Input
val dokkaTaskNames: MutableSet<String> = mutableSetOf()
- @Classpath
- val runtime = project.configurations.create("${name}Runtime").apply {
- defaultDependencies { dependencies ->
- dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}"))
- }
- }
-
- @Classpath
- val plugins = project.configurations.create("${name}Plugin").apply {
- attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
- isCanBeConsumed = false
- }
-
- @Input
- override val pluginsConfiguration: Map<String, String> = mutableMapOf()
@TaskAction
- fun dokkaMultiplatform() {
- val kotlinColorsEnabledBefore = System.getProperty(DokkaTask.COLORS_ENABLED_PROPERTY) ?: "false"
- System.setProperty(DokkaTask.COLORS_ENABLED_PROPERTY, "false")
-
- try {
- val bootstrap = DokkaBootstrap(runtime, "org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl")
- val gson = GsonBuilder().setPrettyPrinting().create()
- val configuration = getConfiguration()
- bootstrap.configure(gson.toJson(configuration)) { level, message ->
- when (level) {
- "debug" -> logger.debug(message)
- "info" -> logger.info(message)
- "progress" -> logger.lifecycle(message)
- "warn" -> logger.warn(message)
- "error" -> logger.error(message)
- }
+ override fun generate() {
+ val bootstrap = DokkaBootstrap("org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl")
+ val gson = GsonBuilder().setPrettyPrinting().create()
+ val configuration = getConfiguration()
+ bootstrap.configure(gson.toJson(configuration)) { level, message ->
+ when (level) {
+ "debug" -> logger.debug(message)
+ "info" -> logger.info(message)
+ "progress" -> logger.lifecycle(message)
+ "warn" -> logger.warn(message)
+ "error" -> logger.error(message)
}
- bootstrap.generate()
- } finally {
- System.setProperty(DokkaTask.COLORS_ENABLED_PROPERTY, kotlinColorsEnabledBefore)
}
+ bootstrap.generate()
}
@Internal
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 b755c5aa..db25fc47 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
@@ -1,24 +1,24 @@
package org.jetbrains.dokka.gradle
import com.google.gson.GsonBuilder
-import org.gradle.api.*
-import org.gradle.api.artifacts.Configuration
-import org.gradle.api.attributes.Usage
+import org.gradle.api.NamedDomainObjectContainer
+import org.gradle.api.Project
+import org.gradle.api.Task
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.*
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
-import org.jetbrains.dokka.plugability.Configurable
import java.io.File
import java.util.concurrent.Callable
-open class DokkaTask : DefaultTask(), Configurable {
+open class DokkaTask : AbstractDokkaTask() {
private val ANDROID_REFERENCE_URL = Builder("https://developer.android.com/reference/").build()
private val GLOBAL_CONFIGURATION_NAME = "global" // Used for copying perPackageOptions to other platforms
private val configExtractor = ConfigurationExtractor(project)
@@ -44,33 +44,12 @@ open class DokkaTask : DefaultTask(), Configurable {
}
@Input
- var outputDirectory: String = defaultDokkaOutputDirectory().absolutePath
-
- @Input
var subProjects: List<String> = emptyList()
- @Input
- override val pluginsConfiguration: Map<String, String> = mutableMapOf()
-
@Optional
@Input
var cacheRoot: String? = null
- @Classpath
- val runtime = project.configurations.create("${name}Runtime").apply {
- defaultDependencies { dependencies ->
- dependencies.add(project.dokkaArtifacts.dokkaCore)
- }
- }
-
- @Classpath
- val plugins: Configuration = project.configurations.create("${name}Plugin").apply {
- defaultDependencies { dependencies ->
- dependencies.add(project.dokkaArtifacts.dokkaBase)
- }
- attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
- isCanBeConsumed = false
- }
@get:Internal
internal var config: GradleDokkaConfigurationImpl? = null
@@ -140,32 +119,27 @@ open class DokkaTask : DefaultTask(), Configurable {
}
@TaskAction
- fun generate() = config?.let { generate(it) } ?: generate(getConfigurationOrThrow())
+ override fun generate() = config?.let { generate(it) } ?: generate(getConfigurationOrThrow())
protected open fun generate(configuration: GradleDokkaConfigurationImpl) {
outputDiagnosticInfo = true
- val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false"
- System.setProperty(COLORS_ENABLED_PROPERTY, "false")
- try {
- val bootstrap = DokkaBootstrap(runtime, "org.jetbrains.dokka.DokkaBootstrapImpl")
-
- bootstrap.configure(
- GsonBuilder().setPrettyPrinting().create().toJson(configuration)
- ) { level, message ->
- when (level) {
- "debug" -> logger.debug(message)
- "info" -> logger.info(message)
- "progress" -> logger.lifecycle(message)
- "warn" -> logger.warn(message)
- "error" -> logger.error(message)
- }
+ val bootstrap = DokkaBootstrap("org.jetbrains.dokka.DokkaBootstrapImpl")
+
+ bootstrap.configure(
+ GsonBuilder().setPrettyPrinting().create().toJson(configuration)
+ ) { level, message ->
+ when (level) {
+ "debug" -> logger.debug(message)
+ "info" -> logger.info(message)
+ "progress" -> logger.lifecycle(message)
+ "warn" -> logger.warn(message)
+ "error" -> logger.error(message)
}
- bootstrap.generate()
- } finally {
- System.setProperty(COLORS_ENABLED_PROPERTY, kotlinColorsEnabledBefore)
}
+ bootstrap.generate()
}
+
@Internal
internal fun getConfigurationOrNull(): GradleDokkaConfigurationImpl? {
val globalConfig = dokkaSourceSets.toList().find { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME }
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 7fb0fe7d..6114dbce 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
@@ -41,16 +41,17 @@ open class DokkaPlugin : Plugin<Project> {
*
* There is no heavy processing done during configuration of those tasks (I promise).
*/
- private fun Project.createDokkaTasks(name: String, configuration: DokkaTask.() -> Unit = {}) {
+ private fun Project.createDokkaTasks(name: String, configuration: AbstractDokkaTask.() -> Unit = {}) {
project.tasks.create<DokkaTask>(name) {
configuration()
}
- project.tasks.create<DokkaCollectorTask>("${name}Collector") {
+ project.tasks.create<DokkaMultimoduleTask>("${name}Multimodule") {
dokkaTaskNames.add(name)
+ configuration()
}
- project.tasks.create<DokkaMultimoduleTask>("${name}Multimodule") {
+ project.tasks.create<DokkaCollectorTask>("${name}Collector") {
dokkaTaskNames.add(name)
}
}