Update BranchDetailAnalyzer.
BranchDetailAnalyzer should have also been updated as part of when the jacoco version in bazel was updated.
Changes like this will be avoided after is merged, because it enables testing with the java coverage tools at head.
Closes
package com.google.testing.coverage;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -22,6 +24,7 @@ import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.analysis.ICoverageVisitor;
import org.jacoco.core.data.ExecutionData;
import org.jacoco.core.data.ExecutionDataStore;
+import org.jacoco.core.internal.InputStreams;
import org.jacoco.core.internal.data.CRC64;
import org.jacoco.core.internal.flow.ClassProbesAdapter;
import org.objectweb.asm.ClassReader;
@@ -38,16 +41,37 @@ public class BranchDetailAnalyzer extends Analyzer {
private final Map<String, BranchCoverageDetail> branchDetails;
public BranchDetailAnalyzer(final ExecutionDataStore executionData) {
- super(executionData, new ICoverageVisitor() {
+ super(
+ executionData,
+ new ICoverageVisitor() {
@Override
- public void visitCoverage(IClassCoverage coverage) {
- }
+ public void visitCoverage(IClassCoverage coverage) {}
});
-
this.executionData = executionData;
this.branchDetails = new TreeMap<String, BranchCoverageDetail>();
}
+ // Override all analyzeClass methods.
+ @Override
+ public void analyzeClass(final InputStream input, final String location) throws IOException {
+ final byte[] buffer;
+ try {
+ buffer = InputStreams.readFully(input);
+ } catch (final IOException e) {
+ throw analyzerError(location, e);
+ }
+ analyzeClass(buffer, location);
+ }
+
+ @Override
+ public void analyzeClass(final byte[] buffer, final String location) throws IOException {
+ try {
+ analyzeClass(buffer);
+ } catch (final RuntimeException cause) {
+ throw analyzerError(location, cause);
+ }
+ }
+
@Override
public void analyzeClass(final ClassReader reader) {
final Map<Integer, BranchExp> lineToBranchExp = mapProbes(reader);
@@ -78,6 +102,17 @@ public class BranchDetailAnalyzer extends Analyzer {
}
}
+ private void analyzeClass(final byte[] source) {
+ final ClassReader reader = new ClassReader(source);
+ analyzeClass(reader);
+ }
+
+ private IOException analyzerError(final String location, final Exception cause) {
+ final IOException ex = new IOException(String.format("Error while analyzing %s.", location));
+ ex.initCause(cause);
+ return ex;
+ }
+
// Generate the line to probeExp map so that we can evaluate the coverage.
private Map<Integer, BranchExp> mapProbes(final ClassReader reader) {
final ClassProbesMapper mapper = new ClassProbesMapper();
