Skip to content

Commit

Permalink
Merge pull request #663 from cqse/ts/41980_closed_stream
Browse files Browse the repository at this point in the history
TS-41980 Handle nested jars for converter
  • Loading branch information
DreierF authored Feb 25, 2025
2 parents 7e96a77 + e57a1ff commit af3965e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void runJaCoCoReportGeneration() throws IOException, AgentOptionParseExce
try (Benchmark benchmark = new Benchmark("Generating the XML report")) {
generator.convert(new Dump(sessionInfo, executionDataStore), Paths.get(arguments.outputFile).toFile());
} catch (EmptyReportException e) {
logger.warn("Converted report was emtpy.", e);
logger.warn("Converted report was empty.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@ public void testSmokeTest(@TempDir File tempDir) throws Exception {
new Converter(arguments).runJaCoCoReportGeneration();

String xml = FileSystemUtils.readFileUTF8(outputFile);
System.err.println(xml);
assertThat(xml).isNotEmpty().contains("<package").contains("<sourcefile").contains("<counter").contains("TestClass");
}

@Test
public void testNestedJar(@TempDir File tempDir) throws Exception {
File execFile = new File(getClass().getResource("coverage.exec").toURI());
File classFile = new File(getClass().getResource("TestClass.jar.zip").toURI());
File outputFile = new File(tempDir, "coverage.xml");

ConvertCommand arguments = new ConvertCommand();
arguments.inputFiles = Collections.singletonList(execFile.getAbsolutePath());
arguments.outputFile = outputFile.getAbsolutePath();
arguments.classDirectoriesOrZips = Collections.singletonList(classFile.getAbsolutePath());

new Converter(arguments).runJaCoCoReportGeneration();

String xml = FileSystemUtils.readFileUTF8(outputFile);
assertThat(xml).isNotEmpty().contains("<package").contains("<sourcefile").contains("<counter").contains("TestClass");
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ open class FilteringAnalyzer(
*/
@Throws(IOException::class)
protected open fun analyzeJar(input: InputStream, location: String): Int {
ZipInputStream(BashFileSkippingInputStream(input)).use { zip ->
return generateSequence { zip.nextEntry(location) }
val zip = ZipInputStream(BashFileSkippingInputStream(input))
return generateSequence { zip.nextEntry(location) }
.map { entry -> analyzeAll(zip, "$location@${entry.name}") }
.sum()
}
}

/** Copied from [org.jacoco.core.analysis.Analyzer.nextEntry]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class BashFileSkippingInputStream(input: InputStream) : FilterInputStream(Buffer
`in`.mark(BUFFER_SIZE)
bytesRead = `in`.read(buffer, 0, BUFFER_SIZE)
}

throw IOException("ZIP header not found in the input stream.")
}

/**
Expand Down

0 comments on commit af3965e

Please sign in to comment.