Skip to content

Commit

Permalink
Merge pull request #184 from Drill4J/fix/jars-inside-ear-scanning-EPM…
Browse files Browse the repository at this point in the history
…DJ-10965

Fix/jars inside ear scanning epmdj 10965
  • Loading branch information
iryabov authored Jan 10, 2025
2 parents 302d861 + b30b7ec commit 3bf0c3b
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.epam.drill.agent.common.classloading.ClassSource

private const val PREFIX_SPRING_BOOT = "BOOT-INF/classes/"
private const val PREFIX_WEB_APP = "WEB-INF/classes/"
private const val PREFIX_JAR = ".jar/"
private const val PACKAGE_DRILL = "com/epam/drill"
private const val JAR_BUFFER_SIZE = 256 * 1024

Expand Down Expand Up @@ -151,9 +152,18 @@ class ClassPathScanner(
it.copy(superName = superName, bytes = bytes)
}
logger.trace { "ClassPathScanner: scanning class file: ${this.toRelativeString(directory)}" }
this.toRelativeString(directory).replace(File.separatorChar, '/')
.removePrefix(PREFIX_WEB_APP).removePrefix(PREFIX_SPRING_BOOT).removeSuffix(".class").let(::ClassSource)
.takeIf(isClassAccepted)?.let(readClassSource)?.takeIf(isPrefixMatches)?.let(::addClassToScanned) ?: 0
this.toRelativeString(directory)
.replace(File.separatorChar, '/')
.removePrefix(PREFIX_WEB_APP)
.removePrefix(PREFIX_SPRING_BOOT)
.removeBefore(PREFIX_JAR)
.removeSuffix(".class")
.let(::ClassSource)
.takeIf(isClassAccepted)
?.let(readClassSource)
?.takeIf(isPrefixMatches)
?.let(::addClassToScanned)
?: 0
}

/**
Expand All @@ -169,7 +179,11 @@ class ClassPathScanner(
it.copy(superName = superName, bytes = bytes)
}
logger.trace { "ClassPathScanner: scanning class entry: $this" }
this.removePrefix(PREFIX_WEB_APP).removePrefix(PREFIX_SPRING_BOOT).removeSuffix(".class").let(::ClassSource)
this.removePrefix(PREFIX_WEB_APP)
.removePrefix(PREFIX_SPRING_BOOT)
.removeBefore(PREFIX_JAR)
.removeSuffix(".class")
.let(::ClassSource)
.takeIf(isClassAccepted)?.let(readClassSource)?.takeIf(isPrefixMatches)?.let(::addClassToScanned) ?: 0
}

Expand Down Expand Up @@ -208,4 +222,9 @@ class ClassPathScanner(
*/
private fun URI.startsWithAnyOf(paths: List<URI>) = paths.any { this.path.startsWith(it.path) }

private fun String.removeBefore(prefix: String): String {
val index = indexOf(prefix)
return if (index != -1) substring(index + prefix.length) else this
}

}

0 comments on commit 3bf0c3b

Please sign in to comment.