Search in sources :

Example 1 with DefaultCoverage

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()));
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultCoverage(org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage)

Example 2 with DefaultCoverage

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());
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArrayList(java.util.ArrayList) DefaultCoverage(org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage) Test(org.junit.Test)

Example 3 with DefaultCoverage

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);
}
Also used : NewSymbolTable(org.sonar.api.batch.sensor.symbol.NewSymbolTable) Collection(java.util.Collection) DefaultSignificantCode(org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode) Measure(org.sonar.api.batch.sensor.measure.Measure) HashMap(java.util.HashMap) Issue(org.sonar.api.batch.sensor.issue.Issue) ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) ArrayList(java.util.ArrayList) NewSignificantCode(org.sonar.api.batch.sensor.code.NewSignificantCode) AnalysisError(org.sonar.api.batch.sensor.error.AnalysisError) DefaultCoverage(org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage) List(java.util.List) NewHighlighting(org.sonar.api.batch.sensor.highlighting.NewHighlighting) Preconditions.checkArgument(org.sonar.api.utils.Preconditions.checkArgument) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) NewCpdTokens(org.sonar.api.batch.sensor.cpd.NewCpdTokens) AdHocRule(org.sonar.api.batch.sensor.rule.AdHocRule) Map(java.util.Map) NewCoverage(org.sonar.api.batch.sensor.coverage.NewCoverage) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) Collections(java.util.Collections) DefaultCpdTokens(org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens) ArrayList(java.util.ArrayList) DefaultCoverage(org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage)

Aggregations

DefaultCoverage (org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage)3 ArrayList (java.util.ArrayList)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 NewSignificantCode (org.sonar.api.batch.sensor.code.NewSignificantCode)1 DefaultSignificantCode (org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode)1 NewCoverage (org.sonar.api.batch.sensor.coverage.NewCoverage)1 NewCpdTokens (org.sonar.api.batch.sensor.cpd.NewCpdTokens)1 DefaultCpdTokens (org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens)1 AnalysisError (org.sonar.api.batch.sensor.error.AnalysisError)1 NewHighlighting (org.sonar.api.batch.sensor.highlighting.NewHighlighting)1 DefaultHighlighting (org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting)1 ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)1 Issue (org.sonar.api.batch.sensor.issue.Issue)1