diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-09-18 11:58:30 +0200 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-09-18 12:01:22 +0200 |
commit | 02fdeb2a67b6bb01c2f4afccaf578b89997f79b4 (patch) | |
tree | c5eb1b5492b71af605546303641665beb2da92cb /runners/gradle-plugin/src/main/kotlin | |
parent | 2460b1d9fd22f5742d99ae79e9bd0eca0f791a03 (diff) | |
download | dokka-02fdeb2a67b6bb01c2f4afccaf578b89997f79b4.tar.gz dokka-02fdeb2a67b6bb01c2f4afccaf578b89997f79b4.tar.bz2 dokka-02fdeb2a67b6bb01c2f4afccaf578b89997f79b4.zip |
Fix for Android classpath bug
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt | 35 |
1 files changed, 23 insertions, 12 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 9f8dfc33..af952148 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 @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult import java.io.File import java.io.Serializable @@ -56,13 +57,14 @@ class ConfigurationExtractor(private val project: Project) { } } - val commonTarget = targets.find { it.platformType == KotlinPlatformType.common } - val platformTargets = targets.filter { it.platformType != KotlinPlatformType.common } - val config = platformTargets.map { + 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 + PlatformData("common", getClasspath(commonTarget), getSourceSet(commonTarget), "common") + return (config + commonTargetPlatformData).filterNotNull() } fun extractFromJavaPlugin(): PlatformData? = @@ -71,16 +73,16 @@ class ConfigurationExtractor(private val project: Project) { ?.let { PlatformData(null, emptyList(), it.toList(), "") } fun extractFromKotlinTasks(kotlinTasks: List<Task>): PlatformData? = - try { + try { kotlinTasks.map { extractFromKotlinTask(it) }.let { platformDataList -> PlatformData(null, platformDataList.flatMap { it.classpath }, platformDataList.flatMap { it.sourceRoots }, "") } } catch (e: Throwable) { - when (e){ - is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> - extractFromKotlinTasksTheHardWay(kotlinTasks) - else -> throw e - } + when (e){ + is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> + extractFromKotlinTasksTheHardWay(kotlinTasks) + else -> throw e + } } private fun extractFromKotlinTask(task: Task): PlatformData = @@ -137,9 +139,13 @@ class ConfigurationExtractor(private val project: Project) { return PlatformData(null, classpath, allSourceRoots.toList(), "") } - private fun getSourceSet(target: KotlinTarget?): List<File> = getSourceSet(getMainCompilation(target)) + private fun getSourceSet(target: KotlinTarget): List<File> = getSourceSet(getMainCompilation(target)) - private fun getClasspath(target: KotlinTarget?): List<File> = getClasspath(getMainCompilation(target)) + private fun getClasspath(target: KotlinTarget): List<File> = if (target.isAndroidTarget()) { + getClasspathFromAndroidTask(getMainCompilation(target)) + } else { + getClasspath(getMainCompilation(target)) + } private fun getSourceSet(compilation: KotlinCompilation<*>?): List<File> = compilation ?.allKotlinSourceSets @@ -154,6 +160,11 @@ class ConfigurationExtractor(private val project: Project) { ?.filter { it.exists() } .orEmpty() + // This is a workaround for KT-33893 + private fun getClasspathFromAndroidTask(compilation: KotlinCompilation<*>?): List<File> = (compilation + ?.compileKotlinTask as? KotlinCompile) + ?.classpath?.files?.toList() ?: getClasspath(compilation) + private fun getMainCompilation(target: KotlinTarget?): KotlinCompilation<KotlinCommonOptions>? = target?.compilations?.getByName(getMainCompilationName(target)) |