Import project configuration specified as Maven properties
#KT-17517 Fixed
This commit is contained in:
@@ -107,38 +107,40 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
||||
configureFacet(mavenProject, modifiableModelsProvider, module)
|
||||
}
|
||||
|
||||
private fun getCompilerArgumentsByConfigurationElement(configuration: Element, platform: TargetPlatformKind<*>): List<String> {
|
||||
private fun getCompilerArgumentsByConfigurationElement(mavenProject: MavenProject,
|
||||
configuration: Element?,
|
||||
platform: TargetPlatformKind<*>): List<String> {
|
||||
val arguments = when (platform) {
|
||||
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
|
||||
is TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
|
||||
is TargetPlatformKind.Common -> K2MetadataCompilerArguments()
|
||||
}
|
||||
|
||||
arguments.apiVersion = configuration.getChild("apiVersion")?.text
|
||||
arguments.languageVersion = configuration.getChild("languageVersion")?.text
|
||||
arguments.multiPlatform = configuration.getChild("multiPlatform")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.suppressWarnings = configuration.getChild("nowarn")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?: mavenProject.properties["kotlin.compiler.apiVersion"]?.toString()
|
||||
arguments.languageVersion = configuration?.getChild("languageVersion")?.text ?: mavenProject.properties["kotlin.compiler.languageVersion"]?.toString()
|
||||
arguments.multiPlatform = configuration?.getChild("multiPlatform")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.suppressWarnings = configuration?.getChild("nowarn")?.text?.trim()?.toBoolean() ?: false
|
||||
|
||||
configuration.getChild("experimentalCoroutines")?.text?.trim()?.let {
|
||||
configuration?.getChild("experimentalCoroutines")?.text?.trim()?.let {
|
||||
arguments.coroutinesState = it
|
||||
}
|
||||
|
||||
when (arguments) {
|
||||
is K2JVMCompilerArguments -> {
|
||||
arguments.classpath = configuration.getChild("classpath")?.text
|
||||
arguments.jdkHome = configuration.getChild("jdkHome")?.text
|
||||
arguments.jvmTarget = configuration.getChild("jvmTarget")?.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()
|
||||
}
|
||||
is K2JSCompilerArguments -> {
|
||||
arguments.sourceMap = configuration.getChild("sourceMap")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.outputFile = configuration.getChild("outputFile")?.text
|
||||
arguments.metaInfo = configuration.getChild("metaInfo")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.moduleKind = configuration.getChild("moduleKind")?.text
|
||||
arguments.main = configuration.getChild("main")?.text
|
||||
arguments.sourceMap = configuration?.getChild("sourceMap")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.outputFile = configuration?.getChild("outputFile")?.text
|
||||
arguments.metaInfo = configuration?.getChild("metaInfo")?.text?.trim()?.toBoolean() ?: false
|
||||
arguments.moduleKind = configuration?.getChild("moduleKind")?.text
|
||||
arguments.main = configuration?.getChild("main")?.text
|
||||
}
|
||||
}
|
||||
|
||||
val additionalArgs = configuration.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList()
|
||||
val additionalArgs = configuration?.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList()
|
||||
parseCommandLineArguments(additionalArgs.toTypedArray(), arguments)
|
||||
|
||||
return ArgumentUtils.convertArgumentsToStringList(arguments)
|
||||
@@ -159,10 +161,10 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
||||
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
|
||||
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!!
|
||||
val configuration = mavenPlugin.configurationElement
|
||||
val sharedArguments = configuration?.let { getCompilerArgumentsByConfigurationElement(it, configuredPlatform) } ?: emptyList()
|
||||
val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform)
|
||||
val executionArguments = mavenPlugin.executions?.filter { it.goals.any { it in compilationGoals } }
|
||||
?.firstOrNull()
|
||||
?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it, configuredPlatform) }
|
||||
?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(mavenProject, it, configuredPlatform) }
|
||||
parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet)
|
||||
if (executionArguments != null) {
|
||||
parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet)
|
||||
|
||||
@@ -457,6 +457,63 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testJvmFacetConfigurationFromProperties() {
|
||||
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>
|
||||
|
||||
<properties>
|
||||
<kotlin.compiler.languageVersion>1.0</kotlin.compiler.languageVersion>
|
||||
<kotlin.compiler.apiVersion>1.0</kotlin.compiler.apiVersion>
|
||||
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
|
||||
</properties>
|
||||
|
||||
<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>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""")
|
||||
|
||||
assertModules("project")
|
||||
assertImporterStatePresent()
|
||||
|
||||
with (facetSettings) {
|
||||
Assert.assertEquals("1.0", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.0", compilerArguments!!.languageVersion)
|
||||
Assert.assertEquals("1.0", apiLevel!!.versionString)
|
||||
Assert.assertEquals("1.0", compilerArguments!!.apiVersion)
|
||||
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
|
||||
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
|
||||
}
|
||||
}
|
||||
|
||||
fun testJsFacetConfiguration() {
|
||||
createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user