Set thread context classloader in the kotlin runner
#KT-26624 fixed
This commit is contained in:
@@ -57,6 +57,8 @@ abstract class AbstractRunner : Runner {
|
||||
)
|
||||
}
|
||||
|
||||
Thread.currentThread().contextClassLoader = classLoader
|
||||
|
||||
try {
|
||||
main.invoke(null, arguments.toTypedArray())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
object ContextClassLoaderTester {
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
kotlin.test.DefaultAsserter.assertTrue("", true) // this tests that kotlin-test is in the compilation and runtime classpaths
|
||||
val contextClassLoader = Thread.currentThread().getContextClassLoader()
|
||||
contextClassLoader.loadClass("kotlin.test.DefaultAsserter") // this tests that thread context classloader is set correctly
|
||||
println("ok")
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,24 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
||||
)
|
||||
}
|
||||
|
||||
fun testKotlinJvmContextClassLoader() {
|
||||
val kotlinTestJar = File(PathUtil.kotlinPathsForDistDirectory.homePath, "lib/kotlin-test.jar")
|
||||
assertTrue("kotlin-main-kts.jar not found, run dist task: ${kotlinTestJar.absolutePath}", kotlinTestJar.exists())
|
||||
runProcess(
|
||||
"kotlinc",
|
||||
"-cp", kotlinTestJar.path,
|
||||
"$testDataDirectory/contextClassLoaderTester.kt",
|
||||
"-d", tmpdir.path
|
||||
)
|
||||
|
||||
runProcess(
|
||||
"kotlin",
|
||||
"-cp", listOf(tmpdir.path, kotlinTestJar.path).joinToString(File.pathSeparator),
|
||||
"ContextClassLoaderTester",
|
||||
expectedStdout = "ok\n"
|
||||
)
|
||||
}
|
||||
|
||||
fun testKotlincJsSimple() {
|
||||
runProcess(
|
||||
"kotlinc-js",
|
||||
|
||||
Reference in New Issue
Block a user