[minor] Fix URL conversion to the file
possibly fixes the exception from https://stackoverflow.com/questions/57727150/kotlin-script-engine-with-spring-boot-self-running-war
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ class ClassPathTest : TestCase() {
|
|||||||
+ jar.toURI().toURL()).toTypedArray(),
|
+ jar.toURI().toURL()).toTypedArray(),
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
val cp = cl.classPathFromTypicalResourceUrls().toList()
|
val cp = cl.classPathFromTypicalResourceUrls().toList().map { it.canonicalFile }
|
||||||
|
|
||||||
Assert.assertTrue(cp.contains(jar.canonicalFile))
|
Assert.assertTrue(cp.contains(jar.canonicalFile))
|
||||||
for (el in emulatedClasspath) {
|
for (el in emulatedClasspath) {
|
||||||
|
|||||||
@@ -94,10 +94,14 @@ fun tryGetResourcePathForClassByName(name: String, classLoader: ClassLoader): Fi
|
|||||||
|
|
||||||
internal fun URL.toFileOrNull() =
|
internal fun URL.toFileOrNull() =
|
||||||
try {
|
try {
|
||||||
File(toURI().schemeSpecificPart).canonicalFile
|
File(toURI())
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
null
|
||||||
} catch (e: java.net.URISyntaxException) {
|
} catch (e: java.net.URISyntaxException) {
|
||||||
|
null
|
||||||
|
} ?: run {
|
||||||
if (protocol != "file") null
|
if (protocol != "file") null
|
||||||
else File(file).canonicalFile
|
else File(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun URL.toContainingJarOrNull(): File? =
|
internal fun URL.toContainingJarOrNull(): File? =
|
||||||
|
|||||||
Reference in New Issue
Block a user