use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.
the class BundleChecker method check.
private void check(final IPackageCoverage packageCoverage) {
final String name = names.getPackageName(packageCoverage.getName());
checkRules(packageCoverage, packageRules, "package", name);
if (traverseClasses) {
for (final IClassCoverage c : packageCoverage.getClasses()) {
check(c);
}
}
if (traverseSourceFiles) {
for (final ISourceFileCoverage s : packageCoverage.getSourceFiles()) {
check(s);
}
}
}
use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.
the class PackageSourcePage method renderSourceFilePages.
private final void renderSourceFilePages() throws IOException {
final String packagename = getNode().getName();
for (final ISourceFileCoverage s : getNode().getSourceFiles()) {
final String sourcename = s.getName();
final Reader reader = locator.getSourceFile(packagename, sourcename);
if (reader == null) {
addItem(new SourceFileItem(s));
} else {
final SourceFilePage sourcePage = new SourceFilePage(s, reader, locator.getTabWidth(), this, folder, context);
sourcePage.render();
sourceFilePages.put(sourcename, sourcePage);
addItem(sourcePage);
}
}
}
use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.
the class ValidationTestBase method analyze.
private void analyze(final ExecutionDataStore store) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(store, builder);
for (ExecutionData data : store.getContents()) {
analyze(analyzer, data);
}
String srcName = target.getName().replace('.', '/') + ".java";
for (ISourceFileCoverage file : builder.getSourceFiles()) {
if (srcName.equals(file.getPackageName() + "/" + file.getName())) {
sourceCoverage = file;
return;
}
}
fail("No source node found for " + srcName);
}
use of org.jacoco.core.analysis.ISourceFileCoverage 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.ISourceFileCoverage 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;
}
Aggregations