aboutsummaryrefslogtreecommitdiff
path: root/runners
diff options
context:
space:
mode:
authorSimon Ogorodnik <sem-oro@yandex.ru>2016-11-01 02:10:32 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2016-11-01 14:46:01 +0300
commit769701f99a1aefbc9d385c1938c9c7d3a7b2e38e (patch)
treec3ea4802d9e627c90870808aba9343eb224a114c /runners
parent08bcaa257f7b48929af6ee29007dd6f0d7bb1b52 (diff)
downloaddokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.tar.gz
dokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.tar.bz2
dokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.zip
Total build refactoring, prepare for new development iteration
Removed old and useless build helpers Remove old .xml's from .idea and add .idea/shelf to .gitignore build-docs.xml fixed, dokka_version set to 0.9.10
Diffstat (limited to 'runners')
-rw-r--r--runners/android-gradle-plugin/build.gradle57
-rw-r--r--runners/android-gradle-plugin/src/main/kotlin/main.kt76
-rw-r--r--runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties1
-rw-r--r--runners/ant/build.gradle16
-rw-r--r--runners/ant/src/main/kotlin/ant/dokka.kt101
-rw-r--r--runners/build.gradle9
-rw-r--r--runners/cli/build.gradle6
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt92
-rw-r--r--runners/fatjar/build.gradle62
-rw-r--r--runners/gradle-plugin/build.gradle58
-rw-r--r--runners/gradle-plugin/src/main/kotlin/logger.kt18
-rw-r--r--runners/gradle-plugin/src/main/kotlin/main.kt190
-rw-r--r--runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties1
-rw-r--r--runners/maven-plugin/build.gradle80
-rw-r--r--runners/maven-plugin/pom.tpl.xml26
-rw-r--r--runners/maven-plugin/src/main/kotlin/DokkaMojo.kt179
-rw-r--r--runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt18
17 files changed, 990 insertions, 0 deletions
diff --git a/runners/android-gradle-plugin/build.gradle b/runners/android-gradle-plugin/build.gradle
new file mode 100644
index 00000000..dd6f2e3d
--- /dev/null
+++ b/runners/android-gradle-plugin/build.gradle
@@ -0,0 +1,57 @@
+apply plugin: 'java'
+
+sourceCompatibility = 1.6
+
+task wrapper(type: Wrapper) {
+ gradleVersion = '2.5'
+ distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
+}
+
+apply plugin: 'com.github.johnrengelman.shadow'
+
+configurations {
+ provided
+}
+
+tasks.withType(AbstractCompile) {
+ classpath += configurations.provided
+ classpath += configurations.shadow
+}
+
+dependencies {
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+ shadow project(':runners:fatjar')
+ shadow project(':runners:gradle-plugin')
+
+ provided gradleApi()
+ provided localGroovy()
+
+ shadow 'com.android.tools.build:gradle:2.0.0'
+}
+
+task sourceJar(type: Jar) {
+ from sourceSets.main.allSource
+}
+
+shadowJar {
+ baseName = 'dokka-android-gradle-plugin'
+ classifier = ''
+ relocate('kotlin.', 'dokkakotlin.')
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+ publications {
+ dokkaAndroidGradlePlugin(MavenPublication) {
+ from components.shadow
+ artifactId = 'dokka-android-gradle-plugin'
+
+ artifact sourceJar {
+ classifier "sources"
+ }
+ }
+ }
+}
+
+bintrayPublication(project, ['dokkaAndroidGradlePlugin']) \ No newline at end of file
diff --git a/runners/android-gradle-plugin/src/main/kotlin/main.kt b/runners/android-gradle-plugin/src/main/kotlin/main.kt
new file mode 100644
index 00000000..054ed358
--- /dev/null
+++ b/runners/android-gradle-plugin/src/main/kotlin/main.kt
@@ -0,0 +1,76 @@
+package org.jetbrains.dokka.gradle
+
+import com.android.build.gradle.AppExtension
+import com.android.build.gradle.LibraryExtension
+import com.android.build.gradle.api.BaseVariant
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.tasks.SourceSet
+import java.io.File
+
+open class DokkaAndroidPlugin : Plugin<Project> {
+ val allVariantsClassPath = mutableSetOf<File>()
+
+ override fun apply(project: Project) {
+ project.tasks.create("dokka", DokkaAndroidTask::class.java).apply {
+ moduleName = project.name
+ outputDirectory = File(project.buildDir, "dokka").absolutePath
+ }
+
+ if (project.hasAndroidPlugin()) {
+ project.afterEvaluate {
+ collectClasspath(project)
+ }
+ }
+ else {
+ project.plugins.whenPluginAdded {
+ if (project.hasAndroidPlugin()) {
+ collectClasspath(project)
+ }
+ }
+ }
+ }
+
+ private fun collectClasspath(project: Project) {
+ val variants = project.collectAllVariants()
+ variants.flatMapTo(allVariantsClassPath) { it.javaCompiler.classpath.files }
+ }
+}
+
+open class DokkaAndroidTask : DokkaTask() {
+ override val sdkProvider: SdkProvider? = AndroidSdkProvider(project)
+}
+
+private fun Project.hasAndroidPlugin() = plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application")
+
+private fun Project.findDokkaAndroidPlugin() = plugins.findPlugin(DokkaAndroidPlugin::class.java)
+
+private fun Project.collectAllVariants(): Collection<BaseVariant> {
+ extensions.findByType(LibraryExtension::class.java)?.let {
+ return it.libraryVariants
+ }
+ extensions.findByType(AppExtension::class.java)?.let {
+ return it.applicationVariants
+ }
+ return emptyList()
+}
+
+private class AndroidSdkProvider(private val project: Project) : SdkProvider {
+ private val ext by lazy {
+ project.extensions.findByType(LibraryExtension::class.java) ?: project.extensions.findByType(AppExtension::class.java)
+ }
+
+ override val name: String = "android"
+
+ override val isValid: Boolean
+ get() = project.hasAndroidPlugin()
+
+ override val classpath: List<File>
+ get() = ext.bootClasspath + (project.findDokkaAndroidPlugin()?.allVariantsClassPath ?: emptyList<File>())
+
+ override val sourceDirs: Set<File>?
+ get() {
+ val sourceSet = ext?.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME)
+ return sourceSet?.java?.srcDirs
+ }
+}
diff --git a/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties b/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties
new file mode 100644
index 00000000..03b28d93
--- /dev/null
+++ b/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties
@@ -0,0 +1 @@
+implementation-class=org.jetbrains.dokka.gradle.DokkaAndroidPlugin \ No newline at end of file
diff --git a/runners/ant/build.gradle b/runners/ant/build.gradle
new file mode 100644
index 00000000..3c4d4ddb
--- /dev/null
+++ b/runners/ant/build.gradle
@@ -0,0 +1,16 @@
+sourceCompatibility = 1.5
+
+configurations {
+ provided
+}
+
+tasks.withType(AbstractCompile) {
+ classpath += configurations.provided
+}
+
+
+dependencies {
+ compile project(":core")
+ provided group: 'org.apache.ant', name: 'ant', version: ant_version
+}
+
diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt
new file mode 100644
index 00000000..38dc543b
--- /dev/null
+++ b/runners/ant/src/main/kotlin/ant/dokka.kt
@@ -0,0 +1,101 @@
+package org.jetbrains.dokka.ant
+
+import org.apache.tools.ant.BuildException
+import org.apache.tools.ant.Project
+import org.apache.tools.ant.Task
+import org.apache.tools.ant.types.Path
+import org.apache.tools.ant.types.Reference
+import org.jetbrains.dokka.DocumentationOptions
+import org.jetbrains.dokka.DokkaGenerator
+import org.jetbrains.dokka.DokkaLogger
+import org.jetbrains.dokka.SourceLinkDefinition
+import java.io.File
+
+class AntLogger(val task: Task): DokkaLogger {
+ override fun info(message: String) = task.log(message, Project.MSG_INFO)
+ override fun warn(message: String) = task.log(message, Project.MSG_WARN)
+ override fun error(message: String) = task.log(message, Project.MSG_ERR)
+}
+
+class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null)
+
+class DokkaAntTask(): Task() {
+ var moduleName: String? = null
+ var outputDir: String? = null
+ var outputFormat: String = "html"
+ var jdkVersion: Int = 6
+
+ var skipDeprecated: Boolean = false
+
+ val compileClasspath: Path by lazy { Path(getProject()) }
+ val sourcePath: Path by lazy { Path(getProject()) }
+ val samplesPath: Path by lazy { Path(getProject()) }
+ val includesPath: Path by lazy { Path(getProject()) }
+
+ val antSourceLinks: MutableList<AntSourceLinkDefinition> = arrayListOf()
+
+ fun setClasspath(classpath: Path) {
+ compileClasspath.append(classpath)
+ }
+
+ fun setClasspathRef(ref: Reference) {
+ compileClasspath.createPath().refid = ref
+ }
+
+ fun setSrc(src: Path) {
+ sourcePath.append(src)
+ }
+
+ fun setSrcRef(ref: Reference) {
+ sourcePath.createPath().refid = ref
+ }
+
+ fun setSamples(samples: Path) {
+ samplesPath.append(samples)
+ }
+
+ fun setSamplesRef(ref: Reference) {
+ samplesPath.createPath().refid = ref
+ }
+
+ fun setInclude(include: Path) {
+ includesPath.append(include)
+ }
+
+ fun createSourceLink(): AntSourceLinkDefinition {
+ val def = AntSourceLinkDefinition()
+ antSourceLinks.add(def)
+ return def
+ }
+
+ override fun execute() {
+ if (sourcePath.list().size == 0) {
+ throw BuildException("At least one source path needs to be specified")
+ }
+ if (moduleName == null) {
+ throw BuildException("Module name needs to be specified")
+ }
+ if (outputDir == null) {
+ throw BuildException("Output directory needs to be specified")
+ }
+ val sourceLinks = antSourceLinks.map {
+ val path = it.path ?: throw BuildException("'path' attribute of a <sourceLink> element is required")
+ val url = it.url ?: throw BuildException("'url' attribute of a <sourceLink> element is required")
+ SourceLinkDefinition(File(path).canonicalFile.absolutePath, url, it.lineSuffix)
+ }
+
+ val generator = DokkaGenerator(
+ AntLogger(this),
+ compileClasspath.list().toList(),
+ sourcePath.list().toList(),
+ samplesPath.list().toList(),
+ includesPath.list().toList(),
+ moduleName!!,
+ DocumentationOptions(outputDir!!, outputFormat,
+ skipDeprecated = skipDeprecated,
+ sourceLinks = sourceLinks,
+ jdkVersion = jdkVersion)
+ )
+ generator.generate()
+ }
+} \ No newline at end of file
diff --git a/runners/build.gradle b/runners/build.gradle
new file mode 100644
index 00000000..574f5ac7
--- /dev/null
+++ b/runners/build.gradle
@@ -0,0 +1,9 @@
+buildscript {
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+
+subprojects {
+ apply plugin: 'kotlin'
+}
diff --git a/runners/cli/build.gradle b/runners/cli/build.gradle
new file mode 100644
index 00000000..2dbaa793
--- /dev/null
+++ b/runners/cli/build.gradle
@@ -0,0 +1,6 @@
+sourceCompatibility = 1.5
+
+dependencies {
+ compile project(":core")
+ compile "com.github.spullara.cli-parser:cli-parser:1.1.1"
+}
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
new file mode 100644
index 00000000..f4e81241
--- /dev/null
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -0,0 +1,92 @@
+package org.jetbrains.dokka
+
+import com.sampullara.cli.Args
+import com.sampullara.cli.Argument
+import org.jetbrains.kotlin.cli.common.arguments.ValueDescription
+import java.io.File
+
+class DokkaArguments {
+ @set:Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
+ @ValueDescription("<path>")
+ var src: String = ""
+
+ @set:Argument(value = "srcLink", description = "Mapping between a source directory and a Web site for browsing the code")
+ @ValueDescription("<path>=<url>[#lineSuffix]")
+ var srcLink: String = ""
+
+ @set:Argument(value = "include", description = "Markdown files to load (allows many paths separated by the system path separator)")
+ @ValueDescription("<path>")
+ var include: String = ""
+
+ @set:Argument(value = "samples", description = "Source root for samples")
+ @ValueDescription("<path>")
+ var samples: String = ""
+
+ @set:Argument(value = "output", description = "Output directory path")
+ @ValueDescription("<path>")
+ var outputDir: String = "out/doc/"
+
+ @set:Argument(value = "format", description = "Output format (text, html, markdown, jekyll, kotlin-website)")
+ @ValueDescription("<name>")
+ var outputFormat: String = "html"
+
+ @set:Argument(value = "module", description = "Name of the documentation module")
+ @ValueDescription("<name>")
+ var moduleName: String = ""
+
+ @set:Argument(value = "classpath", description = "Classpath for symbol resolution")
+ @ValueDescription("<path>")
+ var classpath: String = ""
+
+ @set:Argument(value = "nodeprecated", description = "Exclude deprecated members from documentation")
+ var nodeprecated: Boolean = false
+
+ @set:Argument(value = "jdkVersion", description = "Version of JDK to use for linking to JDK JavaDoc")
+ var jdkVersion: Int = 6
+}
+
+private fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition {
+ val (path, urlAndLine) = srcLink.split('=')
+ return SourceLinkDefinition(File(path).absolutePath,
+ urlAndLine.substringBefore("#"),
+ urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it })
+}
+
+fun main(args: Array<String>) {
+ val arguments = DokkaArguments()
+ val freeArgs: List<String> = Args.parse(arguments, args) ?: listOf()
+ val sources = if (arguments.src.isNotEmpty()) arguments.src.split(File.pathSeparatorChar).toList() + freeArgs else freeArgs
+ val samples = if (arguments.samples.isNotEmpty()) arguments.samples.split(File.pathSeparatorChar).toList() else listOf()
+ val includes = if (arguments.include.isNotEmpty()) arguments.include.split(File.pathSeparatorChar).toList() else listOf()
+
+ val sourceLinks = if (arguments.srcLink.isNotEmpty() && arguments.srcLink.contains("="))
+ listOf(parseSourceLinkDefinition(arguments.srcLink))
+ else {
+ if (arguments.srcLink.isNotEmpty()) {
+ println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.")
+ }
+ listOf()
+ }
+
+ val classPath = arguments.classpath.split(File.pathSeparatorChar).toList()
+
+ val documentationOptions = DocumentationOptions(
+ arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' },
+ arguments.outputFormat,
+ skipDeprecated = arguments.nodeprecated,
+ sourceLinks = sourceLinks
+ )
+
+ val generator = DokkaGenerator(
+ DokkaConsoleLogger,
+ classPath,
+ sources,
+ samples,
+ includes,
+ arguments.moduleName,
+ documentationOptions)
+
+ generator.generate()
+ DokkaConsoleLogger.report()
+}
+
diff --git a/runners/fatjar/build.gradle b/runners/fatjar/build.gradle
new file mode 100644
index 00000000..df20c9b9
--- /dev/null
+++ b/runners/fatjar/build.gradle
@@ -0,0 +1,62 @@
+import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
+import org.jetbrains.PluginXmlTransformer
+
+apply plugin: 'com.github.johnrengelman.shadow'
+
+dependencies {
+ compile project(":runners:cli")
+ compile project(":runners:ant")
+}
+
+shadowJar {
+ baseName = 'dokka-fatjar'
+ classifier = ''
+
+ configurations {
+ exclude provided
+ }
+
+ relocate('com.', 'dokkacom.') {
+ exclude 'com.sun.**'
+ }
+
+ relocate('org.', 'dokkaorg.') {
+ exclude 'org.jetbrains.dokka.**'
+ exclude 'org.xml.**'
+ exclude 'org.w3c.**'
+ exclude 'org.jaxen.**'
+ exclude 'org.apache.xerces.**'
+ exclude 'org.apache.xml.**'
+ exclude 'org.fusesource.jansi.**'
+ exclude 'org.apache.tools.ant.**'
+ }
+
+
+ relocate('kotlin.', 'dokkakotlin.') {
+ exclude '**.*kotlin_builtins' //For kotlin_builtins, still not sure that we should relocate kotlin stdlib
+ exclude 'kotlin.reflect' /* WAT? Ok, ok. Relocate works as Ctrl + Shift + R for ALL class files, so,
+ if you have string "kotlin.reflect", it will be rewritten to not relevant "dokkakotlin.reflect" and you will got
+ builtins crash in runtime, cause could not find dokkakotlin/reflect/reflect.kotlin_builtins */
+ }
+
+ transform(ServiceFileTransformer)
+ transform(PluginXmlTransformer)
+
+ exclude 'colorScheme/**'
+ exclude 'fileTemplates/**'
+ exclude 'inspectionDescriptions/**'
+ exclude 'intentionDescriptions/**'
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+ publications {
+ dokkaFatJar(MavenPublication) {
+ from components.shadow
+ artifactId = 'dokka-fatjar'
+ }
+ }
+}
+
+bintrayPublication(project, ["dokkaFatJar"]) \ No newline at end of file
diff --git a/runners/gradle-plugin/build.gradle b/runners/gradle-plugin/build.gradle
new file mode 100644
index 00000000..50997889
--- /dev/null
+++ b/runners/gradle-plugin/build.gradle
@@ -0,0 +1,58 @@
+apply plugin: 'java'
+
+sourceCompatibility = 1.6
+
+apply plugin: 'com.github.johnrengelman.shadow'
+
+configurations {
+ provided
+}
+
+tasks.withType(AbstractCompile) {
+ classpath += configurations.provided
+ classpath += configurations.shadow
+}
+
+dependencies {
+
+ shadow project(':runners:fatjar')
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+
+ provided group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: kotlin_version
+ provided group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
+ provided gradleApi()
+ provided localGroovy()
+}
+
+task sourceJar(type: Jar) {
+ from sourceSets.main.allSource
+}
+
+task wrapper(type: Wrapper) {
+ gradleVersion = '2.5'
+ distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
+}
+
+shadowJar {
+ baseName = 'dokka-gradle-plugin'
+ classifier = ''
+ relocate('kotlin.', 'dokkakotlin.')
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+ publications {
+ dokkaGradlePlugin(MavenPublication) {
+ from components.shadow
+ artifactId = 'dokka-gradle-plugin'
+
+ artifact sourceJar {
+ classifier "sources"
+ }
+ }
+ }
+}
+
+bintrayPublication(project, ['dokkaGradlePlugin'])
+
diff --git a/runners/gradle-plugin/src/main/kotlin/logger.kt b/runners/gradle-plugin/src/main/kotlin/logger.kt
new file mode 100644
index 00000000..715c1f04
--- /dev/null
+++ b/runners/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/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt
new file mode 100644
index 00000000..49c3b8ba
--- /dev/null
+++ b/runners/gradle-plugin/src/main/kotlin/main.kt
@@ -0,0 +1,190 @@
+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.file.FileCollection
+import org.gradle.api.plugins.JavaBasePlugin
+import org.gradle.api.plugins.JavaPluginConvention
+import org.gradle.api.tasks.*
+import org.jetbrains.dokka.DocumentationOptions
+import org.jetbrains.dokka.DokkaGenerator
+import org.jetbrains.dokka.SourceLinkDefinition
+import java.io.File
+import java.io.Serializable
+import java.util.*
+
+open class DokkaPlugin : Plugin<Project> {
+ override fun apply(project: Project) {
+ project.tasks.create("dokka", DokkaTask::class.java).apply {
+ moduleName = project.name
+ outputDirectory = File(project.buildDir, "dokka").absolutePath
+ }
+ }
+}
+
+open class DokkaTask : DefaultTask() {
+ init {
+ group = JavaBasePlugin.DOCUMENTATION_GROUP
+ description = "Generates dokka documentation for Kotlin"
+ }
+
+ @Input
+ var moduleName: String = ""
+ @Input
+ var outputFormat: String = "html"
+ var outputDirectory: String = ""
+ @Input
+ var processConfigurations: List<Any?> = arrayListOf("compile")
+ @Input
+ var includes: List<Any?> = arrayListOf()
+ @Input
+ var linkMappings: ArrayList<LinkMapping> = arrayListOf()
+ @Input
+ var samples: List<Any?> = arrayListOf()
+ @Input
+ var jdkVersion: Int = 6
+ @Input
+ var sourceDirs: Iterable<File> = emptyList()
+
+ protected open val sdkProvider: SdkProvider? = null
+
+ 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)
+ }
+
+ @TaskAction
+ fun generate() {
+ val project = project
+ val sdkProvider = sdkProvider
+ val sourceDirectories = getSourceDirectories()
+ val allConfigurations = project.configurations
+
+ val classpath =
+ if (sdkProvider != null && sdkProvider.isValid) sdkProvider.classpath else emptyList<File>() +
+ processConfigurations
+ .map { allConfigurations?.getByName(it.toString()) ?: 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 },
+ samples.filterNotNull().map { project.file(it).absolutePath },
+ includes.filterNotNull().map { project.file(it).absolutePath },
+ moduleName,
+ DocumentationOptions(outputDirectory, outputFormat,
+ sourceLinks = linkMappings.map { SourceLinkDefinition(project.file(it.dir).absolutePath, it.url, it.suffix) },
+ jdkVersion = jdkVersion)
+ ).generate()
+ }
+
+ fun getSourceDirectories(): Collection<File> {
+ val provider = sdkProvider
+ val sourceDirs = if (sourceDirs.any()) {
+ logger.info("Dokka: Taking source directories provided by the user")
+ sourceDirs.toSet()
+ } else if (provider != null && provider.isValid) {
+ logger.info("Dokka: Taking source directories from ${provider.name} sdk provider")
+ provider.sourceDirs
+ } else {
+ logger.info("Dokka: Taking source directories from default java plugin")
+ val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java)
+ val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME)
+ sourceSets?.allSource?.srcDirs
+ }
+
+ return sourceDirs?.filter { it.exists() } ?: emptyList()
+ }
+
+ @InputFiles
+ @SkipWhenEmpty
+ fun getInputFiles(): FileCollection =
+ project.files(getSourceDirectories().map { project.fileTree(it) }) +
+ project.files(includes) +
+ project.files(samples.map { project.fileTree(it) })
+
+ @OutputDirectory
+ fun getOutputDirectoryAsFile(): File = project.file(outputDirectory)
+}
+
+open class LinkMapping : Serializable {
+ var dir: String = ""
+ var url: String = ""
+ var suffix: String? = null
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other?.javaClass != javaClass) return false
+
+ other as LinkMapping
+
+ if (dir != other.dir) return false
+ if (url != other.url) return false
+ if (suffix != other.suffix) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = dir.hashCode()
+ result = 31 * result + url.hashCode()
+ result = 31 * result + (suffix?.hashCode() ?: 0)
+ return result
+ }
+
+ companion object {
+ const val serialVersionUID: Long = -8133501684312445981L
+ }
+}
+
+/**
+ * A provider for SDKs that can be used if a project uses classes that live outside the JDK or uses a
+ * different method to determine the source directories.
+ *
+ * For example an Android library project configures its sources through the Android extension instead
+ * of the basic java convention. Also it has its custom classes located in the SDK installation directory.
+ */
+interface SdkProvider {
+ /**
+ * The name of this provider. Only used for logging purposes.
+ */
+ val name: String
+
+ /**
+ * Checks whether this provider has everything it needs to provide the source directories.
+ */
+ val isValid: Boolean
+
+ /**
+ * Provides additional classpath files where Dokka should search for external classes.
+ * The file list is injected **after** JDK Jars and **before** project dependencies.
+ *
+ * This is only called if [isValid] returns `true`.
+ */
+ val classpath: List<File>
+
+ /**
+ * Provides a list of directories where Dokka should search for source files.
+ *
+ * This is only called if [isValid] returns `true`.
+ */
+ val sourceDirs: Set<File>?
+}
diff --git a/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties b/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties
new file mode 100644
index 00000000..b42cfe9f
--- /dev/null
+++ b/runners/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
diff --git a/runners/maven-plugin/build.gradle b/runners/maven-plugin/build.gradle
new file mode 100644
index 00000000..c0b9df2e
--- /dev/null
+++ b/runners/maven-plugin/build.gradle
@@ -0,0 +1,80 @@
+
+apply plugin: 'kotlin'
+apply plugin: 'com.github.johnrengelman.shadow'
+
+
+configurations {
+ provided
+}
+
+tasks.withType(AbstractCompile) {
+ classpath += configurations.provided
+ classpath += configurations.shadow
+}
+
+dependencies {
+ shadow project(":runners:fatjar")
+ shadow "org.apache.maven:maven-core:$maven_version"
+ shadow "org.apache.maven:maven-model:$maven_version"
+ shadow "org.apache.maven:maven-plugin-api:$maven_version"
+ shadow "org.apache.maven:maven-archiver:$maven_archiver_version"
+ shadow "org.codehaus.plexus:plexus-utils:$plexus_utils_version"
+ shadow "org.codehaus.plexus:plexus-archiver:$plexus_archiver_version"
+ shadow "org.apache.maven.plugin-tools:maven-plugin-annotations:$maven_plugin_tools_version"
+}
+
+task generatePom << {
+ final pomTemplate = new File(projectDir, "pom.tpl.xml")
+ final pom = new File(buildDir, "pom.xml")
+ pom.text = pomTemplate.text.replace("<version>dokka_version</version>", "<version>$dokka_version</version>")
+ .replace("<maven.version></maven.version>", "<maven.version>$maven_version</maven.version>")
+ .replace("<version>maven-plugin-plugin</version>", "<version>$maven_plugin_tools_version</version>")
+}
+
+task pluginDescriptor(type: Exec) {
+ workingDir buildDir
+ commandLine 'mvn', '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:descriptor'
+}
+
+task helpMojo(type: Exec) {
+ workingDir buildDir
+ commandLine 'mvn', '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:helpmojo'
+}
+
+
+helpMojo.dependsOn generatePom
+sourceSets.main.java.srcDir("$buildDir/generated-sources/plugin")
+compileJava.dependsOn helpMojo
+
+pluginDescriptor.dependsOn generatePom
+
+shadowJar {
+ baseName = 'dokka-maven-plugin'
+ classifier = ''
+
+ relocate('kotlin.', 'dokkakotlin.')
+}
+
+shadowJar.dependsOn pluginDescriptor
+
+
+task sourceJar(type: Jar) {
+ from sourceSets.main.allSource
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+ publications {
+ dokkaMavenPlugin(MavenPublication) {
+ from components.shadow
+ artifactId = 'dokka-maven-plugin'
+
+ artifact sourceJar {
+ classifier "sources"
+ }
+ }
+ }
+}
+
+bintrayPublication(project, ['dokkaMavenPlugin']) \ No newline at end of file
diff --git a/runners/maven-plugin/pom.tpl.xml b/runners/maven-plugin/pom.tpl.xml
new file mode 100644
index 00000000..3b5afd74
--- /dev/null
+++ b/runners/maven-plugin/pom.tpl.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jetbrains.dokka</groupId>
+ <artifactId>dokka-maven-plugin</artifactId>
+ <version>dokka_version</version>
+ <packaging>maven-plugin</packaging>
+ <properties>
+ <maven.version></maven.version>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>maven-plugin-plugin</version>
+ <configuration>
+ <helpPackageName>org.jetbrains.dokka.maven</helpPackageName>
+ </configuration>
+ </plugin>
+ </plugins>
+ <directory>./</directory>
+ <outputDirectory>classes/main</outputDirectory>
+ </build>
+</project>
diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
new file mode 100644
index 00000000..899d2dde
--- /dev/null
+++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
@@ -0,0 +1,179 @@
+package org.jetbrains.dokka.maven
+
+import org.apache.maven.archiver.MavenArchiveConfiguration
+import org.apache.maven.archiver.MavenArchiver
+import org.apache.maven.execution.MavenSession
+import org.apache.maven.plugin.AbstractMojo
+import org.apache.maven.plugins.annotations.*
+import org.apache.maven.project.MavenProject
+import org.apache.maven.project.MavenProjectHelper
+import org.jetbrains.dokka.DokkaGenerator
+import org.jetbrains.dokka.SourceLinkDefinition
+import org.jetbrains.dokka.DocumentationOptions
+import org.codehaus.plexus.archiver.Archiver
+import org.codehaus.plexus.archiver.jar.JarArchiver
+import java.io.File
+
+class SourceLinkMapItem {
+ @Parameter(name = "dir", required = true)
+ var dir: String = ""
+
+ @Parameter(name = "url", required = true)
+ var url: String = ""
+
+ @Parameter(name = "urlSuffix")
+ var urlSuffix: String? = null
+}
+
+abstract class AbstractDokkaMojo : AbstractMojo() {
+ @Parameter(required = true, defaultValue = "\${project.compileSourceRoots}")
+ var sourceDirectories: List<String> = emptyList()
+
+ @Parameter
+ var samplesDirs: List<String> = emptyList()
+
+ @Parameter
+ @Deprecated("Use <includes> instead")
+ var includeDirs: List<String> = emptyList()
+
+ @Parameter
+ var includes: List<String> = emptyList()
+
+ @Parameter(required = true, defaultValue = "\${project.compileClasspathElements}")
+ var classpath: List<String> = emptyList()
+
+ @Parameter
+ var sourceLinks: Array<SourceLinkMapItem> = emptyArray()
+
+ @Parameter(required = true, defaultValue = "\${project.artifactId}")
+ var moduleName: String = ""
+
+ @Parameter(required = false, defaultValue = "false")
+ var skip: Boolean = false
+
+ @Parameter(required = false, defaultValue = "6")
+ var jdkVersion: Int = 6
+
+ protected abstract fun getOutDir(): String
+ protected abstract fun getOutFormat(): String
+
+ override fun execute() {
+ if (skip) {
+ log.info("Dokka skip parameter is true so no dokka output will be produced")
+ return
+ }
+
+ val gen = DokkaGenerator(
+ MavenDokkaLogger(log),
+ classpath,
+ sourceDirectories,
+ samplesDirs,
+ includeDirs + includes,
+ moduleName,
+ DocumentationOptions(getOutDir(), getOutFormat(),
+ sourceLinks = sourceLinks.map { SourceLinkDefinition(it.dir, it.url, it.urlSuffix) },
+ jdkVersion = jdkVersion
+ )
+ )
+
+ gen.generate()
+ }
+}
+
+@Mojo(name = "dokka", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
+class DokkaMojo : AbstractDokkaMojo() {
+ @Parameter(required = true, defaultValue = "html")
+ var outputFormat: String = "html"
+
+ @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokka")
+ var outputDir: String = ""
+
+ override fun getOutFormat() = outputFormat
+ override fun getOutDir() = outputDir
+}
+
+@Mojo(name = "javadoc", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
+class DokkaJavadocMojo : AbstractDokkaMojo() {
+ @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadoc")
+ var outputDir: String = ""
+
+ override fun getOutFormat() = "javadoc"
+ override fun getOutDir() = outputDir
+}
+
+@Mojo(name = "javadocJar", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
+class DokkaJavadocJarMojo : AbstractDokkaMojo() {
+ @Parameter(required = true, defaultValue = "\${project.basedir}/target/dokkaJavadocJar")
+ var outputDir: String = ""
+
+ /**
+ * Specifies the directory where the generated jar file will be put.
+ */
+ @Parameter(property = "project.build.directory")
+ private var jarOutputDirectory: String? = null
+
+ /**
+ * Specifies the filename that will be used for the generated jar file. Please note that `-javadoc`
+ * or `-test-javadoc` will be appended to the file name.
+ */
+ @Parameter(property = "project.build.finalName")
+ private var finalName: String? = null
+
+ /**
+ * Specifies whether to attach the generated artifact to the project helper.
+ */
+ @Parameter(property = "attach", defaultValue = "true")
+ private val attach: Boolean = false
+
+ /**
+ * The archive configuration to use.
+ * See [Maven Archiver Reference](http://maven.apache.org/shared/maven-archiver/index.html)
+ */
+ @Parameter
+ private val archive = MavenArchiveConfiguration()
+
+ @Parameter(property = "maven.javadoc.classifier", defaultValue = "javadoc", required = true)
+ private var classifier: String? = null
+
+ @Parameter(defaultValue = "\${session}", readonly = true, required = true)
+ protected var session: MavenSession? = null
+
+ @Parameter(defaultValue = "\${project}", readonly = true, required = true)
+ protected var project: MavenProject? = null
+
+ @Component
+ private var projectHelper: MavenProjectHelper? = null
+
+ @Component(role = Archiver::class, hint = "jar")
+ private var jarArchiver: JarArchiver? = null
+
+ override fun getOutFormat() = "javadoc"
+ override fun getOutDir() = outputDir
+
+ override fun execute() {
+ super.execute()
+ if(!File(outputDir).exists()) {
+ log.warn("No javadoc generated so no javadoc jar will be generated")
+ return
+ }
+ val outputFile = generateArchive("$finalName-$classifier.jar")
+ if (attach) {
+ projectHelper?.attachArtifact(project, "javadoc", classifier, outputFile)
+ }
+ }
+
+ private fun generateArchive(jarFileName: String): File {
+ val javadocJar = File(jarOutputDirectory, jarFileName)
+
+ val archiver = MavenArchiver()
+ archiver.setArchiver(jarArchiver)
+ archiver.setOutputFile(javadocJar)
+ archiver.archiver.addDirectory(File(outputDir), arrayOf("**/**"), arrayOf())
+
+ archive.setAddMavenDescriptor(false)
+ archiver.createArchive(session, project, archive)
+
+ return javadocJar
+ }
+}
+
diff --git a/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt b/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt
new file mode 100644
index 00000000..a535c807
--- /dev/null
+++ b/runners/maven-plugin/src/main/kotlin/MavenDokkaLogger.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka.maven
+
+import org.apache.maven.plugin.logging.Log
+import org.jetbrains.dokka.DokkaLogger
+
+class MavenDokkaLogger(val log: Log) : DokkaLogger {
+ override fun error(message: String) {
+ log.error(message)
+ }
+
+ override fun info(message: String) {
+ log.info(message)
+ }
+
+ override fun warn(message: String) {
+ log.warn(message)
+ }
+} \ No newline at end of file