Skip to content

Commit 701f15e

Browse files
committed
[Coverage] Fix coverage for large targets
When a classpath is very large, Bazel will create a manifest jar with the classpath as an entry in the manifest. To get the sources for coverage, Bazel checks whether it needs to reverse the process to find the classpath. However, part of this logic checks whether the manfiest jar is the only jar on the classpath (urls.length == 1). This is not true in our case - there are two jars on the classpath, with the first being the manifest jar. In this commit, we update the logic to check whether the first jar on the classpath is a manfiest jar by looking for the suffix on the jar. This allows Bazel to properly reverse the process when the classpath is large, meaning sources are found, and coverage is properly found again.
1 parent d891f4b commit 701f15e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/java_tools/junitrunner/java/com/google/testing/coverage/JacocoCoverageRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private static URL[] getUrls(ClassLoader classLoader, boolean wasWrappedJar) {
365365
// If the classpath was too long then a temporary top-level jar is created containing nothing
366366
// but a manifest with
367367
// the original classpath. Those are the URLs we are looking for.
368-
if (wasWrappedJar && urls != null && urls.length == 1) {
368+
if (wasWrappedJar && urls != null && (urls.length == 1 || urls[0].toString().endsWith("-classpath.jar"))) {
369369
try {
370370
String jarClassPath =
371371
new JarInputStream(urls[0].openStream())

0 commit comments

Comments
 (0)