From adcfca3f9826f0a0a24ff60311c9b7cc674a31eb Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 30 Sep 2020 13:20:11 +0200 Subject: [PATCH] Treat classpath extraction problems on script definition loading as warnings #KT-44206 fixed --- .../kotlin/idea/core/script/ScriptDefinitionsManager.kt | 9 ++++++++- .../script/experimental/jvm/util/jvmClasspathUtil.kt | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt index 4c447d2f3df..097915a6597 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt @@ -56,6 +56,7 @@ import kotlin.script.experimental.host.configurationDependencies import kotlin.script.experimental.host.toScriptSource import kotlin.script.experimental.jvm.JvmDependency import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration +import kotlin.script.experimental.jvm.util.ClasspathExtractionException import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrStdlib import kotlin.script.templates.standard.ScriptTemplateWithArgs @@ -252,8 +253,14 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit } catch (t: Throwable) { if (t is ControlFlowException) throw t // reporting failed loading only once - scriptingErrorLog("[kts] cannot load script definitions using $this", t) failedContributorsHashes.add(this@safeGetDefinitions.hashCode()) + // Assuming that direct ClasspathExtractionException is the result of versions mismatch and missing subsystems, e.g. kotlin plugin + // so, it only results in warning, while other errors are severe misconfigurations, resulting it user-visible error + if (t.cause is ClasspathExtractionException || t is ClasspathExtractionException) { + scriptingWarnLog("Cannot load script definitions from $this: ${t.cause?.message ?: t.message}") + } else { + scriptingErrorLog("[kts] cannot load script definitions using $this", t) + } } return emptyList() } diff --git a/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt b/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt index 25c49129c84..9470beff944 100644 --- a/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt +++ b/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt @@ -54,6 +54,8 @@ internal const val KOTLIN_SCRIPT_RUNTIME_JAR_PROPERTY = "kotlin.script.runtime.j private val validClasspathFilesExtensions = setOf("jar", "zip", "java") private val validJarCollectionFilesExtensions = setOf("jar", "war", "zip") +class ClasspathExtractionException(message: String) : Exception(message) + fun classpathFromClassloader(currentClassLoader: ClassLoader, unpackJarCollections: Boolean = false): List? { val processedJars = hashSetOf() val unpackJarCollectionsDir by lazy { @@ -299,7 +301,7 @@ fun scriptCompilationClasspathFromContext( wholeClasspath = wholeClasspath, unpackJarCollections = unpackJarCollections ) - ?: throw Exception("Unable to get script compilation classpath from context, please specify explicit classpath via \"$KOTLIN_SCRIPT_CLASSPATH_PROPERTY\" property") + ?: throw ClasspathExtractionException("Unable to get script compilation classpath from context, please specify explicit classpath via \"$KOTLIN_SCRIPT_CLASSPATH_PROPERTY\" property") object KotlinJars {