Maven Import: Support compiler arguments specified directly in <args>
#KT-21592 Fixed
This commit is contained in:
@@ -28,6 +28,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.util.AsyncResult
|
||||
import org.jdom.Element
|
||||
import org.jdom.Text
|
||||
import org.jetbrains.idea.maven.importing.MavenImporter
|
||||
import org.jetbrains.idea.maven.importing.MavenRootModelAdapter
|
||||
import org.jetbrains.idea.maven.model.MavenPlugin
|
||||
@@ -39,15 +40,14 @@ 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.framework.detectLibraryKind
|
||||
import org.jetbrains.kotlin.idea.framework.libraryKind
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
@@ -160,7 +160,23 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
||||
}
|
||||
}
|
||||
|
||||
val additionalArgs = configuration?.getChild("args")?.getChildren("arg")?.mapNotNull { it.text }.orEmpty()
|
||||
val additionalArgs = SmartList<String>().apply {
|
||||
val argsElement = configuration?.getChild("args")
|
||||
|
||||
argsElement?.content?.forEach { argElement ->
|
||||
when (argElement) {
|
||||
is Text -> {
|
||||
argElement.text?.let { addAll(splitArgumentString(it)) }
|
||||
}
|
||||
is Element -> {
|
||||
if (argElement.name == "arg") {
|
||||
addIfNotNull(argElement.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argsElement?.getChildren("arg")?.mapNotNullTo(this) { it.text }
|
||||
}
|
||||
parseCommandLineArguments(additionalArgs, arguments)
|
||||
|
||||
return ArgumentUtils.convertArgumentsToStringList(arguments)
|
||||
|
||||
@@ -728,6 +728,60 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testArgsInFacetInSingleElement() {
|
||||
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>
|
||||
-jvm-target 1.8 -Xcoroutines=enable -classpath "c:\program files\jdk1.8"
|
||||
</args>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""")
|
||||
|
||||
assertModules("project")
|
||||
assertImporterStatePresent()
|
||||
|
||||
with (facetSettings) {
|
||||
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
|
||||
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
|
||||
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
|
||||
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
|
||||
}
|
||||
}
|
||||
|
||||
fun testJvmDetectionByGoalWithJvmStdlib() {
|
||||
createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user