aboutsummaryrefslogtreecommitdiff
path: root/dokka-gradle-plugin/src/main
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-11-05 17:33:16 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-11-05 17:33:16 +0100
commit979dbca7bedeffc9bd91159fcf6a9a06b1cf1564 (patch)
treeec11169d9441bd2de776256daaca648e3c0e499d /dokka-gradle-plugin/src/main
parent4164f9f3cd3aeb90150f483345f15a93a9e0c5f0 (diff)
downloaddokka-979dbca7bedeffc9bd91159fcf6a9a06b1cf1564.tar.gz
dokka-979dbca7bedeffc9bd91159fcf6a9a06b1cf1564.tar.bz2
dokka-979dbca7bedeffc9bd91159fcf6a9a06b1cf1564.zip
setup multi-project build; specify version in one place for all Gradle project
Diffstat (limited to 'dokka-gradle-plugin/src/main')
-rw-r--r--dokka-gradle-plugin/src/main/kotlin/logger.kt18
-rw-r--r--dokka-gradle-plugin/src/main/kotlin/main.kt97
-rw-r--r--dokka-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties1
3 files changed, 116 insertions, 0 deletions
diff --git a/dokka-gradle-plugin/src/main/kotlin/logger.kt b/dokka-gradle-plugin/src/main/kotlin/logger.kt
new file mode 100644
index 00000000..715c1f04
--- /dev/null
+++ b/dokka-gradle-plugin/src/main/kotlin/logger.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.api.logging.Logger
+import org.jetbrains.dokka.DokkaLogger
+
+class DokkaGradleLogger(val logger: Logger) : DokkaLogger {
+ override fun error(message: String) {
+ logger.error(message)
+ }
+
+ override fun info(message: String) {
+ logger.info(message)
+ }
+
+ override fun warn(message: String) {
+ logger.warn(message)
+ }
+} \ No newline at end of file
diff --git a/dokka-gradle-plugin/src/main/kotlin/main.kt b/dokka-gradle-plugin/src/main/kotlin/main.kt
new file mode 100644
index 00000000..e56b2371
--- /dev/null
+++ b/dokka-gradle-plugin/src/main/kotlin/main.kt
@@ -0,0 +1,97 @@
+package org.jetbrains.dokka.gradle
+
+import groovy.lang.Closure
+import org.gradle.api.DefaultTask
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+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.jetbrains.dokka.DokkaGenerator
+import org.jetbrains.dokka.SourceLinkDefinition
+import java.io.File
+import java.util.ArrayList
+
+public open class DokkaPlugin : Plugin<Project> {
+ 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
+ }
+}
+
+public open class DokkaTask : DefaultTask() {
+ init {
+ group = JavaBasePlugin.DOCUMENTATION_GROUP
+ description = "Generates dokka documentation for Kotlin"
+ }
+
+ @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)
+ val sourceDirectories = sourceSets?.allSource?.srcDirs?.filter { it.exists() } ?: emptyList()
+ val allConfigurations = project.configurations
+
+ val classpath =
+ conf.processConfigurations
+ .map { allConfigurations?.getByName(it) ?: throw IllegalArgumentException("No configuration $it found") }
+ .flatMap { it }
+
+ if (sourceDirectories.isEmpty()) {
+ logger.warn("No source directories found: skipping dokka generation")
+ return
+ }
+
+ DokkaGenerator(
+ 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) },
+ false
+ ).generate()
+ }
+
+}
+
+public open class DokkaExtension {
+ var moduleName: String = ""
+ var outputFormat: String = "html"
+ var outputDirectory: String = ""
+ var processConfigurations: ArrayList<String> = arrayListOf("compile")
+ var includes: ArrayList<String> = arrayListOf()
+ var linkMappings: ArrayList<LinkMapping> = arrayListOf()
+ var samples: ArrayList<String> = arrayListOf()
+
+ fun linkMapping(closure: Closure<Any?>) {
+ 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 = ""
+ var suffix: String? = null
+}
diff --git a/dokka-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties b/dokka-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties
new file mode 100644
index 00000000..b42cfe9f
--- /dev/null
+++ b/dokka-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties
@@ -0,0 +1 @@
+implementation-class=org.jetbrains.dokka.gradle.DokkaPlugin \ No newline at end of file