aboutsummaryrefslogtreecommitdiff
path: root/runners/cli/src
diff options
context:
space:
mode:
authorSimon Ogorodnik <sem-oro@yandex.ru>2016-12-08 15:13:06 +0300
committerGitHub <noreply@github.com>2016-12-08 15:13:06 +0300
commit25b9aa91139063e977a06aec0b3f1b30f05a172a (patch)
treefd6f469167acf6ac8efef1b187c9d1067a3dad74 /runners/cli/src
parent3d3f3596ed83448a6e80c14e5ca7117900587b7f (diff)
downloaddokka-25b9aa91139063e977a06aec0b3f1b30f05a172a.tar.gz
dokka-25b9aa91139063e977a06aec0b3f1b30f05a172a.tar.bz2
dokka-25b9aa91139063e977a06aec0b3f1b30f05a172a.zip
tools.jar (#125), Fixes #85, #58
Added hack to adjust publishing pom for maven Added hack to load tools.jar for cli
Diffstat (limited to 'runners/cli/src')
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt116
1 files changed, 83 insertions, 33 deletions
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index b31894eb..afc67e45 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -4,6 +4,7 @@ import com.sampullara.cli.Args
import com.sampullara.cli.Argument
import org.jetbrains.kotlin.cli.common.arguments.ValueDescription
import java.io.File
+import java.net.URLClassLoader
class DokkaArguments {
@set:Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
@@ -45,41 +46,90 @@ class DokkaArguments {
var jdkVersion: Int = 6
}
-fun main(args: Array<String>) {
- val arguments = DokkaArguments()
- val freeArgs: List<String> = Args.parse(arguments, args, false) ?: 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.")
+
+object MainKt {
+
+ @JvmStatic
+ fun entry(args: Array<String>) {
+ val arguments = DokkaArguments()
+ val freeArgs: List<String> = Args.parse(arguments, args, false) ?: 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()
+ }
+
+ fun findToolsJar(): File {
+ val javaHome = System.getProperty("java.home")
+ val default = File(javaHome, "../lib/tools.jar")
+ val mac = File(javaHome, "../Classes/classes.jar")
+ when {
+ default.exists() -> return default
+ mac.exists() -> return mac
+ else -> {
+ throw Exception("tools.jar not found, please check it, also you can provide it manually, using -cp")
+ }
+ }
+ }
+
+ fun createClassLoaderWithTools(): ClassLoader {
+ val toolsJar = findToolsJar().canonicalFile.toURI().toURL()
+ val dokkaJar = javaClass.protectionDomain.codeSource.location
+ return URLClassLoader(arrayOf(toolsJar, dokkaJar), ClassLoader.getSystemClassLoader().parent)
+ }
+
+ fun startWithToolsJar(args: Array<String>) {
+ try {
+ javaClass.classLoader.loadClass("com.sun.tools.doclets.formats.html.HtmlDoclet")
+ entry(args)
+ } catch (e: ClassNotFoundException) {
+ val classLoader = createClassLoaderWithTools()
+ classLoader.loadClass("org.jetbrains.dokka.MainKt")
+ .methods.find { it.name == "entry" }!!
+ .invoke(null, args)
}
- 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()
+ @JvmStatic
+ fun main(args: Array<String>) {
+ val arguments = DokkaArguments()
+ Args.parse(arguments, args, false)
+
+ if (arguments.outputFormat == "javadoc")
+ startWithToolsJar(args)
+ else
+ entry(args)
+ }
}
+
+