diff options
author | Simon Ogorodnik <sem-oro@yandex.ru> | 2016-12-08 15:13:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 15:13:06 +0300 |
commit | 25b9aa91139063e977a06aec0b3f1b30f05a172a (patch) | |
tree | fd6f469167acf6ac8efef1b187c9d1067a3dad74 | |
parent | 3d3f3596ed83448a6e80c14e5ca7117900587b7f (diff) | |
download | dokka-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
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 116 | ||||
-rw-r--r-- | runners/maven-plugin/build.gradle | 58 |
2 files changed, 139 insertions, 35 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) + } } + + diff --git a/runners/maven-plugin/build.gradle b/runners/maven-plugin/build.gradle index d73126f4..bf6b9476 100644 --- a/runners/maven-plugin/build.gradle +++ b/runners/maven-plugin/build.gradle @@ -1,5 +1,7 @@ +import groovy.xml.QName import org.jetbrains.CrossPlatformExec + apply plugin: 'kotlin' apply plugin: 'com.github.johnrengelman.shadow' @@ -52,8 +54,6 @@ pluginDescriptor.dependsOn generatePom shadowJar { baseName = 'dokka-maven-plugin' classifier = '' - - relocate('kotlin.', 'dokkakotlin.') } shadowJar.dependsOn pluginDescriptor @@ -74,8 +74,62 @@ publishing { artifact sourceJar { classifier "sources" } + + pom.withXml { + Node root = asNode() + + def dependency = new XmlParser().parseText(''' + <dependency> + <groupId>com.sun</groupId> + <artifactId>tools</artifactId> + <version>1.8.0</version> + <scope>system</scope> + <systemPath>${toolsjar}</systemPath> + </dependency> + ''') + + root.children().find { + return ((QName) it.name()).qualifiedName == "dependencies" + }.append(dependency) + + def profiles = new XmlParser().parseText(''' + <profiles> + <profile> + <id>default-profile</id> + <activation> + <activeByDefault>true</activeByDefault> + <file> + <exists>${java.home}/../lib/tools.jar</exists> + </file> + </activation> + <properties> + <toolsjar>${java.home}/../lib/tools.jar</toolsjar> + </properties> + </profile> + <profile> + <id>mac-profile</id> + <activation> + <activeByDefault>false</activeByDefault> + <file> + <exists>${java.home}/../Classes/classes.jar</exists> + </file> + </activation> + <properties> + <toolsjar>${java.home}/../Classes/classes.jar</toolsjar> + </properties> + </profile> + </profiles> + ''') + root.append(profiles) + } } } } +tasks.withType(GenerateMavenPom) { Task generatePom -> + generatePom.doLast { + + } +} + bintrayPublication(project, ['dokkaMavenPlugin'])
\ No newline at end of file |