From f338bc0b6dfa603e369b0c727b6cb256dfc711be Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 15 Jan 2015 18:34:23 +0100 Subject: support source links in the Ant task --- ant/src/dokka.kt | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'ant/src') diff --git a/ant/src/dokka.kt b/ant/src/dokka.kt index 9510f78b..464dadfe 100644 --- a/ant/src/dokka.kt +++ b/ant/src/dokka.kt @@ -7,6 +7,8 @@ import org.apache.tools.ant.BuildException import org.apache.tools.ant.Project import org.jetbrains.dokka.DokkaLogger import org.jetbrains.dokka.DokkaGenerator +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) @@ -14,6 +16,8 @@ class AntLogger(val task: Task): DokkaLogger { 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() { public var moduleName: String? = null public var outputDir: String? = null @@ -24,6 +28,8 @@ class DokkaAntTask(): Task() { public val samplesPath: Path = Path(getProject()) public val includesPath: Path = Path(getProject()) + public val antSourceLinks: MutableList = arrayListOf() + public fun setClasspath(classpath: Path) { compileClasspath.append(classpath) } @@ -54,6 +60,12 @@ class DokkaAntTask(): Task() { includesPath.append(include) } + public 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") @@ -64,6 +76,17 @@ class DokkaAntTask(): Task() { if (outputDir == null) { throw BuildException("Output directory needs to be specified") } + val sourceLinks = antSourceLinks.map { + val path = it.path + if (path == null) { + throw BuildException("Path attribute of a element is required") + } + val url = it.url + if (url == null) { + throw BuildException("Path attribute of a element is required") + } + SourceLinkDefinition(File(path).getCanonicalFile().getAbsolutePath(), url, it.lineSuffix) + } val url = javaClass().getResource("/org/jetbrains/dokka/ant/DokkaAntTask.class") val jarRoot = url.getPath().substringBefore("!/").trimLeading("file:") @@ -78,7 +101,7 @@ class DokkaAntTask(): Task() { moduleName!!, outputDir!!, outputFormat, - listOf() + sourceLinks ) generator.generate() } -- cgit