Kotlin Facet: Import Maven option specified in <jvmTarget> element
#KT-16329 In Progress
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="idea-full" level="project" />
|
<orderEntry type="library" name="cli-parser" level="project" />
|
||||||
<orderEntry type="module" module-name="idea" />
|
<orderEntry type="module" module-name="idea" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="maven" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="maven" level="project" />
|
||||||
<orderEntry type="module" module-name="frontend" />
|
<orderEntry type="module" module-name="frontend" />
|
||||||
@@ -22,5 +22,7 @@
|
|||||||
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
||||||
<orderEntry type="module" module-name="idea-jps-common" />
|
<orderEntry type="module" module-name="idea-jps-common" />
|
||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
|
<orderEntry type="module" module-name="cli-common" />
|
||||||
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -112,20 +112,22 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
|||||||
PomFile.KotlinGoals.MetaData)
|
PomFile.KotlinGoals.MetaData)
|
||||||
|
|
||||||
private fun configureFacet(mavenProject: MavenProject, modifiableModelsProvider: IdeModifiableModelsProvider, module: Module) {
|
private fun configureFacet(mavenProject: MavenProject, modifiableModelsProvider: IdeModifiableModelsProvider, module: Module) {
|
||||||
val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)
|
val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID) ?: return
|
||||||
val compilerVersion = mavenPlugin?.version ?: return
|
val compilerVersion = mavenPlugin.version ?: LanguageVersion.LATEST.versionString
|
||||||
val kotlinFacet = module.getOrCreateFacet(modifiableModelsProvider, false)
|
val kotlinFacet = module.getOrCreateFacet(modifiableModelsProvider, false)
|
||||||
val platform = detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
|
val platform = detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
|
||||||
|
|
||||||
kotlinFacet.configureFacet(compilerVersion, CoroutineSupport.DEFAULT, platform, modifiableModelsProvider)
|
kotlinFacet.configureFacet(compilerVersion, CoroutineSupport.DEFAULT, platform, modifiableModelsProvider)
|
||||||
val apiVersion = mavenPlugin.configurationElement?.getChild("apiVersion")?.text?.let { LanguageVersion.fromFullVersionString(it) }
|
val configuration = mavenPlugin.configurationElement
|
||||||
val sharedArguments = mavenPlugin.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it) } ?: emptyList()
|
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 } }
|
val executionArguments = mavenPlugin.executions?.filter { it.goals.any { it in compilationGoals } }
|
||||||
?.firstOrNull()
|
?.firstOrNull()
|
||||||
?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it) }
|
?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(it) }
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
with(kotlinFacet.configuration.settings) {
|
with(kotlinFacet.configuration.settings) {
|
||||||
versionInfo.apiLevel = apiVersion
|
versionInfo.apiLevel = apiVersion
|
||||||
|
compilerInfo.k2jvmCompilerArguments?.jvmTarget = configuration?.getChild("jvmTarget")?.text
|
||||||
}
|
}
|
||||||
parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet)
|
parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet)
|
||||||
parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet)
|
parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet)
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.maven
|
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
|
import java.io.File
|
||||||
|
|
||||||
class KotlinMavenImporterTest : MavenImportingTestCase() {
|
class KotlinMavenImporterTest : MavenImportingTestCase() {
|
||||||
@@ -384,7 +387,115 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
|
|||||||
assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm")
|
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("""
|
||||||
|
<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.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
""")
|
||||||
|
|
||||||
|
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("""
|
||||||
|
<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>
|
||||||
|
<args>
|
||||||
|
<arg>-jvm-target</arg>
|
||||||
|
<arg>1.8</arg>
|
||||||
|
<arg>-Xcoroutines=enable</arg>
|
||||||
|
</args>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
""")
|
||||||
|
|
||||||
|
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() {
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val facetSettings: KotlinFacetSettings
|
||||||
|
get() = KotlinFacet.get(getModule("project"))!!.configuration.settings
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user