aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/main/kotlin/main.kt
diff options
context:
space:
mode:
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin/main.kt')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/main.kt79
1 files changed, 57 insertions, 22 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt
index 25ca370b..f726c6c7 100644
--- a/runners/gradle-plugin/src/main/kotlin/main.kt
+++ b/runners/gradle-plugin/src/main/kotlin/main.kt
@@ -1,10 +1,12 @@
package org.jetbrains.dokka.gradle
import groovy.lang.Closure
+import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
+import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginConvention
@@ -30,6 +32,7 @@ open class DokkaPlugin : Plugin<Project> {
override fun apply(project: Project) {
DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
project.tasks.create("dokka", DokkaTask::class.java).apply {
+ dokkaRuntime = project.configurations.create("dokkaRuntime")
moduleName = project.name
outputDirectory = File(project.buildDir, "dokka").absolutePath
}
@@ -80,7 +83,7 @@ open class DokkaTask : DefaultTask() {
@Input
var outputFormat: String = "html"
var outputDirectory: String = ""
-
+ var dokkaRuntime: Configuration? = null
@Deprecated("Going to be removed in 0.9.16, use classpath + sourceDirs instead if kotlinTasks is not suitable for you")
@Input var processConfigurations: List<Any?> = emptyList()
@@ -147,14 +150,17 @@ open class DokkaTask : DefaultTask() {
private var kotlinTasksConfigurator: () -> List<Any?>? = { defaultKotlinTasks() }
private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks() }
+ fun kotlinTasks(taskSupplier: Callable<List<Any>>) {
+ kotlinTasksConfigurator = { taskSupplier.call() }
+ }
+
fun kotlinTasks(closure: Closure<Any?>) {
kotlinTasksConfigurator = { closure.call() as? List<Any?> }
}
- fun linkMapping(closure: Closure<Unit>) {
+ fun linkMapping(action: Action<LinkMapping>) {
val mapping = LinkMapping()
- closure.delegate = mapping
- closure.call()
+ action.execute(mapping)
if (mapping.path.isEmpty()) {
throw IllegalArgumentException("Link mapping should have dir")
@@ -166,33 +172,55 @@ open class DokkaTask : DefaultTask() {
linkMappings.add(mapping)
}
- fun sourceRoot(closure: Closure<Unit>) {
+ fun linkMapping(closure: Closure<Unit>) {
+ linkMapping(Action { mapping ->
+ closure.delegate = mapping
+ closure.call()
+ })
+ }
+
+ fun sourceRoot(action: Action<SourceRoot>) {
val sourceRoot = SourceRoot()
- closure.delegate = sourceRoot
- closure.call()
+ action.execute(sourceRoot)
sourceRoots.add(sourceRoot)
}
- fun packageOptions(closure: Closure<Unit>) {
+ fun sourceRoot(closure: Closure<Unit>) {
+ sourceRoot(Action { sourceRoot ->
+ closure.delegate = sourceRoot
+ closure.call()
+ })
+ }
+
+ fun packageOptions(action: Action<PackageOptions>) {
val packageOptions = PackageOptions()
- closure.delegate = packageOptions
- closure.call()
+ action.execute(packageOptions)
perPackageOptions.add(packageOptions)
}
- fun externalDocumentationLink(closure: Closure<Unit>) {
+ fun packageOptions(closure: Closure<Unit>) {
+ packageOptions(Action { packageOptions ->
+ closure.delegate = packageOptions
+ closure.call()
+ })
+ }
+
+ fun externalDocumentationLink(action: Action<DokkaConfiguration.ExternalDocumentationLink.Builder>) {
val builder = DokkaConfiguration.ExternalDocumentationLink.Builder()
- closure.delegate = builder
- closure.call()
+ action.execute(builder)
externalDocumentationLinks.add(builder.build())
}
- fun tryResolveFatJar(project: Project): File {
+ fun externalDocumentationLink(closure: Closure<Unit>) {
+ externalDocumentationLink(Action { builder ->
+ closure.delegate = builder
+ closure.call()
+ })
+ }
+
+ fun tryResolveFatJar(project: Project): Set<File> {
return try {
- val dependency = project.buildscript.dependencies.create(dokkaFatJar)
- val configuration = project.buildscript.configurations.detachedConfiguration(dependency)
- configuration.description = "Dokka main jar"
- configuration.resolve().first()
+ dokkaRuntime!!.resolve()
} catch (e: Exception) {
project.parent?.let { tryResolveFatJar(it) } ?: throw e
}
@@ -200,11 +228,11 @@ open class DokkaTask : DefaultTask() {
fun loadFatJar() {
if (fatJarClassLoader == null) {
- val fatjar = if (dokkaFatJar is File)
- dokkaFatJar as File
+ val jars = if (dokkaFatJar is File)
+ setOf(dokkaFatJar as File)
else
tryResolveFatJar(project)
- fatJarClassLoader = URLClassLoader(arrayOf(fatjar.toURI().toURL()), ClassLoader.getSystemClassLoader().parent)
+ fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent)
}
}
@@ -269,6 +297,11 @@ open class DokkaTask : DefaultTask() {
@TaskAction
fun generate() {
+ if (dokkaRuntime == null){
+ dokkaRuntime = project.configurations.getByName("dokkaRuntime")
+ }
+
+ dokkaRuntime?.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create(dokkaFatJar)) }
val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false"
System.setProperty(COLORS_ENABLED_PROPERTY, "false")
try {
@@ -414,7 +447,9 @@ open class LinkMapping : Serializable, DokkaConfiguration.SourceLinkDefinition {
var dir: String
get() = path
set(value) {
- path = value
+ if (value.contains("\\"))
+ throw java.lang.IllegalArgumentException("Incorrect dir property, only Unix based path allowed.")
+ else path = value
}
override var path: String = ""