Scripting: implement support for user-defined execution wrapper

This commit is contained in:
Ilya Chernikov
2022-05-13 17:16:43 +02:00
committed by teamcity
parent abdc2cf85e
commit 6784cb63aa
3 changed files with 52 additions and 2 deletions
@@ -94,10 +94,18 @@ open class BasicJvmScriptEvaluator : ScriptEvaluator {
val ctor = java.constructors.single()
@Suppress("UNCHECKED_CAST")
val wrapper: ScriptExecutionWrapper<Any>? =
refinedEvalConfiguration[ScriptEvaluationConfiguration.scriptExecutionWrapper] as ScriptExecutionWrapper<Any>?
val saveClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = this.java.classLoader
return try {
ctor.newInstance(*args.toArray())
if (wrapper == null) {
ctor.newInstance(*args.toArray())
} else wrapper.invoke {
ctor.newInstance(*args.toArray())
}
} finally {
Thread.currentThread().contextClassLoader = saveClassLoader
}