From e0be6a3d4536ad6aa2d764d96169cd0ca17613b8 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Mon, 23 Sep 2019 10:25:45 +0200 Subject: Refactor configuration extraction --- .../dokka/gradle/ConfigurationExtractor.kt | 28 ++--- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 125 +++++++-------------- .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 12 ++ 3 files changed, 68 insertions(+), 97 deletions(-) (limited to 'runners/gradle-plugin') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index c66998d9..7ae9bca5 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -26,6 +26,12 @@ import java.io.Serializable class ConfigurationExtractor(private val project: Project) { + fun extractConfiguration(targetName: String, variantName: String?) = if (project.isMultiplatformProject()) { + extractFromMultiPlatform(targetName, variantName) + } else { + extractFromSinglePlatform(variantName) + } + fun extractFromSinglePlatform(variantName: String? = null): PlatformData? { val target: KotlinTarget try { @@ -45,28 +51,22 @@ class ConfigurationExtractor(private val project: Project) { } } - fun extractFromMultiPlatform(): List? { - val targets: NamedDomainObjectCollection + private fun extractFromMultiPlatform(targetName: String, variantName: String?): PlatformData? = try { - targets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets + project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets } catch (e: Throwable) { when (e){ is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> - return null + null else -> throw e } + }?.let { + val fixedName = if(targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() + it.find { target -> target.name.toLowerCase() == fixedName }?.let { target -> + PlatformData(fixedName, getClasspath(target, variantName), getSourceSet(target, variantName), target.platformType.toString()) + } } - val commonTargetPlatformData = targets.find { it.platformType == KotlinPlatformType.common }?.let { - PlatformData("common", getClasspath(it), getSourceSet(it), "common") - } - val config = targets.filter { it.platformType != KotlinPlatformType.common }.map { - PlatformData(it.name, getClasspath(it), getSourceSet(it), it.platformType.toString()) - } - - return (config + commonTargetPlatformData).filterNotNull() - } - fun extractFromJavaPlugin(): PlatformData? = project.convention.findPlugin(JavaPluginConvention::class.java) ?.run { sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME)?.allSource?.srcDirs } 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 5153ae1c..35ef118a 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 @@ -15,6 +15,7 @@ import org.jetbrains.dokka.Platform import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance import org.jetbrains.dokka.gradle.ConfigurationExtractor.PlatformData +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import java.io.File import java.net.URLClassLoader import java.util.concurrent.Callable @@ -52,6 +53,9 @@ open class DokkaTask : DefaultTask() { var dokkaRuntime: Configuration? = null + @Input + var subProjects: List = emptyList() + @Input var impliedPlatforms: MutableList = arrayListOf() @@ -72,15 +76,11 @@ open class DokkaTask : DefaultTask() { // Configure Dokka with closure in Gradle Kotlin DSL fun configuration(action: Action) = action.execute(configuration) - private var externalDocumentationLinks: MutableList = mutableListOf() private val kotlinTasks: List by lazy { extractKotlinCompileTasks(configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) } private val configExtractor = ConfigurationExtractor(project) - @Input - var subProjects: List = emptyList() - @Input var disableAutoconfiguration: Boolean = false @@ -153,7 +153,7 @@ open class DokkaTask : DefaultTask() { val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } val passConfigurationList = collectConfigurations() - .map { defaultPassConfiguration(globalConfig, it) } + .map { defaultPassConfiguration(it, globalConfig) } val configuration = GradleDokkaConfigurationImpl() configuration.outputDir = outputDirectory @@ -181,38 +181,15 @@ open class DokkaTask : DefaultTask() { } } - private fun collectConfigurations(): List = - if (this.isMultiplatformProject()) collectFromMultiPlatform() else collectFromSinglePlatform() + private fun collectConfigurations() = + if (this.isMultiplatformProject()) collectMultiplatform() else listOf(collectSinglePlatform(configuration)) - private fun collectFromMultiPlatform(): List { - val userConfig = multiplatform - .filterNot { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } - .map { - if (it.collectKotlinTasks != null) { - configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) - ?.let { platformData -> mergeUserConfigurationAndPlatformData(it, platformData) } ?: it - } else { - it - } - } - - if (disableAutoconfiguration) return userConfig - - val baseConfig = mergeUserAndAutoConfigurations( - userConfig, - configExtractor.extractFromMultiPlatform().orEmpty() - ) - - return if (subProjects.isNotEmpty()) - subProjects.toProjects().fold(baseConfig) { list, subProject -> - mergeUserAndAutoConfigurations(list, ConfigurationExtractor(subProject).extractFromMultiPlatform().orEmpty()) - } - else - baseConfig - } + private fun collectMultiplatform() = multiplatform + .filterNot { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } + .map { collectSinglePlatform(it) } - private fun collectFromSinglePlatform(): List { - val userConfig = configuration.let { + private fun collectSinglePlatform(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + val userConfig = config.let { if (it.collectKotlinTasks != null) { configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) ?.let { platformData -> mergeUserConfigurationAndPlatformData(it, platformData) } ?: it @@ -221,21 +198,27 @@ open class DokkaTask : DefaultTask() { } } - if (disableAutoconfiguration) return listOf(userConfig) + if (disableAutoconfiguration) return userConfig - val extractedConfig = configExtractor.extractFromSinglePlatform(userConfig.androidVariant) - val baseConfig = if (extractedConfig != null) - listOf(mergeUserConfigurationAndPlatformData(userConfig, extractedConfig)) - else - collectFromSinglePlatformOldPlugin() + val baseConfig = configExtractor.extractConfiguration(userConfig.name, userConfig.androidVariant) + ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } + ?: if (this.isMultiplatformProject()) { + if (outputDiagnosticInfo) + logger.warn("Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin, " + + "using only user provided configuration for this target") + userConfig + } else { + logger.warn("Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin") + collectFromSinglePlatformOldPlugin() + } return if (subProjects.isNotEmpty()) { try { - subProjects.toProjects().fold(baseConfig) { list, subProject -> - listOf(mergeUserConfigurationAndPlatformData( - list.first(), - ConfigurationExtractor(subProject).extractFromSinglePlatform()!! - )) + subProjects.toProjects().fold(baseConfig) { config, subProject -> + mergeUserConfigurationAndPlatformData( + config, + ConfigurationExtractor(subProject).extractConfiguration(config.name, config.androidVariant)!! + ) } } catch(e: NullPointerException) { logger.warn("Cannot extract sources from subProjects. Do you have the Kotlin plugin in version 1.3.30+ " + @@ -247,41 +230,14 @@ open class DokkaTask : DefaultTask() { } } - private fun collectFromSinglePlatformOldPlugin(): List { - val kotlinTasks = configExtractor.extractFromKotlinTasks(kotlinTasks) - return if (kotlinTasks != null) { - listOf(mergeUserConfigurationAndPlatformData(configuration, kotlinTasks)) - } else { - val javaPlugin = configExtractor.extractFromJavaPlugin() - if (javaPlugin != null) - listOf(mergeUserConfigurationAndPlatformData(configuration, javaPlugin)) else listOf(configuration) - } - } - - private fun mergeUserAndAutoConfigurations(userConfigurations: List, - autoConfigurations: List): List { - val merged: MutableList = mutableListOf() - merged.addAll( - userConfigurations.map { userConfig -> - val autoConfig = autoConfigurations.find { autoConfig -> autoConfig.name == userConfig.name } - if (autoConfig != null) { - mergeUserConfigurationAndPlatformData(userConfig, autoConfig) - } else { - if(outputDiagnosticInfo) { - logger.warn( - "Could not find platform with name: ${userConfig.name} in Kotlin Gradle Plugin, " + - "using only user provided configuration for this platform" - ) - } - userConfig - } - } - ) - return merged.toList() - } + private fun collectFromSinglePlatformOldPlugin() = + configExtractor.extractFromKotlinTasks(kotlinTasks) + ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } + ?: configExtractor.extractFromJavaPlugin() + ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } + ?: configuration - private fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, - autoConfig: PlatformData): GradlePassConfigurationImpl = + private fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, autoConfig: PlatformData) = userConfig.copy().apply { sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() @@ -289,7 +245,10 @@ open class DokkaTask : DefaultTask() { platform = autoConfig.platform } - private fun defaultPassConfiguration(globalConfig: GradlePassConfigurationImpl?, config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + private fun defaultPassConfiguration( + config: GradlePassConfigurationImpl, + globalConfig: GradlePassConfigurationImpl? + ): GradlePassConfigurationImpl { if (config.moduleName == "") { config.moduleName = project.name } @@ -304,7 +263,6 @@ open class DokkaTask : DefaultTask() { if (project.isAndroidProject() && !config.noAndroidSdkLink) { // TODO: introduce Android as a separate Dokka platform? config.externalDocumentationLinks.add(ANDROID_REFERENCE_URL) } - config.externalDocumentationLinks.addAll(externalDocumentationLinks) if (config.platform != null && config.platform.toString().isNotEmpty()) { config.analysisPlatform = dokkaPlatformFromString(config.platform.toString()) } @@ -319,7 +277,8 @@ open class DokkaTask : DefaultTask() { } private fun dokkaPlatformFromString(platform: String) = when (platform.toLowerCase()) { - "androidjvm", "android" -> Platform.jvm + KotlinPlatformType.androidJvm.toString().toLowerCase(), "androidjvm", "android" -> Platform.jvm + "metadata" -> Platform.common else -> Platform.fromString(platform) } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index d70b0499..31892e8e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.gradle import org.gradle.api.Project import org.gradle.api.UnknownDomainObjectException +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget @@ -15,5 +16,16 @@ fun Project.isAndroidProject() = try { false } +fun Project.isMultiplatformProject() = try { + project.extensions.getByType(KotlinMultiplatformExtension::class.java) + true +} catch(e: UnknownDomainObjectException) { + false +} catch (e: NoClassDefFoundError){ + false +} catch(e: ClassNotFoundException) { + false +} + fun KotlinTarget.isAndroidTarget() = this.platformType == KotlinPlatformType.androidJvm fun DokkaTask.isMultiplatformProject() = this.multiplatform.isNotEmpty() \ No newline at end of file -- cgit From 2ff1c6e5751f6e1e94a346c92775c1fa94ea9e63 Mon Sep 17 00:00:00 2001 From: BarkingBad <32793002+BarkingBad@users.noreply.github.com> Date: Thu, 28 Nov 2019 11:34:11 +0100 Subject: Resolved problems with android multiflavors documentation shadowing (#527) --- .../dokka/gradle/ConfigurationExtractor.kt | 42 ++++++++++++++-------- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 4 +-- .../dokka/gradle/configurationImplementations.kt | 2 +- 3 files changed, 30 insertions(+), 18 deletions(-) (limited to 'runners/gradle-plugin') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index 7ae9bca5..104635dc 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -26,13 +26,13 @@ import java.io.Serializable class ConfigurationExtractor(private val project: Project) { - fun extractConfiguration(targetName: String, variantName: String?) = if (project.isMultiplatformProject()) { - extractFromMultiPlatform(targetName, variantName) + fun extractConfiguration(targetName: String, variantNames: List) = if (project.isMultiplatformProject()) { + extractFromMultiPlatform(targetName, variantNames) } else { - extractFromSinglePlatform(variantName) + extractFromSinglePlatform(variantNames) } - fun extractFromSinglePlatform(variantName: String? = null): PlatformData? { + private fun extractFromSinglePlatform(variantNames: List): PlatformData? { val target: KotlinTarget try { target = project.extensions.getByType(KotlinSingleTargetExtension::class.java).target @@ -45,13 +45,14 @@ class ConfigurationExtractor(private val project: Project) { } return try { - PlatformData(null, getClasspath(target, variantName), getSourceSet(target, variantName), getPlatformName(target.platformType)) + + PlatformData(null, accumulateClassPaths(variantNames, target), accumulateSourceSets(variantNames, target), getPlatformName(target.platformType)) } catch(e: NoSuchMethodError){ null } } - private fun extractFromMultiPlatform(targetName: String, variantName: String?): PlatformData? = + private fun extractFromMultiPlatform(targetName: String, variantNames: List): PlatformData? = try { project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets } catch (e: Throwable) { @@ -63,7 +64,8 @@ class ConfigurationExtractor(private val project: Project) { }?.let { val fixedName = if(targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() it.find { target -> target.name.toLowerCase() == fixedName }?.let { target -> - PlatformData(fixedName, getClasspath(target, variantName), getSourceSet(target, variantName), target.platformType.toString()) + + PlatformData(fixedName, accumulateClassPaths(variantNames, target), accumulateSourceSets(variantNames, target), target.platformType.toString()) } } @@ -139,20 +141,17 @@ class ConfigurationExtractor(private val project: Project) { return PlatformData(null, classpath, allSourceRoots.toList(), "") } - private fun getSourceSet(target: KotlinTarget, variantName: String? = null): List = - if(variantName != null) + private fun getSourceSet(target: KotlinTarget, variantName: String): List = + if (target.isAndroidTarget()) getSourceSet(getCompilation(target, variantName)) else getSourceSet(getMainCompilation(target)) - private fun getClasspath(target: KotlinTarget, variantName: String? = null): List = if (target.isAndroidTarget()) { - if(variantName != null) + private fun getClasspath(target: KotlinTarget, variantName: String): List = + if (target.isAndroidTarget()) getClasspathFromAndroidTask(getCompilation(target, variantName)) else - getClasspathFromAndroidTask(getMainCompilation(target)) - } else { - getClasspath(getMainCompilation(target)) - } + getClasspath(getMainCompilation(target)) private fun getSourceSet(compilation: KotlinCompilation<*>?): List = compilation ?.allKotlinSourceSets @@ -210,6 +209,19 @@ class ConfigurationExtractor(private val project: Project) { private fun getPlatformName(platform: KotlinPlatformType): String = if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() + private fun accumulateClassPaths(variantNames: List, target: KotlinTarget) = + if(variantNames.isNotEmpty()) + variantNames.flatMap { getClasspath(target, it) }.distinct() + else + getClasspath(getMainCompilation(target)) + + private fun accumulateSourceSets(variantNames: List, target: KotlinTarget) = + if(variantNames.isNotEmpty()) + variantNames.flatMap { getSourceSet(target, it) }.distinct() + else + getSourceSet(getMainCompilation(target)) + + data class PlatformData(val name: String?, val classpath: List, val sourceRoots: List, 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 35ef118a..0412b8a7 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 @@ -200,7 +200,7 @@ open class DokkaTask : DefaultTask() { if (disableAutoconfiguration) return userConfig - val baseConfig = configExtractor.extractConfiguration(userConfig.name, userConfig.androidVariant) + val baseConfig = configExtractor.extractConfiguration(userConfig.name, userConfig.androidVariants) ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } ?: if (this.isMultiplatformProject()) { if (outputDiagnosticInfo) @@ -217,7 +217,7 @@ open class DokkaTask : DefaultTask() { subProjects.toProjects().fold(baseConfig) { config, subProject -> mergeUserConfigurationAndPlatformData( config, - ConfigurationExtractor(subProject).extractConfiguration(config.name, config.androidVariant)!! + ConfigurationExtractor(subProject).extractConfiguration(config.name, config.androidVariants)!! ) } } catch(e: NullPointerException) { 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 767bf4f4..55d110f4 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 @@ -51,7 +51,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var targets: List = emptyList() @Input @Optional override var sinceKotlin: String? = null @Transient var collectKotlinTasks: (() -> List?)? = null - @Input @Optional @Transient var androidVariant: String? = null + @Input @Optional @Transient var androidVariants: List = emptyList() fun kotlinTasks(taskSupplier: Callable>) { collectKotlinTasks = { taskSupplier.call() } -- cgit From aefc1bb14d8c89599d80b31fa2162c1f8cec0ca3 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 28 Nov 2019 12:03:29 +0100 Subject: Use builder when creating external link configuration Fixes https://github.com/Kotlin/dokka/issues/514 --- .../dokka/gradle/ConfigurationExtractor.kt | 65 +++++++++++++--------- .../dokka/gradle/configurationImplementations.kt | 34 +++++++---- 2 files changed, 64 insertions(+), 35 deletions(-) (limited to 'runners/gradle-plugin') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index 104635dc..f3ce7d6f 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -26,18 +26,19 @@ import java.io.Serializable class ConfigurationExtractor(private val project: Project) { - fun extractConfiguration(targetName: String, variantNames: List) = if (project.isMultiplatformProject()) { - extractFromMultiPlatform(targetName, variantNames) - } else { - extractFromSinglePlatform(variantNames) - } + fun extractConfiguration(targetName: String, variantNames: List) = + if (project.isMultiplatformProject()) { + extractFromMultiPlatform(targetName, variantNames) + } else { + extractFromSinglePlatform(variantNames) + } private fun extractFromSinglePlatform(variantNames: List): PlatformData? { val target: KotlinTarget try { target = project.extensions.getByType(KotlinSingleTargetExtension::class.java).target } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> return null else -> throw e @@ -45,9 +46,13 @@ class ConfigurationExtractor(private val project: Project) { } return try { - - PlatformData(null, accumulateClassPaths(variantNames, target), accumulateSourceSets(variantNames, target), getPlatformName(target.platformType)) - } catch(e: NoSuchMethodError){ + PlatformData( + null, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + getPlatformName(target.platformType) + ) + } catch (e: NoSuchMethodError) { null } } @@ -56,16 +61,20 @@ class ConfigurationExtractor(private val project: Project) { try { project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> null else -> throw e } }?.let { - val fixedName = if(targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() + val fixedName = if (targetName.toLowerCase() == "common") "metadata" else targetName.toLowerCase() it.find { target -> target.name.toLowerCase() == fixedName }?.let { target -> - - PlatformData(fixedName, accumulateClassPaths(variantNames, target), accumulateSourceSets(variantNames, target), target.platformType.toString()) + PlatformData( + fixedName, + accumulateClassPaths(variantNames, target), + accumulateSourceSets(variantNames, target), + target.platformType.toString() + ) } } @@ -77,10 +86,15 @@ class ConfigurationExtractor(private val project: Project) { fun extractFromKotlinTasks(kotlinTasks: List): PlatformData? = try { kotlinTasks.map { extractFromKotlinTask(it) }.let { platformDataList -> - PlatformData(null, platformDataList.flatMap { it.classpath }, platformDataList.flatMap { it.sourceRoots }, "") + PlatformData( + null, + platformDataList.flatMap { it.classpath }, + platformDataList.flatMap { it.sourceRoots }, + "" + ) } } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> extractFromKotlinTasksTheHardWay(kotlinTasks) else -> throw e @@ -93,7 +107,7 @@ class ConfigurationExtractor(private val project: Project) { .compilations .find { it.compileKotlinTask == task } } catch (e: Throwable) { - when (e){ + when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets .firstNotNullResult { target -> target.compilations.find { it.compileKotlinTask == task } } @@ -136,7 +150,7 @@ class ConfigurationExtractor(private val project: Project) { } catch (e: ResolveException) { mutableListOf() } - classpath.addAll (project.files(allClasspath).toList()) + classpath.addAll(project.files(allClasspath).toList()) return PlatformData(null, classpath, allSourceRoots.toList(), "") } @@ -184,7 +198,7 @@ class ConfigurationExtractor(private val project: Project) { private fun getVariants(project: Project): Set { val androidExtension = project.extensions.getByName("android") - val baseVariants = when (androidExtension) { + val baseVariants = when (androidExtension) { is AppExtension -> androidExtension.applicationVariants.toSet() is LibraryExtension -> { androidExtension.libraryVariants.toSet() + @@ -210,20 +224,21 @@ class ConfigurationExtractor(private val project: Project) { if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() private fun accumulateClassPaths(variantNames: List, target: KotlinTarget) = - if(variantNames.isNotEmpty()) + if (variantNames.isNotEmpty()) variantNames.flatMap { getClasspath(target, it) }.distinct() else getClasspath(getMainCompilation(target)) private fun accumulateSourceSets(variantNames: List, target: KotlinTarget) = - if(variantNames.isNotEmpty()) + if (variantNames.isNotEmpty()) variantNames.flatMap { getSourceSet(target, it) }.distinct() else getSourceSet(getMainCompilation(target)) - - data class PlatformData(val name: String?, - val classpath: List, - val sourceRoots: List, - val platform: String) : Serializable + data class PlatformData( + val name: String?, + val classpath: List, + val sourceRoots: List, + val platform: String + ) : Serializable } \ No newline at end of file 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 55d110f4..0bf21d57 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 @@ -51,7 +51,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var targets: List = emptyList() @Input @Optional override var sinceKotlin: String? = null @Transient var collectKotlinTasks: (() -> List?)? = null - @Input @Optional @Transient var androidVariants: List = emptyList() + @Input @Transient var androidVariants: List = emptyList() fun kotlinTasks(taskSupplier: Callable>) { collectKotlinTasks = { taskSupplier.call() } @@ -95,14 +95,14 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo } fun externalDocumentationLink(c: Closure) { - val link = ConfigureUtil.configure(c, GradleExternalDocumentationLinkImpl()) - externalDocumentationLinks.add(link) + val builder = ConfigureUtil.configure(c, GradleExternalDocumentationLinkImpl.Builder()) + externalDocumentationLinks.add(builder.build()) } - fun externalDocumentationLink(action: Action) { - val link = GradleExternalDocumentationLinkImpl() - action.execute(link) - externalDocumentationLinks.add(link) + fun externalDocumentationLink(action: Action) { + val builder = GradleExternalDocumentationLinkImpl.Builder() + action.execute(builder) + externalDocumentationLinks.add(builder.build()) } } @@ -112,9 +112,23 @@ class GradleSourceLinkDefinitionImpl : SourceLinkDefinition, Serializable { override var lineSuffix: String? = null } -class GradleExternalDocumentationLinkImpl : ExternalDocumentationLink, Serializable { - override var url: URL = URL("http://") - override var packageListUrl: URL = URL("http://") +class GradleExternalDocumentationLinkImpl( + override val url: URL, + override val packageListUrl: URL +): ExternalDocumentationLink, Serializable { + open class Builder(open var url: URL? = null, + open var packageListUrl: URL? = null) { + + constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) }) + + fun build(): ExternalDocumentationLink = + if (packageListUrl != null && url != null) + GradleExternalDocumentationLinkImpl(url!!, packageListUrl!!) + else if (url != null) + GradleExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list")) + else + throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link") + } } class GradleDokkaConfigurationImpl: DokkaConfiguration { -- cgit From e560fe38ec52fd6cb5426d0027a6f6b1dd771e16 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 28 Nov 2019 12:21:20 +0100 Subject: Fix not skipping empty packages by default Fixes https://github.com/Kotlin/dokka/issues/510 --- .../kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runners/gradle-plugin') 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 0bf21d57..6db1709b 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 @@ -33,7 +33,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var includeNonPublic: Boolean = false @Input override var includeRootPackage: Boolean = false @Input override var reportUndocumented: Boolean = false - @Input override var skipEmptyPackages: Boolean = false + @Input override var skipEmptyPackages: Boolean = true @Input override var skipDeprecated: Boolean = false @Input override var jdkVersion: Int = 6 @Input override var sourceLinks: MutableList = mutableListOf() -- cgit From 00f92bd73bfd8cb1e6da40e0bafe43db3f443e5e Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 28 Nov 2019 14:54:47 +0100 Subject: Add better error message when fatjar cannot be resolved --- .../src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'runners/gradle-plugin') 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 0412b8a7..16f6c83e 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 @@ -86,11 +86,14 @@ open class DokkaTask : DefaultTask() { private var outputDiagnosticInfo: Boolean = false // Workaround for Gradle, which fires some methods (like collectConfigurations()) multiple times in its lifecycle - private fun tryResolveFatJar(configuration: Configuration?): Set { + private fun tryResolveFatJar(configuration: Configuration?, level: Int = 0): Set { + val maxRetries = 10 return try { configuration!!.resolve() } catch (e: Exception) { - project.parent?.let { tryResolveFatJar(configuration) } ?: throw e + if (level >= maxRetries) + throw IllegalStateException("Cannot resolve dokka fatjar! Make sure you have jcenter() in your repositories") + project.parent?.let { tryResolveFatJar(configuration, level + 1) } ?: throw e } } -- cgit From d59f77a81fcbc94a074e7b481af299765342a7a2 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 28 Nov 2019 16:02:13 +0100 Subject: Fix package suppression Package suppression depended on the order of `perPackageOption`s. That should not be the case. Fixes https://github.com/Kotlin/dokka/issues/521 --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 6 ++++-- .../org/jetbrains/dokka/gradle/configurationImplementations.kt | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'runners/gradle-plugin') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 3168e033..666f22fa 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -423,7 +423,7 @@ class DocumentationBuilder fun DocumentationModule.appendFragments(fragments: Collection, packageContent: Map, packageDocumentationBuilder: PackageDocumentationBuilder) { - val allFqNames = fragments.filter{ it.isDocumented(passConfiguration) }.map { it.fqName }.distinct() + val allFqNames = fragments.filter { it.isDocumented(passConfiguration) }.map { it.fqName }.distinct() for (packageName in allFqNames) { if (packageName.isRoot && !passConfiguration.includeRootPackage) continue @@ -1157,7 +1157,9 @@ fun ClassDescriptor.supertypesWithAnyPrecise(): Collection { fun PassConfiguration.effectivePackageOptions(pack: String): DokkaConfiguration.PackageOptions { val rootPackageOptions = PackageOptionsImpl("", includeNonPublic, reportUndocumented, skipDeprecated, false) - return perPackageOptions.firstOrNull { pack == it.prefix || pack.startsWith(it.prefix + ".") } ?: rootPackageOptions + return perPackageOptions.firstOrNull { pack == it.prefix } + ?: perPackageOptions.firstOrNull { pack.startsWith(it.prefix + ".") } + ?: rootPackageOptions } fun PassConfiguration.effectivePackageOptions(pack: FqName): DokkaConfiguration.PackageOptions = effectivePackageOptions(pack.asString()) 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 6db1709b..65afad04 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 @@ -143,8 +143,8 @@ class GradleDokkaConfigurationImpl: DokkaConfiguration { class GradlePackageOptionsImpl: PackageOptions, Serializable { override var prefix: String = "" override var includeNonPublic: Boolean = false - override var reportUndocumented: Boolean = true - override var skipDeprecated: Boolean = true + override var reportUndocumented: Boolean = false + override var skipDeprecated: Boolean = false override var suppress: Boolean = false } -- cgit From 732ffcc09816ceb5eb60377adfb07d43fa160554 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 28 Nov 2019 16:20:32 +0100 Subject: Provide an error message when no pass config is present Fixes https://github.com/Kotlin/dokka/issues/511 --- .../src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runners/gradle-plugin') 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 16f6c83e..97deb100 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 @@ -8,7 +8,6 @@ import org.gradle.api.internal.plugins.DslObject import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaBootstrap -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot import org.jetbrains.dokka.Platform @@ -166,6 +165,11 @@ open class DokkaTask : DefaultTask() { configuration.impliedPlatforms = impliedPlatforms configuration.passesConfigurations = passConfigurationList + if(passConfigurationList.isEmpty() || passConfigurationList == listOf(globalConfig)) { + println("No pass configurations for generation detected!") + return + } + bootstrapProxy.configure( BiConsumer { level, message -> when (level) { -- cgit From 29a4cc77cb981265c3a420a47fd35e4f8da18a25 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 18 Dec 2019 12:33:01 +0100 Subject: Make key methods of plugin and task protected open Addresses https://github.com/Kotlin/dokka/issues/534 --- .../main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 15 +++++++-------- .../src/main/kotlin/org/jetbrains/dokka/gradle/main.kt | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'runners/gradle-plugin') 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 97deb100..c5863318 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 @@ -75,7 +75,6 @@ open class DokkaTask : DefaultTask() { // Configure Dokka with closure in Gradle Kotlin DSL fun configuration(action: Action) = action.execute(configuration) - private val kotlinTasks: List by lazy { extractKotlinCompileTasks(configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) } private val configExtractor = ConfigurationExtractor(project) @@ -126,7 +125,7 @@ open class DokkaTask : DefaultTask() { private fun Iterable.toSourceRoots(): List = this.filter { it.exists() }.map { GradleSourceRootImpl().apply { path = it.path } } private fun Iterable.toProjects(): List = project.subprojects.toList().filter { this.contains(it.name) } - private fun collectSuppressedFiles(sourceRoots: List) = + protected open fun collectSuppressedFiles(sourceRoots: List) = if(project.isAndroidProject()) { val generatedRoot = project.buildDir.resolve("generated").absoluteFile sourceRoots @@ -188,14 +187,14 @@ open class DokkaTask : DefaultTask() { } } - private fun collectConfigurations() = + protected open fun collectConfigurations() = if (this.isMultiplatformProject()) collectMultiplatform() else listOf(collectSinglePlatform(configuration)) - private fun collectMultiplatform() = multiplatform + protected open fun collectMultiplatform() = multiplatform .filterNot { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME } .map { collectSinglePlatform(it) } - private fun collectSinglePlatform(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + protected open fun collectSinglePlatform(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { val userConfig = config.let { if (it.collectKotlinTasks != null) { configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) @@ -237,14 +236,14 @@ open class DokkaTask : DefaultTask() { } } - private fun collectFromSinglePlatformOldPlugin() = + protected open fun collectFromSinglePlatformOldPlugin() = configExtractor.extractFromKotlinTasks(kotlinTasks) ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } ?: configExtractor.extractFromJavaPlugin() ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } ?: configuration - private fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, autoConfig: PlatformData) = + protected open fun mergeUserConfigurationAndPlatformData(userConfig: GradlePassConfigurationImpl, autoConfig: PlatformData) = userConfig.copy().apply { sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() @@ -252,7 +251,7 @@ open class DokkaTask : DefaultTask() { platform = autoConfig.platform } - private fun defaultPassConfiguration( + protected open fun defaultPassConfiguration( config: GradlePassConfigurationImpl, globalConfig: GradlePassConfigurationImpl? ): GradlePassConfigurationImpl { 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 6f8d55e4..7ed29c58 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 @@ -27,7 +27,7 @@ open class DokkaPlugin : Plugin { defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-fatjar:${DokkaVersion.version}")) } } - private fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class) { + protected open fun addTasks(project: Project, runtimeConfiguration: Configuration, taskClass: Class) { if(GradleVersion.current() >= GradleVersion.version("4.10")) { project.tasks.register(taskName, taskClass) } else { -- cgit From 9e7154fef3394698dc52c52d61dd1aefde29251e Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 24 Dec 2019 01:19:10 +0100 Subject: Use a different method for classpath extraction from Android task Fixes https://github.com/Kotlin/dokka/issues/549 --- .../org/jetbrains/dokka/gradle/ConfigurationExtractor.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'runners/gradle-plugin') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index f3ce7d6f..39672b9a 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -224,10 +224,14 @@ class ConfigurationExtractor(private val project: Project) { if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() private fun accumulateClassPaths(variantNames: List, target: KotlinTarget) = - if (variantNames.isNotEmpty()) + if (variantNames.isNotEmpty()) { variantNames.flatMap { getClasspath(target, it) }.distinct() - else - getClasspath(getMainCompilation(target)) + } else { + if (target.isAndroidTarget()) + getClasspathFromAndroidTask(getMainCompilation(target)) + else + getClasspath(getMainCompilation(target)) + } private fun accumulateSourceSets(variantNames: List, target: KotlinTarget) = if (variantNames.isNotEmpty()) -- cgit From 4e4f28f6d3fe08ef60fdac26e512ac6fd16ff5bb Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Mon, 27 Jan 2020 12:22:17 +0100 Subject: Remove stack overflow error See https://github.com/Kotlin/dokka/issues/512#issuecomment-539737596 --- .../src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'runners/gradle-plugin') 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 c5863318..bafe657e 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 @@ -84,20 +84,9 @@ open class DokkaTask : DefaultTask() { private var outputDiagnosticInfo: Boolean = false // Workaround for Gradle, which fires some methods (like collectConfigurations()) multiple times in its lifecycle - private fun tryResolveFatJar(configuration: Configuration?, level: Int = 0): Set { - val maxRetries = 10 - return try { - configuration!!.resolve() - } catch (e: Exception) { - if (level >= maxRetries) - throw IllegalStateException("Cannot resolve dokka fatjar! Make sure you have jcenter() in your repositories") - project.parent?.let { tryResolveFatJar(configuration, level + 1) } ?: throw e - } - } - private fun loadFatJar() { if (ClassloaderContainer.fatJarClassLoader == null) { - val jars = tryResolveFatJar(dokkaRuntime).toList() + val jars = dokkaRuntime!!.resolve().toList() ClassloaderContainer.fatJarClassLoader = URLClassLoader(jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent) } } -- cgit