diff options
Diffstat (limited to 'runners')
-rw-r--r-- | runners/android-gradle-plugin/build.gradle | 3 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 7 | ||||
-rw-r--r-- | runners/fatjar/build.gradle | 23 | ||||
-rw-r--r-- | runners/gradle-plugin/build.gradle | 19 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/main.kt | 76 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties | 3 |
6 files changed, 84 insertions, 47 deletions
diff --git a/runners/android-gradle-plugin/build.gradle b/runners/android-gradle-plugin/build.gradle index 6e8da695..4ea12edb 100644 --- a/runners/android-gradle-plugin/build.gradle +++ b/runners/android-gradle-plugin/build.gradle @@ -19,7 +19,7 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' - shadow project(':runners:fatjar') + shadow project(':runners:gradle-plugin') provided gradleApi() @@ -35,7 +35,6 @@ task sourceJar(type: Jar) { shadowJar { baseName = 'dokka-android-gradle-plugin' classifier = '' - relocate('kotlin.', 'dokkakotlin.') } apply plugin: 'maven-publish' diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 68192dc7..b31894eb 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -45,13 +45,6 @@ class DokkaArguments { var jdkVersion: Int = 6 } -private fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinition(File(path).absolutePath, - urlAndLine.substringBefore("#"), - urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) -} - fun main(args: Array<String>) { val arguments = DokkaArguments() val freeArgs: List<String> = Args.parse(arguments, args, false) ?: listOf() diff --git a/runners/fatjar/build.gradle b/runners/fatjar/build.gradle index d888a1ac..a9f0c721 100644 --- a/runners/fatjar/build.gradle +++ b/runners/fatjar/build.gradle @@ -22,29 +22,6 @@ shadowJar { exclude provided } - relocate('com.', 'dokkacom.') { - exclude 'com.sun.**' - } - - relocate('org.', 'dokkaorg.') { - exclude 'org.jetbrains.dokka.**' - exclude 'org.xml.**' - exclude 'org.w3c.**' - exclude 'org.jaxen.**' - exclude 'org.apache.xerces.**' - exclude 'org.apache.xml.**' - exclude 'org.fusesource.jansi.**' - exclude 'org.apache.tools.ant.**' - } - - - relocate('kotlin.', 'dokkakotlin.') { - exclude '**.*kotlin_builtins' //For kotlin_builtins, still not sure that we should relocate kotlin stdlib - exclude 'kotlin.reflect' /* WAT? Ok, ok. Relocate works as Ctrl + Shift + R for ALL class files, so, - if you have string "kotlin.reflect", it will be rewritten to not relevant "dokkakotlin.reflect" and you will got - builtins crash in runtime, cause could not find dokkakotlin/reflect/reflect.kotlin_builtins */ - } - transform(ServiceFileTransformer) transform(PluginXmlTransformer) diff --git a/runners/gradle-plugin/build.gradle b/runners/gradle-plugin/build.gradle index 3c330d18..8e6f11df 100644 --- a/runners/gradle-plugin/build.gradle +++ b/runners/gradle-plugin/build.gradle @@ -14,12 +14,13 @@ tasks.withType(AbstractCompile) { } dependencies { - - shadow project(':runners:fatjar') testCompile group: 'junit', name: 'junit', version: '4.12' - provided group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: kotlin_version - provided group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version + compile group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: kotlin_version + compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version + + compile project(":integration") + provided gradleApi() provided localGroovy() } @@ -28,11 +29,19 @@ task sourceJar(type: Jar) { from sourceSets.main.allSource } +processResources { + eachFile { + if (it.name == "org.jetbrains.dokka.properties") { + it.filter { line -> + line.replace("<version>", dokka_version) + } + } + } +} shadowJar { baseName = 'dokka-gradle-plugin' classifier = '' - relocate('kotlin.', 'dokkakotlin.') } apply plugin: 'maven-publish' diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 49c3b8ba..f3e46c4d 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -8,15 +8,24 @@ import org.gradle.api.file.FileCollection import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.* -import org.jetbrains.dokka.DocumentationOptions -import org.jetbrains.dokka.DokkaGenerator -import org.jetbrains.dokka.SourceLinkDefinition +import org.jetbrains.dokka.DokkaBootstrap +import org.jetbrains.dokka.automagicTypedProxy +import org.jetbrains.dokka.gradle.ClassloaderContainer.fatJarClassLoader import java.io.File import java.io.Serializable +import java.net.URLClassLoader import java.util.* +import java.util.function.Predicate open class DokkaPlugin : Plugin<Project> { + + val properties = Properties() + + init { + properties.load(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) + } override fun apply(project: Project) { + version = properties.getProperty("dokka-version") project.tasks.create("dokka", DokkaTask::class.java).apply { moduleName = project.name outputDirectory = File(project.buildDir, "dokka").absolutePath @@ -24,6 +33,13 @@ open class DokkaPlugin : Plugin<Project> { } } +var version: String? = null + +object ClassloaderContainer { + @JvmField + var fatJarClassLoader: ClassLoader? = null +} + open class DokkaTask : DefaultTask() { init { group = JavaBasePlugin.DOCUMENTATION_GROUP @@ -47,6 +63,8 @@ open class DokkaTask : DefaultTask() { var jdkVersion: Int = 6 @Input var sourceDirs: Iterable<File> = emptyList() + @Input + var dokkaFatJar: Any = "org.jetbrains.dokka:dokka-fatjar:$version" protected open val sdkProvider: SdkProvider? = null @@ -65,8 +83,27 @@ open class DokkaTask : DefaultTask() { linkMappings.add(mapping) } + + fun loadFatJar() { + if (fatJarClassLoader == null) { + val fatjar = if (dokkaFatJar is File) + dokkaFatJar as File + else { + val dependency = project.buildscript.dependencies.create(dokkaFatJar) + val configuration = project.buildscript.configurations.detachedConfiguration(dependency) + configuration.description = "Dokka main jar" + configuration.resolve().first() + } + + fatJarClassLoader = URLClassLoader(arrayOf(fatjar.toURI().toURL())) + } + } + + @TaskAction fun generate() { + loadFatJar() + val project = project val sdkProvider = sdkProvider val sourceDirectories = getSourceDirectories() @@ -83,17 +120,38 @@ open class DokkaTask : DefaultTask() { return } - DokkaGenerator( + val bootstrapClass = fatJarClassLoader!!.loadClass("org.jetbrains.dokka.DokkaBootstrapImpl") + + val bootstrapInstance = bootstrapClass.constructors.first().newInstance() + + val bootstrapProxy = automagicTypedProxy(javaClass.classLoader, + DokkaBootstrap::class.java, + fatJarClassLoader!!, + bootstrapInstance, + Predicate { it.name.startsWith("org.jetbrains.dokka") } + ) + + bootstrapProxy.configure( DokkaGradleLogger(logger), + moduleName, classpath.map { it.absolutePath }, sourceDirectories.map { it.absolutePath }, samples.filterNotNull().map { project.file(it).absolutePath }, includes.filterNotNull().map { project.file(it).absolutePath }, - moduleName, - DocumentationOptions(outputDirectory, outputFormat, - sourceLinks = linkMappings.map { SourceLinkDefinition(project.file(it.dir).absolutePath, it.url, it.suffix) }, - jdkVersion = jdkVersion) - ).generate() + outputDirectory, + outputFormat, + false, + false, + false, + false, + 6, + true, + linkMappings.map { + val path = project.file(it.dir).absolutePath + return@map "$path=${it.url}${it.suffix}" + }) + + bootstrapProxy.generate() } fun getSourceDirectories(): Collection<File> { diff --git a/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties b/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties index b42cfe9f..068bd352 100644 --- a/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties +++ b/runners/gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka.properties @@ -1 +1,2 @@ -implementation-class=org.jetbrains.dokka.gradle.DokkaPlugin
\ No newline at end of file +implementation-class=org.jetbrains.dokka.gradle.DokkaPlugin +dokka-version=<version>
\ No newline at end of file |