use of org.jacoco.core.analysis.CoverageBuilder in project dspot by STAMP-project.
the class JacocoListener method coverageResults.
private CoverageResults coverageResults(ExecutionDataStore executionData) {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
try {
analyzer.analyzeAll(new File(classesDirectory));
} catch (IOException e) {
throw new RuntimeException(e);
}
return new CoverageResults(coverageBuilder);
}
use of org.jacoco.core.analysis.CoverageBuilder in project sonar-java by SonarSource.
the class UnitTestAnalyzer method readExecutionData.
private void readExecutionData(@Nullable File jacocoExecutionData, SensorContext context) {
File newJacocoExecutionData = jacocoExecutionData;
if (newJacocoExecutionData == null || !newJacocoExecutionData.isFile()) {
JaCoCoExtensions.LOG.info("Project coverage is set to 0% as no JaCoCo execution data has been dumped: {}", newJacocoExecutionData);
newJacocoExecutionData = null;
}
ExecutionDataVisitor executionDataVisitor = new ExecutionDataVisitor();
jacocoReportReader = new JacocoReportReader(newJacocoExecutionData).readJacocoReport(executionDataVisitor, executionDataVisitor);
boolean collectedCoveragePerTest = readCoveragePerTests(executionDataVisitor);
CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataVisitor.getMerged(), classFilesCache.values());
int analyzedResources = 0;
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) {
InputFile inputFile = getResource(coverage);
if (inputFile != null) {
NewCoverage newCoverage = context.newCoverage().onFile(inputFile);
analyzeFile(newCoverage, inputFile, coverage);
newCoverage.save();
analyzedResources++;
}
}
if (analyzedResources == 0) {
JaCoCoExtensions.LOG.warn("Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?");
} else if (collectedCoveragePerTest) {
JaCoCoExtensions.LOG.info("Information about coverage per test has been collected.");
} else if (newJacocoExecutionData != null) {
JaCoCoExtensions.LOG.info("No information about coverage per test.");
}
}
use of org.jacoco.core.analysis.CoverageBuilder in project sonar-java by SonarSource.
the class UnitTestAnalyzer method analyzeLinesCoveredByTests.
private boolean analyzeLinesCoveredByTests(String sessionId, ExecutionDataStore executionDataStore) {
int i = sessionId.indexOf(' ');
if (i < 0) {
return false;
}
String testClassName = sessionId.substring(0, i);
String testName = sessionId.substring(i + 1);
InputFile testResource = javaResourceLocator.findResourceByClassName(testClassName);
if (testResource == null) {
// No such test class
return false;
}
boolean result = false;
CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataStore, classFilesOfStore(executionDataStore));
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) {
InputFile resource = getResource(coverage);
if (resource != null) {
List<Integer> coveredLines = coveredLines(coverage);
if (!coveredLines.isEmpty() && addCoverage(resource, testResource, testName, coveredLines)) {
result = true;
}
}
}
return result;
}
use of org.jacoco.core.analysis.CoverageBuilder in project sonar-java by SonarSource.
the class JacocoReportReader method analyzeFiles.
/**
* Caller must guarantee that {@code classFiles} are actually class file.
*/
public CoverageBuilder analyzeFiles(ExecutionDataStore executionDataStore, Collection<File> classFiles) {
CoverageBuilder coverageBuilder = new CoverageBuilder();
if (useCurrentBinaryFormat) {
Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
for (File classFile : classFiles) {
analyzeClassFile(analyzer, classFile);
}
} else {
org.jacoco.previous.core.analysis.Analyzer analyzer = new org.jacoco.previous.core.analysis.Analyzer(executionDataStore, coverageBuilder);
for (File classFile : classFiles) {
analyzeClassFile(analyzer, classFile);
}
}
logNoMatchClasses(coverageBuilder.getNoMatchClasses());
return coverageBuilder;
}
use of org.jacoco.core.analysis.CoverageBuilder in project bazel by bazelbuild.
the class JacocoCoverageRunner method analyzeStructure.
private IBundleCoverage analyzeStructure() throws IOException {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
for (File classesJar : classesJars) {
analyzer.analyzeAll(classesJar);
}
// TODO(bazel-team): Find out where the name of the bundle can pop out in the report.
return coverageBuilder.getBundle("isthisevenused");
}
Aggregations