Skip to content
This repository was archived by the owner on Oct 3, 2021. It is now read-only.

Commit a510838

Browse files
author
Krystian Panek
committedAug 27, 2020
OSGi classloader not working
1 parent 1edb73f commit a510838

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed
 

‎src/main/kotlin/com/neva/slinkt/script/engine/KotlinEngine.kt

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class KotlinEngine(
5454

5555
private fun makeCompilerConfiguration() = CompilerConfiguration().apply {
5656
addJvmSdkRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
57-
classLoader
5857
addJvmClasspathRoots(templateClasspath)
5958
put(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, System.getProperty("user.dir")) //TODO tmp
6059
add(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS, ScriptingCompilerConfigurationComponentRegistrar())

‎src/main/kotlin/com/neva/slinkt/script/host/KotlinScriptEvaluator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class KotlinScriptEvaluator {
3131
wholeClasspath = true,
3232
classLoader = classLoader
3333
)
34-
compilerOptions.append("-Xintellij-plugin-root", System.getProperty("user.dir"))
34+
compilerOptions.append("-Xintellij-plugin-root=${System.getProperty("user.dir")}")
3535
}
3636
compilationOptions()
3737
}

‎src/main/kotlin/com/neva/slinkt/script/host/KotlinScriptServlet.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ import kotlin.script.experimental.host.StringScriptSource
1818
ServletResolverConstants.SLING_SERVLET_METHODS + "=GET",
1919
]
2020
)
21-
class SimpleServlet : SlingSafeMethodsServlet() {
21+
class KotlinScriptServlet : SlingSafeMethodsServlet() {
2222

2323
@Reference
2424
private lateinit var evaluator: KotlinScriptEvaluator
2525

2626
override fun doGet(request: SlingHttpServletRequest, response: SlingHttpServletResponse) {
2727
val scriptSource = StringScriptSource("""
28-
println("Hello World!")
29-
"abecadlo!"
28+
import org.osgi.framework.FrameworkUtil
29+
FrameworkUtil.getBundle(com.neva.slinkt.script.host.KotlinScriptServlet).symbolicName
3030
""".trimIndent())
3131

3232
val result = evaluator.eval(scriptSource)
3333

3434
response.contentType = "text/plain"
35-
response.writer.write(result.valueOrNull().toString())
35+
response.writer.apply {
36+
write("${result.valueOrNull().toString()}\n")
37+
result.reports.forEach { write("$it\n") }
38+
}
3639
}
3740
}

0 commit comments

Comments
 (0)