Scripting: fix loadDependencies property use with cached scripts

#KT-50902 fixed
This commit is contained in:
Ilya Chernikov
2022-04-26 08:31:31 +02:00
committed by teamcity
parent f7fb586ee5
commit 3e19e9d190
2 changed files with 65 additions and 12 deletions
@@ -20,6 +20,7 @@ import kotlin.script.experimental.jvm.JvmDependency
import kotlin.script.experimental.jvm.baseClassLoader
import kotlin.script.experimental.jvm.impl.*
import kotlin.script.experimental.jvm.jvm
import kotlin.script.experimental.jvm.loadDependencies
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrNull
// TODO: generate execution code (main)
@@ -145,8 +146,9 @@ private class KJvmCompiledScriptLazilyLoadedFromClasspath(
if (loadedScript == null) {
val actualEvaluationConfiguration = scriptEvaluationConfiguration ?: ScriptEvaluationConfiguration()
val baseClassLoader = actualEvaluationConfiguration[ScriptEvaluationConfiguration.jvm.baseClassLoader]
val loadDependencies = actualEvaluationConfiguration[ScriptEvaluationConfiguration.jvm.loadDependencies]!!
val classLoader = URLClassLoader(
classPath.map { it.toURI().toURL() }.toTypedArray(),
classPath.let { if (loadDependencies) it else it.take(1) }.map { it.toURI().toURL() }.toTypedArray(),
baseClassLoader
)
loadedScript = createScriptFromClassLoader(scriptClassFQName, classLoader)