Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/jars inside ear scanning epmdj 10965 #184

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
config:
- {os: ubuntu-latest, preset: linuxX64}
- {os: windows-latest, preset: mingwX64}
- {os: macos-12, preset: macosX64}
# - {os: macos-12, preset: macosX64} deprecated in GitHub Actions
- {os: macos-14, preset: macosArm64}
runs-on: ${{ matrix.config.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
config:
- {os: ubuntu-latest, preset: linuxX64}
- {os: windows-latest, preset: mingwX64}
- {os: macos-12, preset: macosX64}
# - {os: macos-12, preset: macosX64} deprecated in GitHub Actions
- {os: macos-14, preset: macosArm64}
runs-on: ${{ matrix.config.os }}
steps:
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
config:
- {os: ubuntu-latest, preset: linuxX64}
- {os: windows-latest, preset: mingwX64}
- {os: macos-12, preset: macosX64}
# - {os: macos-12, preset: macosX64} deprecated in GitHub Actions
- {os: macos-14, preset: macosArm64}
runs-on: ${{ matrix.config.os }}
outputs:
Expand Down
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
}

}
Loading