@@ -17,27 +17,26 @@ class ScriptExecutor {
17
17
private var evalException: Exception ? = null
18
18
19
19
fun executeScript (): ResultWithDiagnostics <EvaluationResult >? {
20
- val classLoader = CustomClassLoader (Thread .currentThread().contextClassLoader)
20
+ // val classLoader = CustomClassLoader(Thread.currentThread().contextClassLoader)
21
21
22
- val scriptingHost = CustomScriptingHost (classLoader)
22
+ val scriptingHost = CustomScriptingHost () // ( classLoader)
23
23
val compilationConfig = ScriptCompilationConfiguration {
24
24
jvm {
25
- dependenciesFromClassloader(classLoader = classLoader, wholeClasspath = true )
26
- // dependencies(JvmDependency(dependencies))
27
- // dependenciesFromClassloader(classLoader = classLoader, wholeClasspath = true)
25
+ // dependenciesFromClassloader(classLoader = classLoader, wholeClasspath = true)
26
+ dependenciesFromClassloader(wholeClasspath = true )
28
27
}
29
28
providedProperties(" context" to KotlinScriptContext ::class )
30
29
compilerOptions.append(" -nowarn" )
31
30
}
32
31
val context = KotlinScriptContext ()
33
32
context.setProperty(" testVariable" , Constants .TEST_VAR )
34
33
val evaluationConfiguration = ScriptEvaluationConfiguration {
35
- jvm {
36
- baseClassLoader(classLoader)
37
- }
34
+ /* jvm {
35
+ baseClassLoader(classLoader) // Without effect. ClassLoader will be overwritten by the UrlClassLoader.
36
+ }*/
38
37
providedProperties(" context" to context)
39
38
}
40
- val scriptSource = script .toScriptSource()
39
+ val scriptSource = Constants . CHECK_SCRIPT .toScriptSource()
41
40
val executor = Executors .newSingleThreadExecutor()
42
41
var future: Future <ResultWithDiagnostics <EvaluationResult >>? = null
43
42
try {
@@ -59,36 +58,4 @@ class ScriptExecutor {
59
58
}
60
59
return null
61
60
}
62
-
63
- companion object {
64
- val simplestScript = " \" Hello world!\" "
65
- val script = """
66
- import de.micromata.kotlinscripting.business.ThreadLocalStorage
67
- val sb = StringBuilder()
68
- sb.appendLine("Hello world!")
69
- val threadLocalVal = ThreadLocalStorage.threadLocal.get()
70
- if (threadLocalVal == "${Constants .THREADLOCAL_TEST } ") {
71
- sb.appendLine("ThreadLocal: ${' $' } threadLocalVal (OK)")
72
- } else {
73
- sb.appendLine("ThreadLocal: ${' $' } threadLocalVal (*** ERROR, ${Constants .THREADLOCAL_TEST } expected)")
74
- }
75
- val testVar = context.getProperty("testVariable")
76
- if (testVar == "${Constants .TEST_VAR } ") {
77
- sb.appendLine("Context: ${' $' } testVar (OK)")
78
- } else {
79
- sb.appendLine("Context: ${' $' } testVar (*** ERROR, ${Constants .TEST_VAR } expected)")
80
- }
81
- var loader = Thread.currentThread().contextClassLoader
82
- val classLoaders = mutableListOf<ClassLoader>()
83
- while (loader != null) {
84
- classLoaders.add(loader)
85
- loader = loader.parent
86
- }
87
- sb.append("ClassLoader: ")
88
- sb.appendLine("${' $' } {classLoaders.joinToString(", parent: ") { it.toString() }}")
89
- sb.appendLine("Classpath: ${' $' } {System.getProperty("java.class.path")}")
90
- //sb.appendLine(de.micromata.springbootkotlinscripting.ScriptExecutor.script)
91
- sb.toString()
92
- """ .trimIndent()
93
- }
94
61
}
0 commit comments