Remove usage of deprecated URLClassloader (re-coded without scanning and pattern matching on run-time classpath URLs)

This commit is contained in:
josecoll 2019-05-16 17:39:37 +01:00
parent e1d1563901
commit 077a2f5af6

View File

@ -126,7 +126,7 @@ class DriverDSLImpl(
private val state = ThreadBox(State()) private val state = ThreadBox(State())
//TODO: remove this once we can bundle quasar properly. //TODO: remove this once we can bundle quasar properly.
private val quasarJarPath: String by lazy { resolveJar(".*quasar.*\\.jar$") } private val quasarJarPath: String by lazy { resolveJar("co.paralleluniverse.fibers.Suspendable") }
private fun NodeConfig.checkAndOverrideForInMemoryDB(): NodeConfig = this.run { private fun NodeConfig.checkAndOverrideForInMemoryDB(): NodeConfig = this.run {
if (inMemoryDB && corda.dataSourceProperties.getProperty("dataSource.url").startsWith("jdbc:h2:")) { if (inMemoryDB && corda.dataSourceProperties.getProperty("dataSource.url").startsWith("jdbc:h2:")) {
@ -138,15 +138,13 @@ class DriverDSLImpl(
} }
} }
private fun resolveJar(jarNamePattern: String): String { private fun resolveJar(className: String): String {
return try { return try {
val cl = ClassLoader.getSystemClassLoader() val type = Class.forName(className)
val urls = (cl as URLClassLoader).urLs val src = type.protectionDomain.codeSource
val jarPattern = jarNamePattern.toRegex() return src.location.toString()
val jarFileUrl = urls.first { jarPattern.matches(it.path) }
jarFileUrl.toPath().toString()
} catch (e: Exception) { } catch (e: Exception) {
log.warn("Unable to locate JAR `$jarNamePattern` on classpath: ${e.message}", e) log.warn("Unable to locate JAR for class given by `$className` on classpath: ${e.message}", e)
throw e throw e
} }
} }