Report error on non-existent classpath in -Xplugin
#KT-52380 Fixed
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode.*
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
|
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
|
||||||
import org.jetbrains.kotlin.cli.common.messages.*
|
import org.jetbrains.kotlin.cli.common.messages.*
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
||||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||||
@@ -161,8 +162,15 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
|||||||
protected abstract fun MutableList<String>.addPlatformOptions(arguments: A)
|
protected abstract fun MutableList<String>.addPlatformOptions(arguments: A)
|
||||||
|
|
||||||
protected fun loadPlugins(paths: KotlinPaths?, arguments: A, configuration: CompilerConfiguration): ExitCode {
|
protected fun loadPlugins(paths: KotlinPaths?, arguments: A, configuration: CompilerConfiguration): ExitCode {
|
||||||
var pluginClasspaths: Iterable<String> = arguments.pluginClasspaths?.asIterable() ?: emptyList()
|
val pluginClasspaths = arguments.pluginClasspaths.orEmpty().toMutableList()
|
||||||
val pluginOptions = arguments.pluginOptions?.toMutableList() ?: ArrayList()
|
val pluginOptions = arguments.pluginOptions.orEmpty().toMutableList()
|
||||||
|
val messageCollector = configuration.getNotNull(MESSAGE_COLLECTOR_KEY)
|
||||||
|
|
||||||
|
for (classpath in pluginClasspaths) {
|
||||||
|
if (!File(classpath).exists()) {
|
||||||
|
messageCollector.report(ERROR, "Plugin classpath entry points to a non-existent location: $classpath")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!arguments.disableDefaultScriptingPlugin) {
|
if (!arguments.disableDefaultScriptingPlugin) {
|
||||||
val explicitOrLoadedScriptingPlugin =
|
val explicitOrLoadedScriptingPlugin =
|
||||||
@@ -174,9 +182,8 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
|||||||
val (jars, missingJars) =
|
val (jars, missingJars) =
|
||||||
PathUtil.KOTLIN_SCRIPTING_PLUGIN_CLASSPATH_JARS.map { File(libPath, it) }.partition { it.exists() }
|
PathUtil.KOTLIN_SCRIPTING_PLUGIN_CLASSPATH_JARS.map { File(libPath, it) }.partition { it.exists() }
|
||||||
if (missingJars.isEmpty()) {
|
if (missingJars.isEmpty()) {
|
||||||
pluginClasspaths = jars.map { it.canonicalPath } + pluginClasspaths
|
pluginClasspaths.addAll(0, jars.map { it.canonicalPath })
|
||||||
} else {
|
} else {
|
||||||
val messageCollector = configuration.getNotNull(MESSAGE_COLLECTOR_KEY)
|
|
||||||
messageCollector.report(
|
messageCollector.report(
|
||||||
CompilerMessageSeverity.LOGGING,
|
CompilerMessageSeverity.LOGGING,
|
||||||
"Scripting plugin will not be loaded: not all required jars are present in the classpath (missing files: $missingJars)"
|
"Scripting plugin will not be loaded: not all required jars are present in the classpath (missing files: $missingJars)"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-Xplugin
|
-Xjsr305
|
||||||
non-existing-file.jar
|
strict
|
||||||
$TESTDATA_DIR$/simple.kt
|
$TESTDATA_DIR$/simple.kt
|
||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
warning: advanced option value is passed in an obsolete form. Please use the '=' character to specify the value: -Xplugin=...
|
warning: advanced option value is passed in an obsolete form. Please use the '=' character to specify the value: -Xjsr305=...
|
||||||
OK
|
OK
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-Xplugin=/non-existing-path
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
error: plugin classpath entry points to a non-existent location: /non-existing-path
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -784,6 +784,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/nonExistingPhaseName.args");
|
runTest("compiler/testData/cli/jvm/nonExistingPhaseName.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonExistingPluginClassPath.args")
|
||||||
|
public void testNonExistingPluginClassPath() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/nonExistingPluginClassPath.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonExistingSourcePath.args")
|
@TestMetadata("nonExistingSourcePath.args")
|
||||||
public void testNonExistingSourcePath() throws Exception {
|
public void testNonExistingSourcePath() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/nonExistingSourcePath.args");
|
runTest("compiler/testData/cli/jvm/nonExistingSourcePath.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user