CLI: refactor argument validation out of parsing
This commit is contained in:
@@ -36,7 +36,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.parseArguments
|
||||
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
|
||||
@@ -139,7 +139,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
|
||||
}
|
||||
|
||||
val additionalArgs = configuration.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList()
|
||||
parseArguments(additionalArgs.toTypedArray(), arguments, true)
|
||||
parseCommandLineArguments(additionalArgs.toTypedArray(), arguments)
|
||||
|
||||
return ArgumentUtils.convertArgumentsToStringList(arguments)
|
||||
}
|
||||
@@ -269,4 +269,4 @@ class KotlinImporterComponent : PersistentStateComponent<KotlinImporterComponent
|
||||
}
|
||||
|
||||
private val Module.kotlinImporterComponent: KotlinImporterComponent
|
||||
get() = getComponent(KotlinImporterComponent::class.java) ?: throw IllegalStateException("No maven importer state configured")
|
||||
get() = getComponent(KotlinImporterComponent::class.java) ?: throw IllegalStateException("No maven importer state configured")
|
||||
|
||||
@@ -177,12 +177,10 @@ class KotlinFacetEditorGeneralTab(
|
||||
}
|
||||
val argumentClass = primaryArguments.javaClass
|
||||
val additionalArguments = argumentClass.newInstance().apply {
|
||||
try {
|
||||
parseArguments(splitArgumentString(editor.compilerConfigurable.additionalArgsOptionsField.text).toTypedArray(), this)
|
||||
}
|
||||
catch(e: IllegalArgumentException) {
|
||||
return ValidationResult(e.message)
|
||||
}
|
||||
parseCommandLineArguments(
|
||||
splitArgumentString(editor.compilerConfigurable.additionalArgsOptionsField.text).toTypedArray(), this
|
||||
)
|
||||
validateArguments(errors)?.let { message -> return ValidationResult(message) }
|
||||
}
|
||||
val emptyArguments = argumentClass.newInstance()
|
||||
val fieldNamesToCheck = when (platform) {
|
||||
|
||||
@@ -175,10 +175,10 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
|
||||
val compilerArguments = this.compilerArguments ?: return
|
||||
|
||||
val defaultCompilerArguments = compilerArguments::class.java.newInstance()
|
||||
parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true)
|
||||
parseCommandLineArguments(defaultArguments.toTypedArray(), defaultCompilerArguments)
|
||||
defaultCompilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
parseArguments(argumentArray, compilerArguments, true)
|
||||
parseCommandLineArguments(argumentArray, compilerArguments)
|
||||
|
||||
compilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user