Treat classpath extraction problems on script definition loading as warnings
#KT-44206 fixed
This commit is contained in:
+8
-1
@@ -56,6 +56,7 @@ import kotlin.script.experimental.host.configurationDependencies
|
|||||||
import kotlin.script.experimental.host.toScriptSource
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
import kotlin.script.experimental.jvm.JvmDependency
|
import kotlin.script.experimental.jvm.JvmDependency
|
||||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||||
|
import kotlin.script.experimental.jvm.util.ClasspathExtractionException
|
||||||
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrStdlib
|
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrStdlib
|
||||||
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||||
|
|
||||||
@@ -252,8 +253,14 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
|
|||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
if (t is ControlFlowException) throw t
|
if (t is ControlFlowException) throw t
|
||||||
// reporting failed loading only once
|
// reporting failed loading only once
|
||||||
scriptingErrorLog("[kts] cannot load script definitions using $this", t)
|
|
||||||
failedContributorsHashes.add(this@safeGetDefinitions.hashCode())
|
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()
|
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 validClasspathFilesExtensions = setOf("jar", "zip", "java")
|
||||||
private val validJarCollectionFilesExtensions = setOf("jar", "war", "zip")
|
private val validJarCollectionFilesExtensions = setOf("jar", "war", "zip")
|
||||||
|
|
||||||
|
class ClasspathExtractionException(message: String) : Exception(message)
|
||||||
|
|
||||||
fun classpathFromClassloader(currentClassLoader: ClassLoader, unpackJarCollections: Boolean = false): List<File>? {
|
fun classpathFromClassloader(currentClassLoader: ClassLoader, unpackJarCollections: Boolean = false): List<File>? {
|
||||||
val processedJars = hashSetOf<File>()
|
val processedJars = hashSetOf<File>()
|
||||||
val unpackJarCollectionsDir by lazy {
|
val unpackJarCollectionsDir by lazy {
|
||||||
@@ -299,7 +301,7 @@ fun scriptCompilationClasspathFromContext(
|
|||||||
wholeClasspath = wholeClasspath,
|
wholeClasspath = wholeClasspath,
|
||||||
unpackJarCollections = unpackJarCollections
|
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 {
|
object KotlinJars {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user