From b0d4220a7e1b2c53dfd5b8da118a1829039ce44b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 17 Oct 2016 16:31:39 +0200 Subject: SONAR-8284 Remove overall/IT coverage data from scanner report --- .../sonar/scanner/report/CoveragePublisher.java | 52 ++-------------------- .../mediumtest/coverage/CoverageMediumTest.java | 22 ++++----- .../scanner/report/CoveragePublisherTest.java | 8 ++-- 3 files changed, 15 insertions(+), 67 deletions(-) (limited to 'sonar-scanner-engine/src') diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/CoveragePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/CoveragePublisher.java index cf17785dab8..ba776070fa5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/CoveragePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/CoveragePublisher.java @@ -56,57 +56,11 @@ public class CoveragePublisher implements ReportPublisherStep { int lineCount = ((InputFile) resource.inputComponent()).lines(); applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setUtHits(Integer.parseInt(value) > 0); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setItHits(Integer.parseInt(value) > 0); - } - }); - // Just in case we have only IT and no UT, we first take conditions from ITs, then from UTs (UTs will override ITs). - // Note that it would be very strange (and unsupported in scanner report) to have ITs and UTs don't report the same number of - // conditions. Not even talking about overall conditions... - applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setConditions(Integer.parseInt(value)); - } - }); + (value, builder) -> builder.setHits(Integer.parseInt(value) > 0)); applyLineMeasure(resource.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setConditions(Integer.parseInt(value)); - } - }); + (value, builder) -> builder.setConditions(Integer.parseInt(value))); applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setUtCoveredConditions(Integer.parseInt(value)); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setItCoveredConditions(Integer.parseInt(value)); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, LineCoverage.Builder builder) { - builder.setOverallCoveredConditions(Integer.parseInt(value)); - } - }); + (value, builder) -> builder.setCoveredConditions(Integer.parseInt(value))); writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE)); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java index ccc5440ae86..0f3c28a14f0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java @@ -83,12 +83,9 @@ public class CoverageMediumTest { .start(); InputFile file = result.inputFile("src/sample.xoo"); - assertThat(result.coverageFor(file, 2).getUtHits()).isTrue(); - assertThat(result.coverageFor(file, 2).getItHits()).isFalse(); + assertThat(result.coverageFor(file, 2).getHits()).isTrue(); assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2); - assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(1); - assertThat(result.coverageFor(file, 2).getItCoveredConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 2).getOverallCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(1); Map> allMeasures = result.allMeasures(); assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value") @@ -125,10 +122,10 @@ public class CoverageMediumTest { .start(); InputFile file = result.inputFile("src/sample.xoo"); - assertThat(result.coverageFor(file, 2).getUtHits()).isTrue(); + assertThat(result.coverageFor(file, 2).getHits()).isTrue(); assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2); - assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(2); - assertThat(result.coverageFor(file, 3).getUtHits()).isTrue(); + assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(2); + assertThat(result.coverageFor(file, 3).getHits()).isTrue(); Map> allMeasures = result.allMeasures(); assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value") @@ -199,14 +196,11 @@ public class CoverageMediumTest { InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 1)).isNull(); - assertThat(result.coverageFor(file, 2).getUtHits()).isFalse(); - assertThat(result.coverageFor(file, 2).getItHits()).isFalse(); + assertThat(result.coverageFor(file, 2).getHits()).isFalse(); assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 2).getItCoveredConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 2).getOverallCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 3).getUtHits()).isFalse(); + assertThat(result.coverageFor(file, 3).getHits()).isFalse(); assertThat(result.coverageFor(file, 4)).isNull(); Map> allMeasures = result.allMeasures(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java index 6ce6b181fc9..95757460e10 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java @@ -84,17 +84,17 @@ public class CoveragePublisherTest { try (CloseableIterator it = new ScannerReportReader(outputDir).readComponentCoverage(2)) { assertThat(it.next()).isEqualTo(LineCoverage.newBuilder() .setLine(2) - .setUtHits(true) + .setHits(true) .build()); assertThat(it.next()).isEqualTo(LineCoverage.newBuilder() .setLine(3) - .setUtHits(true) + .setHits(true) .setConditions(4) - .setUtCoveredConditions(2) + .setCoveredConditions(2) .build()); assertThat(it.next()).isEqualTo(LineCoverage.newBuilder() .setLine(5) - .setUtHits(false) + .setHits(false) .build()); } -- cgit v1.2.3