Fix script classpath utility functions that use classpath filtering by "keys"
The problem was that only the first matching classpath entry were used. The problem was reported by @lion7 on github (https://github.com/JetBrains/kotlin/commit/67ad3773de2b12f7e1d29e00151b997a4f6373ba#commitcomment-34443927)
This commit is contained in:
+23
@@ -16,6 +16,7 @@ import java.util.jar.JarOutputStream
|
||||
import java.util.jar.Manifest
|
||||
import kotlin.script.experimental.jvm.util.classPathFromTypicalResourceUrls
|
||||
import kotlin.script.experimental.jvm.util.classpathFromClassloader
|
||||
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrNull
|
||||
|
||||
class ClassPathTest : TestCase() {
|
||||
|
||||
@@ -57,6 +58,28 @@ class ClassPathTest : TestCase() {
|
||||
Assert.assertTrue(cp.contains(File(root1, el).canonicalFile))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFilterClasspath() {
|
||||
val tempDir = createTempDir().canonicalFile
|
||||
try {
|
||||
val files = listOf(
|
||||
File(tempDir, "projX/classes"),
|
||||
File(tempDir, "projX/test-classes"),
|
||||
File(tempDir, "projY/classes")
|
||||
)
|
||||
files.forEach { it.mkdirs() }
|
||||
|
||||
val classloader = URLClassLoader(files.map { it.toURI().toURL() }.toTypedArray(), null)
|
||||
|
||||
val classpath =
|
||||
scriptCompilationClasspathFromContextOrNull("projX", classLoader = classloader)!!.map { it.toRelativeString(tempDir) }
|
||||
|
||||
Assert.assertEquals(files.dropLast(1).map { it.toRelativeString(tempDir) }, classpath)
|
||||
} finally {
|
||||
tempDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val emulatedCollectionFiles = arrayOf(
|
||||
|
||||
Reference in New Issue
Block a user