From 0e8733ead6d5c4c6db7e4fe8a1f34b7598823290 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 11 May 2017 16:31:04 +0300 Subject: Add external documentation links argument to gradle, maven, ant --- runners/ant/src/main/kotlin/ant/dokka.kt | 8 +++++++- runners/cli/src/main/kotlin/cli/main.kt | 7 ++++--- runners/gradle-plugin/src/main/kotlin/main.kt | 12 +++++++++++- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) (limited to 'runners') diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index f645aea4..83d7e8ac 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -6,6 +6,7 @@ import org.apache.tools.ant.Task import org.apache.tools.ant.types.Path import org.apache.tools.ant.types.Reference import org.jetbrains.dokka.* +import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import java.io.File class AntLogger(val task: Task): DokkaLogger { @@ -47,6 +48,7 @@ class DokkaAntTask: Task() { val antSourceLinks: MutableList = arrayListOf() val antSourceRoots: MutableList = arrayListOf() val antPackageOptions: MutableList = arrayListOf() + val antExternalDocumentationLinks = mutableListOf() fun setClasspath(classpath: Path) { compileClasspath.append(classpath) @@ -86,6 +88,8 @@ class DokkaAntTask: Task() { fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { antPackageOptions.add(this) } + fun createExternalDocumentationLink() = ExternalDocumentationLink.Builder().apply { antExternalDocumentationLinks.add(this) } + override fun execute() { if (sourcePath.list().isEmpty() && antSourceRoots.isEmpty()) { throw BuildException("At least one source path needs to be specified") @@ -114,7 +118,9 @@ class DokkaAntTask: Task() { sourceLinks = sourceLinks, jdkVersion = jdkVersion, impliedPlatforms = impliedPlatforms.split(','), - perPackageOptions = antPackageOptions) + perPackageOptions = antPackageOptions, + externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() } + ) ) generator.generate() } diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index f8a01c38..ff2107e2 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka +import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import org.jetbrains.kotlin.cli.common.arguments.ValueDescription import org.jetbrains.kotlin.cli.common.parser.com.sampullara.cli.Args import org.jetbrains.kotlin.cli.common.parser.com.sampullara.cli.Argument @@ -61,13 +62,13 @@ class DokkaArguments { object MainKt { - fun parseLinks(links: String): List { + fun parseLinks(links: String): List { val (parsedLinks, parsedOfflineLinks) = links.split("^^") .map { it.split("^").map { it.trim() }.filter { it.isNotBlank() } } .filter { it.isNotEmpty() } .partition { it.size == 1 } - return parsedLinks.map { (root) -> ExternalDocumentationLinkImpl(root) } + + return parsedLinks.map { (root) -> ExternalDocumentationLink.Builder(root).build() } + parsedOfflineLinks.map { (root, packageList) -> val rootUrl = URL(root) val packageListUrl = @@ -76,7 +77,7 @@ object MainKt { } catch (ex: MalformedURLException) { File(packageList).toURI().toURL() } - ExternalDocumentationLinkImpl(rootUrl, packageListUrl) + ExternalDocumentationLink.Builder(rootUrl, packageListUrl).build() } } diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 60311fff..bfa8feea 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -85,6 +85,8 @@ open class DokkaTask : DefaultTask() { @Input var perPackageOptions: MutableList = arrayListOf() @Input var impliedPlatforms: MutableList = arrayListOf() + @Input var externalDocumentationLinks = mutableListOf() + protected open val sdkProvider: SdkProvider? = null @@ -117,6 +119,13 @@ open class DokkaTask : DefaultTask() { perPackageOptions.add(packageOptions) } + fun externalDocumentationLink(closure: Closure) { + val builder = DokkaConfiguration.ExternalDocumentationLink.Builder() + closure.delegate = builder + closure.call() + externalDocumentationLinks.add(builder.build()) + } + fun tryResolveFatJar(project: Project): File { return try { val dependency = project.buildscript.dependencies.create(dokkaFatJar) @@ -185,7 +194,8 @@ open class DokkaTask : DefaultTask() { true, linkMappings, impliedPlatforms, - perPackageOptions) + perPackageOptions, + externalDocumentationLinks) bootstrapProxy.configure( diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index dbae2362..cef0f2d8 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -11,6 +11,7 @@ import org.codehaus.plexus.archiver.Archiver import org.codehaus.plexus.archiver.jar.JarArchiver import org.jetbrains.dokka.* import java.io.File +import java.net.URL class SourceLinkMapItem { @Parameter(name = "dir", required = true) @@ -23,6 +24,14 @@ class SourceLinkMapItem { var urlSuffix: String? = null } +class ExternalDocumentationLinkBuilder : DokkaConfiguration.ExternalDocumentationLink.Builder() { + + @Parameter(name = "url", required = true) + override var url: URL? = null + @Parameter(name = "packageListUrl", required = true) + override var packageListUrl: URL? = null +} + abstract class AbstractDokkaMojo : AbstractMojo() { class SourceRoot : DokkaConfiguration.SourceRoot { @Parameter(required = true) @@ -87,6 +96,9 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var perPackageOptions: List = emptyList() + @Parameter + var externalDocumentationLinks: List = emptyList() + protected abstract fun getOutDir(): String protected abstract fun getOutFormat(): String @@ -110,7 +122,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { skipEmptyPackages = skipEmptyPackages, reportUndocumented = reportNotDocumented, impliedPlatforms = impliedPlatforms, - perPackageOptions = perPackageOptions + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks.map { it.build() } ) ) -- cgit