Using stdlib instead of runtime in the JSR 223 engines

This commit is contained in:
Ilya Chernikov
2017-01-26 18:04:40 +01:00
parent b8b044c6b0
commit bd47337be2
3 changed files with 20 additions and 15 deletions
@@ -33,6 +33,7 @@ public class PathUtil {
public static final String NOARG_PLUGIN_JAR_NAME = "noarg-compiler-plugin.jar";
public static final String JS_LIB_SRC_JAR_NAME = "kotlin-stdlib-js-sources.jar";
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
public static final String KOTLIN_JAVA_STDLIB_JAR = "kotlin-stdlib.jar";
public static final String KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar";
public static final String KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar";
public static final String KOTLIN_TEST_JAR = "kotlin-test.jar";
@@ -20,8 +20,7 @@ import com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineFactoryBase
import org.jetbrains.kotlin.cli.common.repl.ScriptArgsWithTypes
import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlin.utils.PathUtil.KOTLIN_JAVA_RUNTIME_JAR
import org.jetbrains.kotlin.utils.PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR
import org.jetbrains.kotlin.utils.PathUtil.*
import java.io.File
import java.io.FileNotFoundException
import java.net.URL
@@ -80,20 +79,23 @@ private fun contextClasspath(keyName: String, classLoader: ClassLoader): List<Fi
private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader): List<File> =
( System.getProperty("kotlin.script.classpath")?.split(File.pathSeparator)?.map(::File)
?: contextClasspath(KOTLIN_JAVA_RUNTIME_JAR, classLoader)
?: listOf(kotlinRuntimeJar, kotlinScriptRuntimeJar)
)
?: classpathFromClassloader(classLoader)
).let {
it?.plus(kotlinScriptStandardJars) ?: kotlinScriptStandardJars
}
.map { it?.canonicalFile }
.distinct()
.mapNotNull { it?.existsOrNull() }
private val kotlinRuntimeJar: File? by lazy {
private val kotlinStdlibJar: File? by lazy {
System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_RUNTIME_JAR) }.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_STDLIB_JAR) }.existsOrNull()
}
private val kotlinScriptRuntimeJar: File? by lazy {
System.getProperty("kotlin.script.runtime.jar")?.let(::File)?.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_SCRIPT_RUNTIME_JAR) }.existsOrNull()
}
private val kotlinScriptStandardJars by lazy { listOf(kotlinStdlibJar, kotlinScriptRuntimeJar) }
@@ -79,12 +79,13 @@ private fun contextClasspath(keyName: String, classLoader: ClassLoader): List<Fi
private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader = Thread.currentThread().contextClassLoader): List<File> =
(System.getProperty("kotlin.script.classpath")?.split(File.pathSeparator)?.map(::File)
?: contextClasspath(KOTLIN_JAVA_RUNTIME_JAR, classLoader)
?: listOf(kotlinRuntimeJar, kotlinScriptRuntimeJar)
)
.map { it?.canonicalFile }
.distinct()
.mapNotNull { it?.existsOrNull() }
?: classpathFromClassloader(classLoader)
).let {
it?.plus(kotlinScriptStandardJars) ?: kotlinScriptStandardJars
}
.map { it?.canonicalFile }
.distinct()
.mapNotNull { it?.existsOrNull() }
private val kotlinCompilerJar: File by lazy {
// highest prio - explicit property
@@ -97,9 +98,9 @@ private val kotlinCompilerJar: File by lazy {
?: throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.jar property to proper location")
}
private val kotlinRuntimeJar: File? by lazy {
private val kotlinStdlibJar: File? by lazy {
System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_RUNTIME_JAR) }.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_STDLIB_JAR) }.existsOrNull()
?: getResourcePathForClass(JvmStatic::class.java).existsOrNull()
}
@@ -109,5 +110,6 @@ private val kotlinScriptRuntimeJar: File? by lazy {
?: getResourcePathForClass(ScriptTemplateWithArgs::class.java).existsOrNull()
}
private val kotlinScriptStandardJars by lazy { listOf(kotlinStdlibJar, kotlinScriptRuntimeJar) }