Add a property for resolving via classloader in JSR-223
This commit is contained in:
+14
-2
@@ -12,8 +12,9 @@ import javax.script.Bindings
|
||||
import javax.script.ScriptContext
|
||||
import javax.script.ScriptEngine
|
||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||
import kotlin.script.experimental.api.dependencies
|
||||
import kotlin.script.experimental.jvm.JvmDependencyFromClassLoader
|
||||
import kotlin.script.experimental.jvm.JvmScriptCompilationConfigurationBuilder
|
||||
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
||||
import kotlin.script.experimental.jvm.jvm
|
||||
import kotlin.script.experimental.jvm.updateClasspath
|
||||
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext
|
||||
@@ -21,6 +22,13 @@ import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromT
|
||||
import kotlin.script.experimental.jvmhost.createJvmEvaluationConfigurationFromTemplate
|
||||
import kotlin.script.experimental.jvmhost.jsr223.KotlinJsr223ScriptEngineImpl
|
||||
|
||||
/**
|
||||
* If the property is set to true, the dependencies will be resolved directly from the context classloader
|
||||
* (Thread.currentThread().contextClassLoader) using reflection and other techniques (experimental!).
|
||||
* Otherwise the same classloader will be used to extract the classpath first, and this classpath will be used instead.
|
||||
*/
|
||||
const val KOTLIN_JSR223_RESOLVE_FROM_CLASSLOADER_PROPERTY = "kotlin.jsr223.experimental.resolve.dependencies.from.context.classloader"
|
||||
|
||||
class KotlinJsr223DefaultScriptEngineFactory : KotlinJsr223JvmScriptEngineFactoryBase() {
|
||||
|
||||
private val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<KotlinJsr223DefaultScript>()
|
||||
@@ -49,7 +57,11 @@ class KotlinJsr223DefaultScriptEngineFactory : KotlinJsr223JvmScriptEngineFactor
|
||||
this,
|
||||
ScriptCompilationConfiguration(compilationConfiguration) {
|
||||
jvm {
|
||||
dependenciesFromCurrentContext()
|
||||
if (System.getProperty(KOTLIN_JSR223_RESOLVE_FROM_CLASSLOADER_PROPERTY) == "true") {
|
||||
dependencies(JvmDependencyFromClassLoader { Thread.currentThread().contextClassLoader })
|
||||
} else {
|
||||
dependenciesFromCurrentContext()
|
||||
}
|
||||
}
|
||||
},
|
||||
evaluationConfiguration
|
||||
|
||||
Reference in New Issue
Block a user