diff options
author | BarkingBad <32793002+BarkingBad@users.noreply.github.com> | 2019-11-28 11:34:11 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-11-28 11:34:52 +0100 |
commit | 2ff1c6e5751f6e1e94a346c92775c1fa94ea9e63 (patch) | |
tree | 4023e15a6838eb19a4a3818e5b556463e50ec5dd /runners/gradle-plugin/src/main | |
parent | 5e91a085f0bc508e5a9d5f29f27bb2ced8f4e3f1 (diff) | |
download | dokka-2ff1c6e5751f6e1e94a346c92775c1fa94ea9e63.tar.gz dokka-2ff1c6e5751f6e1e94a346c92775c1fa94ea9e63.tar.bz2 dokka-2ff1c6e5751f6e1e94a346c92775c1fa94ea9e63.zip |
Resolved problems with android multiflavors documentation shadowing (#527)
Diffstat (limited to 'runners/gradle-plugin/src/main')
3 files changed, 30 insertions, 18 deletions
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<String>) = if (project.isMultiplatformProject()) { + extractFromMultiPlatform(targetName, variantNames) } else { - extractFromSinglePlatform(variantName) + extractFromSinglePlatform(variantNames) } - fun extractFromSinglePlatform(variantName: String? = null): PlatformData? { + private fun extractFromSinglePlatform(variantNames: List<String>): 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<String>): 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<File> = - if(variantName != null) + private fun getSourceSet(target: KotlinTarget, variantName: String): List<File> = + if (target.isAndroidTarget()) getSourceSet(getCompilation(target, variantName)) else getSourceSet(getMainCompilation(target)) - private fun getClasspath(target: KotlinTarget, variantName: String? = null): List<File> = if (target.isAndroidTarget()) { - if(variantName != null) + private fun getClasspath(target: KotlinTarget, variantName: String): List<File> = + if (target.isAndroidTarget()) getClasspathFromAndroidTask(getCompilation(target, variantName)) else - getClasspathFromAndroidTask(getMainCompilation(target)) - } else { - getClasspath(getMainCompilation(target)) - } + getClasspath(getMainCompilation(target)) private fun getSourceSet(compilation: KotlinCompilation<*>?): List<File> = 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<String>, target: KotlinTarget) = + if(variantNames.isNotEmpty()) + variantNames.flatMap { getClasspath(target, it) }.distinct() + else + getClasspath(getMainCompilation(target)) + + private fun accumulateSourceSets(variantNames: List<String>, target: KotlinTarget) = + if(variantNames.isNotEmpty()) + variantNames.flatMap { getSourceSet(target, it) }.distinct() + else + getSourceSet(getMainCompilation(target)) + + data class PlatformData(val name: String?, val classpath: List<File>, val sourceRoots: List<File>, 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<String> = emptyList() @Input @Optional override var sinceKotlin: String? = null @Transient var collectKotlinTasks: (() -> List<Any?>?)? = null - @Input @Optional @Transient var androidVariant: String? = null + @Input @Optional @Transient var androidVariants: List<String> = emptyList() fun kotlinTasks(taskSupplier: Callable<List<Any>>) { collectKotlinTasks = { taskSupplier.call() } |