From 0783f6fbe2104334195964bbc91cb584cbbab4e0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 15 Jan 2015 14:59:50 +0100 Subject: Ant task for Dokka --- ant/ant.iml | 14 ++++++++ ant/src/dokka-antlib.xml | 3 ++ ant/src/dokka.kt | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 ant/ant.iml create mode 100644 ant/src/dokka-antlib.xml create mode 100644 ant/src/dokka.kt (limited to 'ant') diff --git a/ant/ant.iml b/ant/ant.iml new file mode 100644 index 00000000..0761035c --- /dev/null +++ b/ant/ant.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ant/src/dokka-antlib.xml b/ant/src/dokka-antlib.xml new file mode 100644 index 00000000..9c3373d5 --- /dev/null +++ b/ant/src/dokka-antlib.xml @@ -0,0 +1,3 @@ + + + diff --git a/ant/src/dokka.kt b/ant/src/dokka.kt new file mode 100644 index 00000000..9510f78b --- /dev/null +++ b/ant/src/dokka.kt @@ -0,0 +1,85 @@ +package org.jetbrains.dokka.ant + +import org.apache.tools.ant.Task +import org.apache.tools.ant.types.Path +import org.apache.tools.ant.types.Reference +import org.apache.tools.ant.BuildException +import org.apache.tools.ant.Project +import org.jetbrains.dokka.DokkaLogger +import org.jetbrains.dokka.DokkaGenerator + +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 DokkaAntTask(): Task() { + public var moduleName: String? = null + public var outputDir: String? = null + public var outputFormat: String = "html" + + public val compileClasspath: Path = Path(getProject()) + public val sourcePath: Path = Path(getProject()) + public val samplesPath: Path = Path(getProject()) + public val includesPath: Path = Path(getProject()) + + public fun setClasspath(classpath: Path) { + compileClasspath.append(classpath) + } + + public fun setClasspathRef(ref: Reference) { + compileClasspath.createPath().setRefid(ref) + } + + public fun setSrc(src: Path) { + log("setSrc($src)") + sourcePath.append(src) + log("sourcePath=${sourcePath.list().join(",")}") + } + + public fun setSrcRef(ref: Reference) { + sourcePath.createPath().setRefid(ref) + } + + public fun setSamples(samples: Path) { + samplesPath.append(samples) + } + + public fun setSamplesRef(ref: Reference) { + samplesPath.createPath().setRefid(ref) + } + + public fun setInclude(include: Path) { + includesPath.append(include) + } + + 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 url = javaClass().getResource("/org/jetbrains/dokka/ant/DokkaAntTask.class") + val jarRoot = url.getPath().substringBefore("!/").trimLeading("file:") + log(jarRoot) + + val generator = DokkaGenerator( + AntLogger(this), + listOf(jarRoot) + compileClasspath.list().toList(), + sourcePath.list().toList(), + samplesPath.list().toList(), + includesPath.list().toList(), + moduleName!!, + outputDir!!, + outputFormat, + listOf() + ) + generator.generate() + } +} \ No newline at end of file -- cgit 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 ++++++++++++++++++++++++- build.xml | 4 +++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'ant') 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() } diff --git a/build.xml b/build.xml index 81a4dea9..a11200f4 100644 --- a/build.xml +++ b/build.xml @@ -4,6 +4,8 @@ - + + + -- cgit From c12704ba2e1308a2df1068d75335d814b677d2ea Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 15 Jan 2015 18:43:22 +0100 Subject: remove some logging which is no longer needed --- ant/src/dokka.kt | 3 --- 1 file changed, 3 deletions(-) (limited to 'ant') diff --git a/ant/src/dokka.kt b/ant/src/dokka.kt index 464dadfe..051b6fe7 100644 --- a/ant/src/dokka.kt +++ b/ant/src/dokka.kt @@ -39,9 +39,7 @@ class DokkaAntTask(): Task() { } public fun setSrc(src: Path) { - log("setSrc($src)") sourcePath.append(src) - log("sourcePath=${sourcePath.list().join(",")}") } public fun setSrcRef(ref: Reference) { @@ -90,7 +88,6 @@ class DokkaAntTask(): Task() { val url = javaClass().getResource("/org/jetbrains/dokka/ant/DokkaAntTask.class") val jarRoot = url.getPath().substringBefore("!/").trimLeading("file:") - log(jarRoot) val generator = DokkaGenerator( AntLogger(this), -- cgit