diff options
Diffstat (limited to 'runners/gradle-plugin/src/main')
3 files changed, 37 insertions, 37 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index 84bbaf78..6a4fbe4f 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -21,7 +21,8 @@ import java.util.function.BiConsumer open class DokkaTask : DefaultTask() { - fun defaultKotlinTasks() = with(ReflectDsl) { + @Suppress("MemberVisibilityCanBePrivate") + fun defaultKotlinTasks(): List<Task> = with(ReflectDsl) { val abstractKotlinCompileClz = try { project.buildscript.classLoader.loadClass(ABSTRACT_KOTLIN_COMPILE) } catch (cnfe: ClassNotFoundException) { @@ -48,13 +49,6 @@ open class DokkaTask : DefaultTask() { var dokkaRuntime: Configuration? = null - var defaultDokkaRuntime: Configuration? = null - - @Input - var dokkaFatJar: String = "dokka-fatjar-${DokkaVersion.version}" - - private val defaultDokkaFatJar = "dokka-fatjar-${DokkaVersion.version}" - @Input var impliedPlatforms: MutableList<String> = arrayListOf() @@ -77,26 +71,15 @@ open class DokkaTask : DefaultTask() { protected var externalDocumentationLinks: MutableList<DokkaConfiguration.ExternalDocumentationLink> = mutableListOf() - private var kotlinTasksConfigurator: () -> List<Any?>? = { defaultKotlinTasks() } private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks() } - @Deprecated("Use manual configuration of source roots or subProjects{} closure") - fun kotlinTasks(taskSupplier: Callable<List<Any>>) { - kotlinTasksConfigurator = { taskSupplier.call() } - } - - @Deprecated("Use manual configuration of source roots or subProjects{} closure") - fun kotlinTasks(closure: Closure<Any?>) { - kotlinTasksConfigurator = { closure.call() as? List<Any?> } - } - @Input var subProjects: List<String> = emptyList() @Input var disableAutoconfiguration: Boolean = false - fun tryResolveFatJar(configuration: Configuration?): Set<File> { + private fun tryResolveFatJar(configuration: Configuration?): Set<File> { return try { configuration!!.resolve() } catch (e: Exception) { @@ -104,15 +87,17 @@ open class DokkaTask : DefaultTask() { } } - fun loadFatJar() { + private fun loadFatJar() { if (ClassloaderContainer.fatJarClassLoader == null) { - val jars = tryResolveFatJar(dokkaRuntime).toList().union(tryResolveFatJar(defaultDokkaRuntime).toList()).filter { it.name.contains(dokkaFatJar) || it.name.contains(defaultDokkaFatJar) } + val jars = tryResolveFatJar(dokkaRuntime).toList() ClassloaderContainer.fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent) } } private fun extractKotlinCompileTasks(): List<Task> { - val inputList = (kotlinTasksConfigurator.invoke() ?: emptyList()).filterNotNull() + val collectTasks = configuration.collectKotlinTasks ?: { defaultKotlinTasks() } + + val inputList = (collectTasks.invoke() ?: emptyList()).filterNotNull() val (paths, other) = inputList.partition { it is String } val taskContainer = project.tasks @@ -200,9 +185,9 @@ open class DokkaTask : DefaultTask() { private fun collectFromSinglePlatform(): List<GradlePassConfigurationImpl> { if (disableAutoconfiguration) return listOf(configuration) - val autoConfig = ConfigurationExtractor.extractFromSinglePlatform(project) - val baseConfig = if (autoConfig != null) - listOf(mergeUserConfigurationAndPlatformData(configuration, autoConfig)) + val extractedConfig = ConfigurationExtractor.extractFromSinglePlatform(project) + val baseConfig = if (extractedConfig != null && configuration.collectKotlinTasks == null) + listOf(mergeUserConfigurationAndPlatformData(configuration, extractedConfig)) else collectFromSinglePlatformOldPlugin() diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 0364985d..2c071bf8 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -11,6 +11,7 @@ import org.jetbrains.dokka.Platform import java.io.File import java.io.Serializable import java.net.URL +import java.util.concurrent.Callable import kotlin.reflect.KMutableProperty import kotlin.reflect.full.memberProperties @@ -48,6 +49,15 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input @Optional var platform: String? = null @Input override var targets: List<String> = emptyList() @Input @Optional override var sinceKotlin: String? = null + @Transient var collectKotlinTasks: (() -> List<Any?>?)? = null + + fun kotlinTasks(taskSupplier: Callable<List<Any>>) { + collectKotlinTasks = { taskSupplier.call() } + } + + fun kotlinTasks(closure: Closure<Any?>) { + collectKotlinTasks = { closure.call() as? List<Any?> } + } fun sourceRoot(c: Closure<Unit>) { val configured = ConfigureUtil.configure(c, GradleSourceRootImpl()) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index 66020c5c..a47c238f 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration import org.gradle.util.GradleVersion import java.io.File import java.io.InputStream @@ -11,31 +12,35 @@ internal const val CONFIGURATION_EXTENSION_NAME = "configuration" internal const val MULTIPLATFORM_EXTENSION_NAME = "multiplatform" open class DokkaPlugin : Plugin<Project> { + private val taskName = "dokka" override fun apply(project: Project) { - DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) + loadDokkaVersion() + val dokkaRuntimeConfiguration = addConfiguration(project) + addTasks(project, dokkaRuntimeConfiguration, DokkaTask::class.java) + } - val dokkaRuntimeConfiguration = project.configurations.create("dokkaRuntime") - val defaultDokkaRuntimeConfiguration = project.configurations.create("defaultDokkaRuntime") - val taskName = "dokka" + protected fun loadDokkaVersion() = DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties")) - defaultDokkaRuntimeConfiguration.defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } + protected fun addConfiguration(project: Project) = + project.configurations.create("dokkaRuntime").apply { + defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } + } + protected fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class<out DokkaTask>) { if(GradleVersion.current() >= GradleVersion.version("4.10")) { - project.tasks.register(taskName, DokkaTask::class.java).configure { + project.tasks.register(taskName, taskClass).configure { it.outputDirectory = File(project.buildDir, taskName).absolutePath } } else { - project.tasks.create(taskName, DokkaTask::class.java).apply { + project.tasks.create(taskName, taskClass).apply { outputDirectory = File(project.buildDir, taskName).absolutePath } } - - project.tasks.withType(DokkaTask::class.java) { task -> + project.tasks.withType(taskClass) { task -> task.multiplatform = project.container(GradlePassConfigurationImpl::class.java) task.configuration = GradlePassConfigurationImpl() - task.dokkaRuntime = dokkaRuntimeConfiguration - task.defaultDokkaRuntime = defaultDokkaRuntimeConfiguration + task.dokkaRuntime = runtimeConfiguration } } } |