From 9bbea47f93323b0a514d1c732a9a78a8f6821bb5 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 10 Mar 2017 20:02:48 +0300 Subject: [PATCH] Kotlin Facet: Parse and merge compiler arguments specified in elements instead of appending them (to avoid duplication) #KT-16776 Fixed --- .../kotlin/idea/maven/KotlinMavenImporter.kt | 9 +-- .../idea/maven/KotlinMavenImporterTest.kt | 69 +++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index ea0e24f7bad..7003dcdf9a4 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -36,6 +36,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.parseArguments import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.JvmTarget @@ -131,10 +132,10 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ } } - return ArrayList().apply { - this += ArgumentUtils.convertArgumentsToStringList(arguments) - configuration.getChild("args")?.getChildren("arg")?.mapNotNullTo(this) { it.text } - } + val additionalArgs = configuration.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList() + parseArguments(additionalArgs.toTypedArray(), arguments, true) + + return ArgumentUtils.convertArgumentsToStringList(arguments) } private val compilationGoals = listOf(PomFile.KotlinGoals.Compile, diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt index 540c54048c8..f7483ca0b17 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt @@ -1286,6 +1286,75 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { } } + fun testArgsOverridingInFacet() { + createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") + + importProject(""" + test + project + 1.0.0 + + + + org.jetbrains.kotlin + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + 1.6 + temp + 1.0 + 1.0 + + -jvm-target + 1.8 + -language-version + 1.1 + -api-version + 1.1 + -jdk-home + c:\program files\jdk1.8 + + + + + + """) + + assertModules("project") + assertImporterStatePresent() + + with (facetSettings) { + Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) + Assert.assertEquals("1.1", languageLevel!!.description) + Assert.assertEquals("1.1", apiLevel!!.description) + Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) + Assert.assertEquals( + listOf("-jdk-home", "c:\\program files\\jdk1.8"), + compilerSettings!!.additionalArgumentsAsList + ) + } + } + private fun assertImporterStatePresent() { assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java)) }