CORDA-2050 Upgrade Corda to Java 11 (compatibility mode) (#5356) Upgrade Corda to run with Java 11 (compatibility mode) - see https://github.com/corda/corda/pull/5356 - 3fafbe55

Reapply change that was lost during merge - Adjust resolution of byteman jar to use java 11 compatible mechanism. - a1077092

Manual cherry pick of these changes (a1077092 + 3fafbe55)
This commit is contained in:
LankyDan 2019-11-01 11:40:59 +00:00
parent c53ea9dde5
commit 4aa9add8c8

View File

@ -124,13 +124,13 @@ class DriverDSLImpl(
private val state = ThreadBox(State())
//TODO: remove this once we can bundle quasar properly.
private val quasarJarPath: String by lazy { resolveJar(".*quasar.*\\.jar$").getOrThrow() }
private val quasarJarPath: String by lazy { resolveJar("co.paralleluniverse.fibers.Suspendable") }
private val bytemanJarPath: String? by lazy {
val maybeResolvedJar = resolveJar(".*byteman-\\d.*\\.jar$", verbose = false)
when (maybeResolvedJar) {
is Try.Success -> maybeResolvedJar.getOrThrow()
is Try.Failure -> null
try {
resolveJar("org.jboss.byteman.agent.Transformer")
} catch (e: Exception) {
null
}
}
@ -144,20 +144,14 @@ class DriverDSLImpl(
}
}
private fun resolveJar(jarNamePattern: String, verbose: Boolean = true): Try<String> {
private fun resolveJar(className: String): String {
return try {
val cl = ClassLoader.getSystemClassLoader()
val urls = (cl as URLClassLoader).urLs
val jarPattern = jarNamePattern.toRegex()
val jarFileUrl = urls.first { jarPattern.matches(it.path) }
Try.Success(jarFileUrl.toPath().toString())
val type = Class.forName(className)
val src = type.protectionDomain.codeSource
src.location.toPath().toString()
} catch (e: Exception) {
if(verbose) {
log.warn("Unable to locate JAR `$jarNamePattern` on classpath: ${e.message}", e)
} else {
log.info("Unable to locate JAR `$jarNamePattern` on classpath")
}
Try.Failure(e)
log.warn("Unable to locate JAR for class given by `$className` on classpath: ${e.message}", e)
throw e
}
}