From c4a33e0a2fb5ed61034d13354797be8eb61a6bba Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 5 Sep 2018 17:34:24 +0300 Subject: [PATCH] [CHECKME] Support non-convention KotlinNativeCompile task in IDEA import --- .../src/KotlinMPPGradleModelBuilder.kt | 19 +++++++++++++++---- .../src/KotlinMPPGradleModelBuilder.kt.181 | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt index 709ad4252f5..ee325aaa9d4 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt +++ b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt @@ -13,6 +13,7 @@ import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.component.ProjectComponentIdentifier import org.gradle.api.file.FileCollection import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.provider.Property import org.jetbrains.plugins.gradle.model.AbstractExternalDependency import org.jetbrains.plugins.gradle.model.DefaultExternalProjectDependency import org.jetbrains.plugins.gradle.model.ExternalDependency @@ -248,8 +249,13 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { private fun buildCompilationArguments(compileKotlinTask: Task): KotlinCompilationArguments? { val compileTaskClass = compileKotlinTask.javaClass - val getCurrentArguments = compileTaskClass.getMethodOrNull("getSerializedCompilerArguments") ?: return null - val getDefaultArguments = compileTaskClass.getMethodOrNull("getDefaultSerializedCompilerArguments") ?: return null + val getCurrentArguments = compileTaskClass.getMethodOrNull("getSerializedCompilerArguments") + val getDefaultArguments = compileTaskClass.getMethodOrNull("getDefaultSerializedCompilerArguments") + + //TODO: Hack for KotlinNativeCompile + if (getCurrentArguments == null || getDefaultArguments == null) { + return KotlinCompilationArgumentsImpl(emptyList(), emptyList()) + } @Suppress("UNCHECKED_CAST") val currentArguments = getCurrentArguments(compileKotlinTask) as? List ?: return null @Suppress("UNCHECKED_CAST") @@ -277,10 +283,15 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { val getClassesDirs = gradleOutputClass.getMethodOrNull("getClassesDirs") ?: return null val getResourcesDir = gradleOutputClass.getMethodOrNull("getResourcesDir") ?: return null val compileKotlinTaskClass = compileKotlinTask.javaClass - val getDestinationDir = compileKotlinTaskClass.getMethodOrNull("getDestinationDir") ?: return null + val getDestinationDir = compileKotlinTaskClass.getMethodOrNull("getDestinationDir") + val getOutputFile = compileKotlinTaskClass.getMethodOrNull("getOutputFile") val classesDirs = getClassesDirs(gradleOutput) as? FileCollection ?: return null val resourcesDir = getResourcesDir(gradleOutput) as? File ?: return null - val destinationDir = getDestinationDir(compileKotlinTask) as? File + val destinationDir = + getDestinationDir?.invoke(compileKotlinTask) as? File + //TODO: Hack for KotlinNativeCompile + ?: (getOutputFile?.invoke(compileKotlinTask) as? Property)?.orNull?.parentFile + ?: return null return KotlinCompilationOutputImpl(classesDirs.files, destinationDir, resourcesDir) } diff --git a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt.181 b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt.181 index 45cd6e292e2..c2035677d8a 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt.181 +++ b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt.181 @@ -13,6 +13,7 @@ import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.component.ProjectComponentIdentifier import org.gradle.api.file.FileCollection import org.gradle.api.file.SourceDirectorySet +import org.gradle.api.provider.Property import org.jetbrains.plugins.gradle.model.AbstractExternalDependency import org.jetbrains.plugins.gradle.model.DefaultExternalProjectDependency import org.jetbrains.plugins.gradle.model.ExternalDependency @@ -248,8 +249,13 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { private fun buildCompilationArguments(compileKotlinTask: Task): KotlinCompilationArguments? { val compileTaskClass = compileKotlinTask.javaClass - val getCurrentArguments = compileTaskClass.getMethodOrNull("getSerializedCompilerArguments") ?: return null - val getDefaultArguments = compileTaskClass.getMethodOrNull("getDefaultSerializedCompilerArguments") ?: return null + val getCurrentArguments = compileTaskClass.getMethodOrNull("getSerializedCompilerArguments") + val getDefaultArguments = compileTaskClass.getMethodOrNull("getDefaultSerializedCompilerArguments") + + //TODO: Hack for KotlinNativeCompile + if (getCurrentArguments == null || getDefaultArguments == null) { + return KotlinCompilationArgumentsImpl(emptyList(), emptyList()) + } @Suppress("UNCHECKED_CAST") val currentArguments = getCurrentArguments(compileKotlinTask) as? List ?: return null @Suppress("UNCHECKED_CAST") @@ -277,10 +283,15 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { val getClassesDirs = gradleOutputClass.getMethodOrNull("getClassesDirs") ?: return null val getResourcesDir = gradleOutputClass.getMethodOrNull("getResourcesDir") ?: return null val compileKotlinTaskClass = compileKotlinTask.javaClass - val getDestinationDir = compileKotlinTaskClass.getMethodOrNull("getDestinationDir") ?: return null + val getDestinationDir = compileKotlinTaskClass.getMethodOrNull("getDestinationDir") + val getOutputFile = compileKotlinTaskClass.getMethodOrNull("getOutputFile") val classesDirs = getClassesDirs(gradleOutput) as? FileCollection ?: return null val resourcesDir = getResourcesDir(gradleOutput) as? File ?: return null - val destinationDir = getDestinationDir(compileKotlinTask) as? File + val destinationDir = + getDestinationDir?.invoke(compileKotlinTask) as? File + //TODO: Hack for KotlinNativeCompile + ?: (getOutputFile?.invoke(compileKotlinTask) as? Property)?.orNull?.parentFile + ?: return null return KotlinCompilationOutputImpl(classesDirs.files, destinationDir, resourcesDir) }