Proper handling of the scripting compiler plugin in JSR-223 with daemon
This commit is contained in:
@@ -67,6 +67,9 @@ messages/**)
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreter
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreterFactory
|
||||
|
||||
# The appropriate jar is either loaded separately or added explicitly to the classpath then needed
|
||||
-dontwarn org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
|
||||
|
||||
-dontwarn org.jdom.xpath.jaxen.*
|
||||
-dontwarn com.intellij.util.io.Decompressor*
|
||||
-dontwarn org.w3c.dom.Location
|
||||
|
||||
@@ -58,6 +58,9 @@ messages/**)
|
||||
# Depends on apache batik which has lots of dependencies
|
||||
-dontwarn com.intellij.util.SVGLoader*
|
||||
|
||||
# The appropriate jar is either loaded separately or added explicitly to the classpath then needed
|
||||
-dontwarn org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
|
||||
|
||||
#-libraryjars '<rtjar>'
|
||||
#-libraryjars '<jssejar>'
|
||||
#-libraryjars '<bootstrap.runtime>'
|
||||
|
||||
@@ -68,6 +68,9 @@ messages/**)
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreter
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreterFactory
|
||||
|
||||
# The appropriate jar is either loaded separately or added explicitly to the classpath then needed
|
||||
-dontwarn org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
|
||||
|
||||
-dontwarn org.jdom.xpath.jaxen.*
|
||||
-dontwarn com.intellij.util.io.Decompressor*
|
||||
-dontwarn org.w3c.dom.Location
|
||||
|
||||
@@ -59,6 +59,9 @@ messages/**)
|
||||
# Depends on apache batick which has lots of dependencies
|
||||
-dontwarn com.intellij.util.SVGLoader*
|
||||
|
||||
# The appropriate jar is either loaded separately or added explicitly to the classpath then needed
|
||||
-dontwarn org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
|
||||
|
||||
#-libraryjars '<rtjar>'
|
||||
#-libraryjars '<jssejar>'
|
||||
#-libraryjars '<bootstrap.runtime>'
|
||||
|
||||
@@ -68,6 +68,9 @@ messages/**)
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreter
|
||||
-dontwarn org.apache.batik.script.rhino.RhinoInterpreterFactory
|
||||
|
||||
# The appropriate jar is either loaded separately or added explicitly to the classpath then needed
|
||||
-dontwarn org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
|
||||
|
||||
-dontwarn org.jdom.xpath.jaxen.*
|
||||
-dontwarn com.intellij.util.io.Decompressor*
|
||||
-dontwarn org.w3c.dom.Location
|
||||
|
||||
@@ -17,6 +17,7 @@ dependencies {
|
||||
testCompile(project(":kotlin-test:kotlin-test-junit"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
compilerClasspath(projectRuntimeJar(":kotlin-compiler-embeddable"))
|
||||
compilerClasspath(projectRuntimeJar(":kotlin-scripting-compiler-embeddable"))
|
||||
compilerClasspath(project(":kotlin-reflect"))
|
||||
compilerClasspath(kotlinStdlib())
|
||||
compilerClasspath(project(":kotlin-script-runtime"))
|
||||
|
||||
@@ -17,6 +17,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common")) // TODO: fix import (workaround for jps build)
|
||||
testCompileOnly(project(":core:util.runtime")) // TODO: fix import (workaround for jps build)
|
||||
testCompileOnly(project(":compiler:daemon-common")) // TODO: fix import (workaround for jps build)
|
||||
testRuntime(projectRuntimeJar(":kotlin-scripting-compiler-embeddable"))
|
||||
}
|
||||
|
||||
projectTest()
|
||||
|
||||
+33
-11
@@ -22,6 +22,10 @@ internal const val KOTLIN_JAVA_STDLIB_JAR = "kotlin-stdlib.jar"
|
||||
internal const val KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar"
|
||||
internal const val KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar"
|
||||
internal const val TROVE4J_JAR = "trove4j.jar"
|
||||
internal const val KOTLIN_SCRIPTING_COMPILER_JAR = "kotlin-scripting-compiler.jar"
|
||||
internal const val KOTLIN_SCRIPTING_COMPILER_EMBEDDABLE_JAR = "kotlin-scripting-compiler-embeddable.jar"
|
||||
internal const val KOTLIN_SCRIPTING_COMMON_JAR = "kotlin-scripting-common.jar"
|
||||
internal const val KOTLIN_SCRIPTING_JVM_JAR = "kotlin-scripting-jvm.jar"
|
||||
|
||||
internal const val KOTLIN_COMPILER_NAME = "kotlin-compiler"
|
||||
internal const val KOTLIN_COMPILER_JAR = "$KOTLIN_COMPILER_NAME.jar"
|
||||
@@ -158,6 +162,14 @@ object KotlinJars {
|
||||
}
|
||||
|
||||
val compilerClasspath: List<File> by lazy {
|
||||
findCompilerClasspath(withScripting = false)
|
||||
}
|
||||
|
||||
val compilerWithScriptingClasspath: List<File> by lazy {
|
||||
findCompilerClasspath(withScripting = true)
|
||||
}
|
||||
|
||||
private fun findCompilerClasspath(withScripting: Boolean): List<File> {
|
||||
val kotlinCompilerJars = listOf(
|
||||
KOTLIN_COMPILER_JAR,
|
||||
KOTLIN_COMPILER_EMBEDDABLE_JAR
|
||||
@@ -168,22 +180,32 @@ object KotlinJars {
|
||||
KOTLIN_JAVA_SCRIPT_RUNTIME_JAR,
|
||||
TROVE4J_JAR
|
||||
)
|
||||
val kotlinBaseJars = kotlinCompilerJars + kotlinLibsJars
|
||||
val kotlinScriptingJars = if (withScripting) listOf(
|
||||
KOTLIN_SCRIPTING_COMPILER_JAR,
|
||||
KOTLIN_SCRIPTING_COMPILER_EMBEDDABLE_JAR,
|
||||
KOTLIN_SCRIPTING_COMMON_JAR,
|
||||
KOTLIN_SCRIPTING_JVM_JAR
|
||||
) else emptyList()
|
||||
|
||||
val kotlinBaseJars = kotlinCompilerJars + kotlinLibsJars + kotlinScriptingJars
|
||||
|
||||
val classpath = explicitCompilerClasspath
|
||||
// search classpath from context classloader and `java.class.path` property
|
||||
?: (classpathFromFQN(
|
||||
Thread.currentThread().contextClassLoader,
|
||||
"org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
|
||||
)
|
||||
?: classpathFromClassloader(Thread.currentThread().contextClassLoader)?.takeIf { it.isNotEmpty() }
|
||||
?: classpathFromClasspathProperty()
|
||||
)?.filter { f -> kotlinBaseJars.any { f.matchMaybeVersionedFile(it) } }?.takeIf { it.isNotEmpty() }
|
||||
// search classpath from context classloader and `java.class.path` property
|
||||
?: (classpathFromFQN( Thread.currentThread().contextClassLoader, "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" )
|
||||
?: classpathFromClassloader(Thread.currentThread().contextClassLoader)?.takeIf { it.isNotEmpty() }
|
||||
?: classpathFromClasspathProperty()
|
||||
)?.filter { f -> kotlinBaseJars.any { f.matchMaybeVersionedFile(it) } }?.takeIf { it.isNotEmpty() }
|
||||
// if autodetected, additionally check for presence of the compiler jars
|
||||
if (classpath == null || (explicitCompilerClasspath == null && classpath.none { f -> kotlinCompilerJars.any { f.matchMaybeVersionedFile(it) } })) {
|
||||
if (classpath == null || (explicitCompilerClasspath == null && classpath.none { f ->
|
||||
kotlinCompilerJars.any {
|
||||
f.matchMaybeVersionedFile(
|
||||
it
|
||||
)
|
||||
}
|
||||
})) {
|
||||
throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.classpath property to proper location")
|
||||
}
|
||||
classpath!!
|
||||
return classpath!!
|
||||
}
|
||||
|
||||
fun getLib(propertyName: String, jarName: String, markerClass: KClass<*>, classLoader: ClassLoader? = null): File? =
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class KotlinJsr223JvmDaemonLocalEvalScriptEngineFactory : KotlinJsr223JvmScriptE
|
||||
override fun getScriptEngine(): ScriptEngine =
|
||||
KotlinJsr223JvmDaemonCompileScriptEngine(
|
||||
this,
|
||||
KotlinJars.compilerClasspath,
|
||||
KotlinJars.compilerWithScriptingClasspath,
|
||||
scriptCompilationClasspathFromContextOrStlib("kotlin-script-util.jar", wholeClasspath = true),
|
||||
KotlinStandardJsr223ScriptTemplate::class.qualifiedName!!,
|
||||
{ ctx, types -> ScriptArgsWithTypes(arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)), types ?: emptyArray()) },
|
||||
|
||||
Reference in New Issue
Block a user