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/src/main') 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