File tree 1 file changed +6
-5
lines changed
src/main/kotlin/org/jetbrains/kotlin/jupyter
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,13 @@ package org.jetbrains.kotlin.jupyter
3
3
import java.io.File
4
4
import kotlin.reflect.KClass
5
5
6
-
7
6
fun <T : Any > KClass<T>.containingClasspath (): File ? {
8
7
val clp = " ${qualifiedName?.replace(' .' , ' /' )} .class"
9
8
val url = Thread .currentThread().contextClassLoader.getResource(clp)?.toString() ? : return null
10
- val filenameRegex = """ (?:zip:|jar:file:)(.*)!/(?:.*)""" .toRegex()
11
- val matched = filenameRegex.find(url) ? : throw IllegalStateException (" Expecting a local classpath when searching for class: ${qualifiedName} " )
12
- val pathToJar = matched.groupValues[1 ]
13
- return File (pathToJar)
9
+ val zipOrJarRegex = """ (?:zip:|jar:file:)(.*)!\/(?:.*)""" .toRegex()
10
+ val filePathRegex = """ (?:file:)(.*)""" .toRegex()
11
+ val foundPath = zipOrJarRegex.find(url)?.let { it.groupValues[1 ] }
12
+ ? : filePathRegex.find(url)?.let { it.groupValues[1 ].removeSuffix(clp) }
13
+ ? : throw IllegalStateException (" Expecting a local classpath when searching for class: ${qualifiedName} " )
14
+ return File (foundPath)
14
15
}
You can’t perform that action at this time.
0 commit comments