diff --git a/idea/idea-maven/idea-maven.iml b/idea/idea-maven/idea-maven.iml index 479158b82d5..d272a4c3d2e 100644 --- a/idea/idea-maven/idea-maven.iml +++ b/idea/idea-maven/idea-maven.iml @@ -9,7 +9,7 @@ - + @@ -22,5 +22,7 @@ + + - + \ No newline at end of file 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 7ee5b265c60..09be0b9d72e 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 @@ -112,20 +112,22 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ PomFile.KotlinGoals.MetaData) private fun configureFacet(mavenProject: MavenProject, modifiableModelsProvider: IdeModifiableModelsProvider, module: Module) { - val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID) - val compilerVersion = mavenPlugin?.version ?: return + val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID) ?: return + val compilerVersion = mavenPlugin.version ?: LanguageVersion.LATEST.versionString val kotlinFacet = module.getOrCreateFacet(modifiableModelsProvider, false) val platform = detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject) kotlinFacet.configureFacet(compilerVersion, CoroutineSupport.DEFAULT, platform, modifiableModelsProvider) - val apiVersion = mavenPlugin.configurationElement?.getChild("apiVersion")?.text?.let { LanguageVersion.fromFullVersionString(it) } - val sharedArguments = mavenPlugin.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it) } ?: emptyList() + val configuration = mavenPlugin.configurationElement + val apiVersion = configuration?.getChild("apiVersion")?.text?.let { LanguageVersion.fromFullVersionString(it) } + val sharedArguments = configuration?.let { getCompilerArgumentsByConfigurationElement(it) } ?: emptyList() val executionArguments = mavenPlugin.executions?.filter { it.goals.any { it in compilationGoals } } ?.firstOrNull() ?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it) } ?: emptyList() with(kotlinFacet.configuration.settings) { versionInfo.apiLevel = apiVersion + compilerInfo.k2jvmCompilerArguments?.jvmTarget = configuration?.getChild("jvmTarget")?.text } parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet) parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet) 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 ddd71f51460..609b55732af 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 @@ -16,6 +16,9 @@ package org.jetbrains.kotlin.idea.maven +import org.jetbrains.kotlin.config.KotlinFacetSettings +import org.jetbrains.kotlin.idea.facet.KotlinFacet +import org.junit.Assert import java.io.File class KotlinMavenImporterTest : MavenImportingTestCase() { @@ -384,7 +387,115 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm") } + fun testJvmTarget() { + 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.8 + + + + + """) + + assertModules("project") + assertImporterStatePresent() + + with (facetSettings) { + Assert.assertEquals("JVM 1.8", versionInfo.targetPlatformKind!!.description) + Assert.assertEquals("1.8", compilerInfo.k2jvmCompilerArguments!!.jvmTarget) + } + } + + fun testArgsInFacet() { + 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 + + + + + + -jvm-target + 1.8 + -Xcoroutines=enable + + + + + + """) + + assertModules("project") + assertImporterStatePresent() + + with (facetSettings) { + Assert.assertEquals("JVM 1.8", versionInfo.targetPlatformKind!!.description) + Assert.assertEquals("1.8", compilerInfo.k2jvmCompilerArguments!!.jvmTarget) + Assert.assertEquals("enable", compilerInfo.coroutineSupport.compilerArgument) + } + } + private fun assertImporterStatePresent() { assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java)) } + + private val facetSettings: KotlinFacetSettings + get() = KotlinFacet.get(getModule("project"))!!.configuration.settings } \ No newline at end of file