Report error on non-existent classpath in -Xplugin

#KT-52380 Fixed
This commit is contained in:
Alexander Udalov
2022-05-25 00:52:37 +02:00
parent c45a3d39b1
commit 70121f0c78
6 changed files with 25 additions and 7 deletions
@@ -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<A : CommonCompilerArguments> : CLITool<A>() {
protected abstract fun MutableList<String>.addPlatformOptions(arguments: A)
protected fun loadPlugins(paths: KotlinPaths?, arguments: A, configuration: CompilerConfiguration): ExitCode {
var pluginClasspaths: Iterable<String> = 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<A : CommonCompilerArguments> : CLITool<A>() {
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)"
@@ -1,5 +1,5 @@
-Xplugin
non-existing-file.jar
-Xjsr305
strict
$TESTDATA_DIR$/simple.kt
-d
$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
@@ -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");
}
@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");