Kotlin Facet: Parse and merge compiler arguments specified in <arg> elements instead of appending them (to avoid duplication)
#KT-16776 Fixed
This commit is contained in:
@@ -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.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
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.compilerRunner.ArgumentUtils
|
||||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
import org.jetbrains.kotlin.config.CoroutineSupport
|
||||||
import org.jetbrains.kotlin.config.JvmTarget
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
@@ -131,10 +132,10 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ArrayList<String>().apply {
|
val additionalArgs = configuration.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList()
|
||||||
this += ArgumentUtils.convertArgumentsToStringList(arguments)
|
parseArguments(additionalArgs.toTypedArray(), arguments, true)
|
||||||
configuration.getChild("args")?.getChildren("arg")?.mapNotNullTo(this) { it.text }
|
|
||||||
}
|
return ArgumentUtils.convertArgumentsToStringList(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val compilationGoals = listOf(PomFile.KotlinGoals.Compile,
|
private val compilationGoals = listOf(PomFile.KotlinGoals.Compile,
|
||||||
|
|||||||
@@ -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("""
|
||||||
|
<groupId>test</groupId>
|
||||||
|
<artifactId>project</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib</artifactId>
|
||||||
|
<version>$kotlinVersion</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>1.6</jvmTarget>
|
||||||
|
<jdkHome>temp</jdkHome>
|
||||||
|
<languageVersion>1.0</languageVersion>
|
||||||
|
<apiVersion>1.0</apiVersion>
|
||||||
|
<args>
|
||||||
|
<arg>-jvm-target</arg>
|
||||||
|
<arg>1.8</arg>
|
||||||
|
<arg>-language-version</arg>
|
||||||
|
<arg>1.1</arg>
|
||||||
|
<arg>-api-version</arg>
|
||||||
|
<arg>1.1</arg>
|
||||||
|
<arg>-jdk-home</arg>
|
||||||
|
<arg>c:\program files\jdk1.8</arg>
|
||||||
|
</args>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
""")
|
||||||
|
|
||||||
|
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() {
|
private fun assertImporterStatePresent() {
|
||||||
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
|
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user