Switch to File instead of String for classpaths in script dependencies
This commit is contained in:
committed by
Pavel V. Talanov
parent
5e3ba36cc1
commit
64bb47ed37
@@ -119,7 +119,7 @@ class ScriptTest {
|
||||
val aClass1 = compileScript("fib_ext.kts", SimpleParamsWithClasspathTestScriptDefinition(".kts", numIntParam(), classpath = emptyList()), runIsolated = true, suppressOutput = true)
|
||||
Assert.assertNull(aClass1)
|
||||
|
||||
val cp = classpathFromClassloader(ScriptTest::class.java.classLoader).filter { it.contains("kotlin-runtime") || it.contains("junit") }
|
||||
val cp = classpathFromClassloader(ScriptTest::class.java.classLoader).filter { it.name.contains("kotlin-runtime") || it.name.contains("junit") }
|
||||
Assert.assertFalse(cp.isEmpty())
|
||||
|
||||
val aClass2 = compileScript("fib_ext.kts", SimpleParamsWithClasspathTestScriptDefinition(".kts", numIntParam(), classpath = cp), runIsolated = true)
|
||||
@@ -131,7 +131,7 @@ class ScriptTest {
|
||||
val aClass1 = compileScript("fib_ext.kts", SimpleParamsWithClasspathTestScriptDefinition(".kts", numIntParam(), classpath = emptyList()), runIsolated = true, suppressOutput = true)
|
||||
Assert.assertNull(aClass1)
|
||||
|
||||
val cp = classpathFromClassloader(ScriptTest::class.java.classLoader).filter { it.contains("kotlin-runtime") || it.contains("junit") }
|
||||
val cp = classpathFromClassloader(ScriptTest::class.java.classLoader).filter { it.name.contains("kotlin-runtime") || it.name.contains("junit") }
|
||||
Assert.assertFalse(cp.isEmpty())
|
||||
|
||||
val aClass2 = compileScript("fib_ext.kts", SimpleParamsWithClasspathTestScriptDefinition(".kts", numIntParam(), classpath = cp, extraDependencies = SimpleScriptExtraDependencies(cp)), runIsolated = true)
|
||||
@@ -145,7 +145,8 @@ class ScriptTest {
|
||||
StandardWithClasspathScriptDefinition(
|
||||
".kts",
|
||||
listOf("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar",
|
||||
"dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-reflect.jar")))
|
||||
"dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-reflect.jar")
|
||||
.map { File(it) }))
|
||||
Assert.assertNotNull(aClass)
|
||||
var exceptionThrown = false
|
||||
try {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -123,20 +124,20 @@ class GetTestKotlinScriptDependencies : GetScriptDependencies {
|
||||
val cp = anns.flatMap {
|
||||
it.value.mapNotNull {
|
||||
when (it) {
|
||||
is SimpleUntypedAst.Node.str -> if (it.value == "@{runtime}") kotlinPaths.runtimePath.canonicalPath else it.value
|
||||
is SimpleUntypedAst.Node.str -> if (it.value == "@{runtime}") kotlinPaths.runtimePath else File(it.value)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
return object : KotlinScriptExternalDependencies {
|
||||
override val classpath = classpathFromClassloader() + cp
|
||||
override val classpath: Iterable<File> = classpathFromClassloader() + cp
|
||||
}
|
||||
}
|
||||
|
||||
private fun classpathFromClassloader(): List<String> =
|
||||
private fun classpathFromClassloader(): List<File> =
|
||||
(GetTestKotlinScriptDependencies::class.java.classLoader as? URLClassLoader)?.urLs
|
||||
?.mapNotNull { it.toFile()?.canonicalPath }
|
||||
?.filter { it.contains("out/test") }
|
||||
?.mapNotNull { it.toFile() }
|
||||
?.filter { it.path.contains("out") && it.path.contains("test") }
|
||||
?: emptyList()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user