Skip to content

Commit a2a9d25

Browse files
committed
fix classpath finding from a starting class to work with file based classes (as well as previously the JAR and ZIP)
1 parent 81a7147 commit a2a9d25

File tree

1 file changed

+6
-5
lines changed
  • src/main/kotlin/org/jetbrains/kotlin/jupyter

1 file changed

+6
-5
lines changed

src/main/kotlin/org/jetbrains/kotlin/jupyter/util.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package org.jetbrains.kotlin.jupyter
33
import java.io.File
44
import kotlin.reflect.KClass
55

6-
76
fun <T: Any> KClass<T>.containingClasspath(): File? {
87
val clp = "${qualifiedName?.replace('.', '/')}.class"
98
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)
1415
}

0 commit comments

Comments
 (0)