From 70121f0c785532b1e888060adb2105db82ea5d0c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 25 May 2022 00:52:37 +0200 Subject: [PATCH] Report error on non-existent classpath in -Xplugin #KT-52380 Fixed --- .../jetbrains/kotlin/cli/common/CLICompiler.kt | 15 +++++++++++---- .../jvm/extraArgumentPassedInObsoleteForm.args | 4 ++-- .../cli/jvm/extraArgumentPassedInObsoleteForm.out | 2 +- .../cli/jvm/nonExistingPluginClassPath.args | 4 ++++ .../cli/jvm/nonExistingPluginClassPath.out | 2 ++ .../jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ 6 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 compiler/testData/cli/jvm/nonExistingPluginClassPath.args create mode 100644 compiler/testData/cli/jvm/nonExistingPluginClassPath.out diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt index 4b0ecdf636f..6c6c71fffe8 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt @@ -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.environment.setIdeaIoUseFallback 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.jvm.plugins.PluginCliParser import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar @@ -161,8 +162,15 @@ abstract class CLICompiler : CLITool() { protected abstract fun MutableList.addPlatformOptions(arguments: A) protected fun loadPlugins(paths: KotlinPaths?, arguments: A, configuration: CompilerConfiguration): ExitCode { - var pluginClasspaths: Iterable = arguments.pluginClasspaths?.asIterable() ?: emptyList() - val pluginOptions = arguments.pluginOptions?.toMutableList() ?: ArrayList() + val pluginClasspaths = arguments.pluginClasspaths.orEmpty().toMutableList() + 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) { val explicitOrLoadedScriptingPlugin = @@ -174,9 +182,8 @@ abstract class CLICompiler : CLITool() { val (jars, missingJars) = PathUtil.KOTLIN_SCRIPTING_PLUGIN_CLASSPATH_JARS.map { File(libPath, it) }.partition { it.exists() } if (missingJars.isEmpty()) { - pluginClasspaths = jars.map { it.canonicalPath } + pluginClasspaths + pluginClasspaths.addAll(0, jars.map { it.canonicalPath }) } else { - val messageCollector = configuration.getNotNull(MESSAGE_COLLECTOR_KEY) messageCollector.report( CompilerMessageSeverity.LOGGING, "Scripting plugin will not be loaded: not all required jars are present in the classpath (missing files: $missingJars)" diff --git a/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.args b/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.args index 00d6472ea5c..3c469755853 100644 --- a/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.args +++ b/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.args @@ -1,5 +1,5 @@ --Xplugin -non-existing-file.jar +-Xjsr305 +strict $TESTDATA_DIR$/simple.kt -d $TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.out b/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.out index 1f22a77f1c1..5c26bef242e 100644 --- a/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.out +++ b/compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.out @@ -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 diff --git a/compiler/testData/cli/jvm/nonExistingPluginClassPath.args b/compiler/testData/cli/jvm/nonExistingPluginClassPath.args new file mode 100644 index 00000000000..ae4b9838572 --- /dev/null +++ b/compiler/testData/cli/jvm/nonExistingPluginClassPath.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/simple.kt +-d +$TEMP_DIR$ +-Xplugin=/non-existing-path diff --git a/compiler/testData/cli/jvm/nonExistingPluginClassPath.out b/compiler/testData/cli/jvm/nonExistingPluginClassPath.out new file mode 100644 index 00000000000..bd2715496c5 --- /dev/null +++ b/compiler/testData/cli/jvm/nonExistingPluginClassPath.out @@ -0,0 +1,2 @@ +error: plugin classpath entry points to a non-existent location: /non-existing-path +COMPILATION_ERROR diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 46c09948989..5cb83aa19f7 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -784,6 +784,11 @@ public class CliTestGenerated extends AbstractCliTest { 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") public void testNonExistingSourcePath() throws Exception { runTest("compiler/testData/cli/jvm/nonExistingSourcePath.args");