Treat classpath extraction problems on script definition loading as warnings

#KT-44206 fixed
This commit is contained in:
Ilya Chernikov
2020-09-30 13:20:11 +02:00
parent 741df42c18
commit adcfca3f98
2 changed files with 11 additions and 2 deletions
@@ -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()
}
@@ -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<File>? {
val processedJars = hashSetOf<File>()
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 {