From 89352a295d876fed15c3063e4d37ea32450c8c0d Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Mon, 4 Dec 2017 14:31:18 +0300 Subject: [PATCH] Maven Import: Support compiler arguments specified directly in #KT-21592 Fixed --- .../kotlin/idea/maven/KotlinMavenImporter.kt | 26 +++++++-- .../idea/maven/KotlinMavenImporterTest.kt | 54 +++++++++++++++++++ 2 files changed, 75 insertions(+), 5 deletions(-) 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 97f7b82b671..0c805e10e94 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 @@ -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().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) 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 74dd0c571ea..f08d7410832 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 @@ -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(""" + 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 -classpath "c:\program files\jdk1.8" + + + + + + """) + + 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")