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.
This commit is contained in:
Viktor Kolomeyko 2018-07-17 09:04:24 +01:00 committed by GitHub
parent 52d281b66f
commit 2b6e59e7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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