use of org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage in project sonarqube by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(NewCoverage coverage) {
DefaultCoverage defaultCoverage = (DefaultCoverage) coverage;
DefaultInputFile inputFile = (DefaultInputFile) defaultCoverage.inputFile();
inputFile.setPublished(true);
SortedMap<Integer, ScannerReport.LineCoverage.Builder> coveragePerLine = reloadExistingCoverage(inputFile);
int lineCount = inputFile.lines();
mergeLineCoverageValues(lineCount, defaultCoverage.hitsByLine(), coveragePerLine, (value, builder) -> builder.setHits(builder.getHits() || value > 0));
mergeLineCoverageValues(lineCount, defaultCoverage.conditionsByLine(), coveragePerLine, (value, builder) -> builder.setConditions(max(value, builder.getConditions())));
mergeLineCoverageValues(lineCount, defaultCoverage.coveredConditionsByLine(), coveragePerLine, (value, builder) -> builder.setCoveredConditions(max(value, builder.getCoveredConditions())));
reportPublisher.getWriter().writeComponentCoverage(inputFile.scannerId(), coveragePerLine.values().stream().map(ScannerReport.LineCoverage.Builder::build).collect(Collectors.toList()));
}
use of org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_merge_coverage.
@Test
public void should_merge_coverage() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setLines(5).build();
DefaultCoverage coverage = new DefaultCoverage(underTest);
coverage.onFile(file).lineHits(3, 1);
DefaultCoverage coverage2 = new DefaultCoverage(underTest);
coverage2.onFile(file).lineHits(1, 1);
underTest.store(coverage);
underTest.store(coverage2);
List<ScannerReport.LineCoverage> lineCoverage = new ArrayList<>();
reportReader.readComponentCoverage(file.scannerId()).forEachRemaining(lineCoverage::add);
assertThat(lineCoverage).containsExactly(// should be sorted by line
ScannerReport.LineCoverage.newBuilder().setLine(1).setHits(true).build(), ScannerReport.LineCoverage.newBuilder().setLine(3).setHits(true).build());
}
use of org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage in project sonarqube by SonarSource.
the class InMemorySensorStorage method store.
@Override
public void store(NewCoverage coverage) {
DefaultCoverage defaultCoverage = (DefaultCoverage) coverage;
String fileKey = defaultCoverage.inputFile().key();
coverageByComponent.computeIfAbsent(fileKey, x -> new ArrayList<>()).add(defaultCoverage);
}
Aggregations