Fix default base classloader initialization for scripting hosts

also refactor runner functions
#KT-37823 fixed
This commit is contained in:
Ilya Chernikov
2020-03-31 16:57:41 +02:00
parent 15d76ae887
commit 278f77713d
4 changed files with 57 additions and 6 deletions
@@ -30,7 +30,7 @@ val JvmScriptingHostConfigurationKeys.jdkHome by PropertiesCollection.key<File>(
val JvmScriptingHostConfigurationKeys.baseClassLoader by PropertiesCollection.key<ClassLoader>(
{
get(ScriptingHostConfiguration.configurationDependencies)?.let {
URLClassLoader(it.toClassPathOrEmpty().map { f -> f.toURI().toURL() }.toTypedArray())
URLClassLoader(it.toClassPathOrEmpty().map { f -> f.toURI().toURL() }.toTypedArray(), null)
}
},
isTransient = true
@@ -9,6 +9,7 @@ import junit.framework.Assert
import org.jetbrains.kotlin.mainKts.COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR
import org.jetbrains.kotlin.mainKts.COMPILED_SCRIPTS_CACHE_DIR_PROPERTY
import org.jetbrains.kotlin.scripting.compiler.plugin.runWithK2JVMCompiler
import org.jetbrains.kotlin.scripting.compiler.plugin.runWithKotlinLauncherScript
import org.jetbrains.kotlin.scripting.compiler.plugin.runWithKotlinc
import org.junit.Ignore
import org.junit.Test
@@ -46,6 +47,19 @@ class MainKtsIT {
fun testThreadContextClassLoader() {
runWithKotlincAndMainKts("$TEST_DATA_ROOT/context-classloader.main.kts", listOf("MainKtsConfigurator"))
}
@Test
fun testCachedReflection() {
val cache = createTempDir("main.kts.test")
try {
runWithKotlinRunner("$TEST_DATA_ROOT/use-reflect.main.kts", listOf("false"), cacheDir = cache)
// second run uses the cached script
runWithKotlinRunner("$TEST_DATA_ROOT/use-reflect.main.kts", listOf("false"), cacheDir = cache)
} finally {
cache.deleteRecursively()
}
}
}
fun runWithKotlincAndMainKts(
@@ -65,6 +79,18 @@ fun runWithKotlincAndMainKts(
)
}
fun runWithKotlinRunner(
scriptPath: String,
expectedOutPatterns: List<String> = emptyList(),
expectedExitCode: Int = 0,
cacheDir: File? = null
) {
runWithKotlinLauncherScript(
"kotlin", listOf(scriptPath), expectedOutPatterns, expectedExitCode,
additionalEnvVars = listOf(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR to (cacheDir?.absolutePath ?: ""))
)
}
fun runWithK2JVMCompilerAndMainKts(
scriptPath: String,
expectedOutPatterns: List<String> = emptyList(),
@@ -0,0 +1,2 @@
println(""::class.isOpen)