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