minor: some repl cleanup
This commit is contained in:
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.util.KotlinFrontEndException
|
||||
import org.junit.Test
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
@@ -98,7 +97,7 @@ class GenericReplTest : TestCase() {
|
||||
val state = repl.createState()
|
||||
|
||||
val codeLine0 = ReplCodeLine(0, 0, "val l1 = 1\r\nl1\r\n")
|
||||
val res0 = repl.replCompiler?.check(state, codeLine0)
|
||||
val res0 = repl.replCompiler.check(state, codeLine0)
|
||||
val res0c = res0 as? ReplCheckResult.Ok
|
||||
TestCase.assertNotNull("Unexpected compile result: $res0", res0c)
|
||||
}
|
||||
|
||||
+6
-20
@@ -55,26 +55,12 @@ private fun URL.toFile() =
|
||||
fun classpathFromClassloader(classLoader: ClassLoader): List<File>? =
|
||||
generateSequence(classLoader) { it.parent }.toList().flatMap { (it as? URLClassLoader)?.urLs?.mapNotNull(URL::toFile) ?: emptyList() }
|
||||
|
||||
private fun File.existsOrNull(): File? = existsAndCheckOrNull { true }
|
||||
private inline fun File.existsAndCheckOrNull(check: (File.() -> Boolean)): File? = if (exists() && check()) this else null
|
||||
|
||||
private val kotlinCompilerJar: File by lazy {
|
||||
// highest prio - explicit property
|
||||
System.getProperty("kotlin.compiler.jar")?.let(::File)?.existsOrNull()
|
||||
System.getProperty("kotlin.compiler.jar")?.let(::File)?.takeIf(File::exists)
|
||||
?: PathUtil.getKotlinPathsForIdeaPlugin().compilerPath
|
||||
?: throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.jar property to proper location")
|
||||
}
|
||||
private fun <T> Iterable<T>.anyOrNull(predicate: (T) -> Boolean) = if (any(predicate)) this else null
|
||||
|
||||
private fun File.matchMaybeVersionedFile(baseName: String) =
|
||||
name == baseName ||
|
||||
name == baseName.removeSuffix(".jar") || // for classes dirs
|
||||
name.startsWith(baseName.removeSuffix(".jar") + "-")
|
||||
|
||||
private fun contextClasspath(keyName: String, classLoader: ClassLoader): List<File>? =
|
||||
( classpathFromClassloader(classLoader)?.anyOrNull { it.matchMaybeVersionedFile(keyName) }
|
||||
)?.toList()
|
||||
|
||||
|
||||
private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader): List<File> =
|
||||
( System.getProperty("kotlin.script.classpath")?.split(File.pathSeparator)?.map(::File)
|
||||
@@ -84,17 +70,17 @@ private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader): Lis
|
||||
}
|
||||
.map { it?.canonicalFile }
|
||||
.distinct()
|
||||
.mapNotNull { it?.existsOrNull() }
|
||||
.mapNotNull { it?.takeIf(File::exists) }
|
||||
|
||||
|
||||
private val kotlinStdlibJar: File? by lazy {
|
||||
System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull()
|
||||
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_STDLIB_JAR) }.existsOrNull()
|
||||
System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.takeIf(File::exists)
|
||||
?: File(kotlinCompilerJar.parentFile, KOTLIN_JAVA_STDLIB_JAR).takeIf(File::exists)
|
||||
}
|
||||
|
||||
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()
|
||||
System.getProperty("kotlin.script.runtime.jar")?.let(::File)?.takeIf(File::exists)
|
||||
?: File(kotlinCompilerJar.parentFile, KOTLIN_JAVA_SCRIPT_RUNTIME_JAR).takeIf(File::exists)
|
||||
}
|
||||
|
||||
private val kotlinScriptStandardJars by lazy { listOf(kotlinStdlibJar, kotlinScriptRuntimeJar) }
|
||||
Reference in New Issue
Block a user