Eliminate extensive printout when Byteman not found on the classpath. (#1277)

Byteman is absent for most of the integration tests and long stacktrace is seen in the log
presently that un-necessarily attracts attention and consumes logging space.

(cherry picked from commit 2b6e59e7bd)
This commit is contained in:
Viktor Kolomeyko 2018-07-17 09:04:24 +01:00 committed by LankyDan
parent e737b01184
commit c53ea9dde5

View File

@ -127,7 +127,7 @@ class DriverDSLImpl(
private val quasarJarPath: String by lazy { resolveJar(".*quasar.*\\.jar$").getOrThrow() } private val quasarJarPath: String by lazy { resolveJar(".*quasar.*\\.jar$").getOrThrow() }
private val bytemanJarPath: String? by lazy { private val bytemanJarPath: String? by lazy {
val maybeResolvedJar = resolveJar(".*byteman-\\d.*\\.jar$") val maybeResolvedJar = resolveJar(".*byteman-\\d.*\\.jar$", verbose = false)
when (maybeResolvedJar) { when (maybeResolvedJar) {
is Try.Success -> maybeResolvedJar.getOrThrow() is Try.Success -> maybeResolvedJar.getOrThrow()
is Try.Failure -> null is Try.Failure -> null
@ -144,7 +144,7 @@ class DriverDSLImpl(
} }
} }
private fun resolveJar(jarNamePattern: String): Try<String> { private fun resolveJar(jarNamePattern: String, verbose: Boolean = true): Try<String> {
return try { return try {
val cl = ClassLoader.getSystemClassLoader() val cl = ClassLoader.getSystemClassLoader()
val urls = (cl as URLClassLoader).urLs val urls = (cl as URLClassLoader).urLs
@ -152,7 +152,11 @@ class DriverDSLImpl(
val jarFileUrl = urls.first { jarPattern.matches(it.path) } val jarFileUrl = urls.first { jarPattern.matches(it.path) }
Try.Success(jarFileUrl.toPath().toString()) Try.Success(jarFileUrl.toPath().toString())
} catch (e: Exception) { } catch (e: Exception) {
if(verbose) {
log.warn("Unable to locate JAR `$jarNamePattern` on classpath: ${e.message}", e) 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) Try.Failure(e)
} }
} }