Kotlin Facet: Do not import jdkHome from Gradle/Maven model

#KT-18151 Fixed
This commit is contained in:
Alexey Sedunov
2017-06-14 14:49:45 +03:00
parent fe42586c6f
commit f68689b5e4
4 changed files with 24 additions and 33 deletions
@@ -38,10 +38,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
@@ -128,7 +125,6 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
when (arguments) {
is K2JVMCompilerArguments -> {
arguments.classpath = configuration?.getChild("classpath")?.text
arguments.jdkHome = configuration?.getChild("jdkHome")?.text ?: mavenProject.properties["kotlin.compiler.jdkHome"]?.toString()
arguments.jvmTarget = configuration?.getChild("jvmTarget")?.text ?: mavenProject.properties["kotlin.compiler.jvmTarget"]?.toString()
}
is K2JSCompilerArguments -> {
@@ -431,7 +431,6 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<arg>-Xcoroutines=enable</arg>
</args>
<jvmTarget>1.8</jvmTarget>
<jdkHome>JDK_HOME</jdkHome>
<classpath>foobar.jar</classpath>
</configuration>
</plugin>
@@ -452,7 +451,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals("-jdk-home JDK_HOME -Xmulti-platform",
Assert.assertEquals("-Xmulti-platform",
compilerSettings!!.additionalArguments)
}
}
@@ -622,7 +621,6 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<args>
<arg>-Xcoroutines=enable</arg>
</args>
<jdkHome>JDK_HOME</jdkHome>
<classpath>foobar.jar</classpath>
</configuration>
</execution>
@@ -650,8 +648,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals("-jdk-home JDK_HOME -Xmulti-platform",
compilerSettings!!.additionalArguments)
Assert.assertEquals("-Xmulti-platform", compilerSettings!!.additionalArguments)
}
}
@@ -693,7 +690,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<arg>-jvm-target</arg>
<arg>1.8</arg>
<arg>-Xcoroutines=enable</arg>
<arg>-jdk-home</arg>
<arg>-classpath</arg>
<arg>c:\program files\jdk1.8</arg>
</args>
</configuration>
@@ -709,10 +706,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals(
listOf("-jdk-home", "c:/program files/jdk1.8"),
compilerSettings!!.additionalArgumentsAsList
)
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
}
}
@@ -1377,7 +1371,6 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
</executions>
<configuration>
<jvmTarget>1.6</jvmTarget>
<jdkHome>temp</jdkHome>
<languageVersion>1.0</languageVersion>
<apiVersion>1.0</apiVersion>
<args>
@@ -1387,8 +1380,6 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<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>
@@ -1404,10 +1395,6 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
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
)
}
}
@@ -1447,12 +1434,13 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
</executions>
<configuration>
<jvmTarget>1.7</jvmTarget>
<jdkHome>temp</jdkHome>
<languageVersion>1.1</languageVersion>
<apiVersion>1.0</apiVersion>
<args>
<arg>-java-parameters</arg>
<arg>-Xdump-declarations-to=dumpDir</arg>
<arg>-kotlin-home</arg>
<arg>temp</arg>
</args>
</configuration>
</plugin>
@@ -1555,7 +1543,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<configuration>
<jvmTarget>1.8</jvmTarget>
<args combine.children="append">
<arg>-jdk-home</arg>
<arg>-kotlin-home</arg>
<arg>temp2</arg>
</args>
</configuration>
@@ -1608,7 +1596,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
<configuration combine.self="override">
<jvmTarget>1.8</jvmTarget>
<args>
<arg>-jdk-home</arg>
<arg>-kotlin-home</arg>
<arg>temp2</arg>
</args>
</configuration>
@@ -1629,7 +1617,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(
listOf("-jdk-home", "temp", "-Xdump-declarations-to=dumpDir2"),
listOf("-Xdump-declarations-to=dumpDir2"),
compilerSettings!!.additionalArgumentsAsList
)
}
@@ -1640,7 +1628,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(
listOf("-jdk-home", "temp2", "-java-parameters", "-Xdump-declarations-to=dumpDir"),
listOf("-kotlin-home", "temp2", "-java-parameters", "-Xdump-declarations-to=dumpDir"),
compilerSettings!!.additionalArgumentsAsList
)
}
@@ -1651,7 +1639,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.1", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(
listOf("-jdk-home", "temp2"),
listOf("-kotlin-home", "temp2"),
compilerSettings!!.additionalArgumentsAsList
)
}
@@ -177,6 +177,12 @@ private val CommonCompilerArguments.primaryFields: List<String>
else -> commonPrimaryFields
}
private val CommonCompilerArguments.ignoredFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> listOf(K2JVMCompilerArguments::noJdk.name, K2JVMCompilerArguments::jdkHome.name)
else -> emptyList()
}
fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: List<String>, kotlinFacet: KotlinFacet) {
val argumentArray = arguments.toTypedArray()
@@ -191,15 +197,16 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
compilerArguments.convertPathsToSystemIndependent()
// Retain only fields exposed in facet configuration editor.
// Retain only fields exposed (and not explicitly ignored) in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments
val primaryFields = compilerArguments.primaryFields
val ignoredFields = compilerArguments.ignoredFields
fun exposeAsAdditionalArgument(field: Field) = field.name !in primaryFields && field.get(compilerArguments) != field.get(defaultCompilerArguments)
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(compilerArguments, this, ::exposeAsAdditionalArgument)
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
ArgumentUtils.convertArgumentsToStringList(this).joinToString(separator = " ") {
if (StringUtil.containsWhitespaces(it) || it.startsWith('"')) {
StringUtil.wrapWithDoubleQuote(StringUtil.escapeQuotes(it))
@@ -210,7 +217,7 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
if (additionalArgumentsString.isNotEmpty()) additionalArgumentsString else CompilerSettings.DEFAULT_ADDITIONAL_ARGUMENTS
with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(this, compilerArguments, ::exposeAsAdditionalArgument)
copyFieldsSatisfying(this, compilerArguments) { exposeAsAdditionalArgument(it) || it.name in ignoredFields }
}
}
}
@@ -704,14 +704,14 @@ class GradleFacetImportTest : GradleImportingTestCase() {
apply plugin: 'kotlin-platform-jvm'
compileKotlin {
kotlinOptions.jdkHome = "c:\\program files\\jdk1.8"
kotlinOptions.freeCompilerArgs = ["-module", "module with spaces"]
}
""")
importProject()
with (facetSettings) {
Assert.assertEquals(
listOf("-jdk-home", "c:/program files/jdk1.8", "-Xmulti-platform"),
listOf("-module", "module with spaces"),
compilerSettings!!.additionalArgumentsAsList
)
}