From 6b0263f65a320116c0b84349a02221f780b8a0d8 Mon Sep 17 00:00:00 2001 From: ingo Date: Sun, 3 Jan 2016 14:17:27 +0100 Subject: Allow multiple dokka tasks for one project. For example, if multiple formats should be generated, adding more tasks like task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" } is now possible. --- dokka-gradle-plugin/src/main/kotlin/main.kt | 72 ++++++++++++++--------------- 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'dokka-gradle-plugin') diff --git a/dokka-gradle-plugin/src/main/kotlin/main.kt b/dokka-gradle-plugin/src/main/kotlin/main.kt index e56b2371..a107260e 100644 --- a/dokka-gradle-plugin/src/main/kotlin/main.kt +++ b/dokka-gradle-plugin/src/main/kotlin/main.kt @@ -15,11 +15,10 @@ import java.util.ArrayList public open class DokkaPlugin : Plugin { override fun apply(project: Project) { - val ext = project.extensions.create("dokka", DokkaExtension::class.java) - project.tasks.create("dokka", DokkaTask::class.java) - - ext.moduleName = project.name - ext.outputDirectory = File(project.buildDir, "dokka").absolutePath + project.tasks.create("dokka", DokkaTask::class.java).apply { + moduleName = project.name + outputDirectory = File(project.buildDir, "dokka").absolutePath + } } } @@ -29,10 +28,32 @@ public open class DokkaTask : DefaultTask() { description = "Generates dokka documentation for Kotlin" } + var moduleName: String = "" + var outputFormat: String = "html" + var outputDirectory: String = "" + var processConfigurations: ArrayList = arrayListOf("compile") + var includes: ArrayList = arrayListOf() + var linkMappings: ArrayList = arrayListOf() + var samples: ArrayList = arrayListOf() + + fun linkMapping(closure: Closure) { + val mapping = LinkMapping() + closure.delegate = mapping + closure.call() + + if (mapping.dir.isEmpty()) { + throw IllegalArgumentException("Link mapping should have dir") + } + if (mapping.url.isEmpty()) { + throw IllegalArgumentException("Link mapping should have url") + } + + linkMappings.add(mapping) + } + @TaskAction fun generate() { val project = project - val conf = project.extensions.getByType(DokkaExtension::class.java) val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) @@ -40,7 +61,7 @@ public open class DokkaTask : DefaultTask() { val allConfigurations = project.configurations val classpath = - conf.processConfigurations + processConfigurations .map { allConfigurations?.getByName(it) ?: throw IllegalArgumentException("No configuration $it found") } .flatMap { it } @@ -53,43 +74,18 @@ public open class DokkaTask : DefaultTask() { DokkaGradleLogger(logger), classpath.map { it.absolutePath }, sourceDirectories.map { it.absolutePath }, - conf.samples, - conf.includes, - conf.moduleName, - conf.outputDirectory, - conf.outputFormat, - conf.linkMappings.map { SourceLinkDefinition(project.file(it.dir).absolutePath, it.url, it.suffix) }, + samples, + includes, + moduleName, + outputDirectory, + outputFormat, + linkMappings.map { SourceLinkDefinition(project.file(it.dir).absolutePath, it.url, it.suffix) }, false ).generate() } } -public open class DokkaExtension { - var moduleName: String = "" - var outputFormat: String = "html" - var outputDirectory: String = "" - var processConfigurations: ArrayList = arrayListOf("compile") - var includes: ArrayList = arrayListOf() - var linkMappings: ArrayList = arrayListOf() - var samples: ArrayList = arrayListOf() - - fun linkMapping(closure: Closure) { - val mapping = LinkMapping() - closure.delegate = mapping - closure.call() - - if (mapping.dir.isEmpty()) { - throw IllegalArgumentException("Link mapping should have dir") - } - if (mapping.url.isEmpty()) { - throw IllegalArgumentException("Link mapping should have url") - } - - linkMappings.add(mapping) - } -} - public open class LinkMapping { var dir: String = "" var url: String = "" -- cgit From e0c6c1a58ff09e657d41f2bca6943486cb877f25 Mon Sep 17 00:00:00 2001 From: ingo Date: Sun, 3 Jan 2016 16:25:21 +0100 Subject: dokka gradle tasks now know when they are up-to-date. --- dokka-gradle-plugin/src/main/kotlin/main.kt | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'dokka-gradle-plugin') diff --git a/dokka-gradle-plugin/src/main/kotlin/main.kt b/dokka-gradle-plugin/src/main/kotlin/main.kt index a107260e..28600a6b 100644 --- a/dokka-gradle-plugin/src/main/kotlin/main.kt +++ b/dokka-gradle-plugin/src/main/kotlin/main.kt @@ -4,10 +4,10 @@ import groovy.lang.Closure import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.file.FileCollection import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPluginConvention -import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaGenerator import org.jetbrains.dokka.SourceLinkDefinition import java.io.File @@ -28,12 +28,18 @@ public open class DokkaTask : DefaultTask() { description = "Generates dokka documentation for Kotlin" } + @Input var moduleName: String = "" + @Input var outputFormat: String = "html" var outputDirectory: String = "" + @Input var processConfigurations: ArrayList = arrayListOf("compile") + @Input var includes: ArrayList = arrayListOf() + @Input var linkMappings: ArrayList = arrayListOf() + @Input var samples: ArrayList = arrayListOf() fun linkMapping(closure: Closure) { @@ -54,10 +60,7 @@ public open class DokkaTask : DefaultTask() { @TaskAction fun generate() { val project = project - val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) - - val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) - val sourceDirectories = sourceSets?.allSource?.srcDirs?.filter { it.exists() } ?: emptyList() + val sourceDirectories = getSourceDirectories() val allConfigurations = project.configurations val classpath = @@ -84,6 +87,19 @@ public open class DokkaTask : DefaultTask() { ).generate() } + fun getSourceDirectories(): List { + val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) + val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) + return sourceSets?.allSource?.srcDirs?.filter { it.exists() } ?: emptyList() + } + + @InputFiles + @SkipWhenEmpty + fun getIncludedFiles() : FileCollection = project.files(getSourceDirectories().map { project.fileTree(it) }) + + @OutputDirectory + fun getOutputDirectoryAsFile() : File = project.file(outputDirectory) + } public open class LinkMapping { -- cgit