diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-10-17 16:31:39 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-10-18 16:00:26 +0200 |
commit | b0d4220a7e1b2c53dfd5b8da118a1829039ce44b (patch) | |
tree | fbdcc3cdfe974a260628011e8eb90ed2f363f2c5 | |
parent | f21abcbb8250053703ce6edc36bfea03bb3665e7 (diff) | |
download | sonarqube-b0d4220a7e1b2c53dfd5b8da118a1829039ce44b.tar.gz sonarqube-b0d4220a7e1b2c53dfd5b8da118a1829039ce44b.zip |
SONAR-8284 Remove overall/IT coverage data from scanner report
12 files changed, 115 insertions, 266 deletions
diff --git a/it/it-tests/src/test/java/it/test/CoverageTest.java b/it/it-tests/src/test/java/it/test/CoverageTest.java index 106cd9ffbce..65368cc2f9f 100644 --- a/it/it-tests/src/test/java/it/test/CoverageTest.java +++ b/it/it-tests/src/test/java/it/test/CoverageTest.java @@ -55,7 +55,7 @@ public class CoverageTest { } @Test - public void unit_test_coverage() throws Exception { + public void coverage() throws Exception { orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-ut-coverage"))); Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-ut-coverage", ALL_COVERAGE_METRICS)); @@ -86,7 +86,7 @@ public class CoverageTest { } @Test - public void unit_test_coverage_no_condition() throws Exception { + public void coverage_no_condition() throws Exception { orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-ut-coverage-no-condition"))); Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-ut-coverage", ALL_COVERAGE_METRICS)); @@ -111,19 +111,22 @@ public class CoverageTest { } @Test - public void it_coverage() throws Exception { + public void it_coverage_imported_as_coverage() throws Exception { orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-it-coverage"))); Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-it-coverage", ALL_COVERAGE_METRICS)); - assertThat(project.getMeasureValue("coverage")).isNull(); - assertThat(project.getMeasureValue("it_line_coverage")).isEqualTo(50.0); - assertThat(project.getMeasureValue("it_lines_to_cover")).isEqualTo(4); - assertThat(project.getMeasureValue("it_uncovered_lines")).isEqualTo(2); - assertThat(project.getMeasureValue("it_branch_coverage")).isEqualTo(50.0); - assertThat(project.getMeasureValue("it_conditions_to_cover")).isEqualTo(2); - assertThat(project.getMeasureValue("it_uncovered_conditions")).isEqualTo(1); - assertThat(project.getMeasureValue("it_coverage")).isEqualTo(50.0); + // Since SQ 6.2 all coverage reports are merged as coverage + + assertThat(project.getMeasureValue("line_coverage")).isEqualTo(50.0); + assertThat(project.getMeasureValue("lines_to_cover")).isEqualTo(4); + assertThat(project.getMeasureValue("uncovered_lines")).isEqualTo(2); + assertThat(project.getMeasureValue("branch_coverage")).isEqualTo(50.0); + assertThat(project.getMeasureValue("conditions_to_cover")).isEqualTo(2); + assertThat(project.getMeasureValue("uncovered_conditions")).isEqualTo(1); + assertThat(project.getMeasureValue("coverage")).isEqualTo(50.0); + + assertThat(project.getMeasureValue("it_coverage")).isNull(); assertThat(project.getMeasureValue("overall_coverage")).isNull(); @@ -135,9 +138,11 @@ public class CoverageTest { } @Test - public void ut_and_it_coverage() throws Exception { + public void ut_and_it_coverage_merged_in_coverage() throws Exception { orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-overall-coverage"))); + // Since SQ 6.2 all coverage reports are merged as coverage + Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-overall-coverage", ALL_COVERAGE_METRICS)); assertThat(project.getMeasureValue("line_coverage")).isEqualTo(50.0); assertThat(project.getMeasureValue("lines_to_cover")).isEqualTo(4); @@ -147,21 +152,9 @@ public class CoverageTest { assertThat(project.getMeasureValue("uncovered_conditions")).isEqualTo(3); assertThat(project.getMeasureValue("coverage")).isEqualTo(37.5); - assertThat(project.getMeasureValue("it_line_coverage")).isEqualTo(50.0); - assertThat(project.getMeasureValue("it_lines_to_cover")).isEqualTo(4); - assertThat(project.getMeasureValue("it_uncovered_lines")).isEqualTo(2); - assertThat(project.getMeasureValue("it_branch_coverage")).isEqualTo(25.0); - assertThat(project.getMeasureValue("it_conditions_to_cover")).isEqualTo(4); - assertThat(project.getMeasureValue("it_uncovered_conditions")).isEqualTo(3); - assertThat(project.getMeasureValue("it_coverage")).isEqualTo(37.5); - - assertThat(project.getMeasureValue("overall_line_coverage")).isEqualTo(75.0); - assertThat(project.getMeasureValue("overall_lines_to_cover")).isEqualTo(4); - assertThat(project.getMeasureValue("overall_uncovered_lines")).isEqualTo(1); - assertThat(project.getMeasureValue("overall_branch_coverage")).isEqualTo(50.0); - assertThat(project.getMeasureValue("overall_conditions_to_cover")).isEqualTo(4); - assertThat(project.getMeasureValue("overall_uncovered_conditions")).isEqualTo(2); - assertThat(project.getMeasureValue("overall_coverage")).isEqualTo(62.5); + assertThat(project.getMeasureValue("it_coverage")).isNull(); + + assertThat(project.getMeasureValue("overall_coverage")).isNull(); String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-overall-coverage:src/main/xoo/sample/Sample.xoo")); // Use strict checking to be sure no extra coverage is present diff --git a/it/it-tests/src/test/resources/test/CoverageTest/it_coverage-expected.json b/it/it-tests/src/test/resources/test/CoverageTest/it_coverage-expected.json index e18e570ff1e..25e10e11bd3 100644 --- a/it/it-tests/src/test/resources/test/CoverageTest/it_coverage-expected.json +++ b/it/it-tests/src/test/resources/test/CoverageTest/it_coverage-expected.json @@ -2,77 +2,77 @@ "sources": [ { "line": 1, - "code": "package sample;", + "code": "package sample;" }, { "line": 2, - "code": "", + "code": "" }, { "line": 3, - "code": "public class Sample {", + "code": "public class Sample {" }, { "line": 4, - "code": "\t", + "code": "\t" }, { "line": 5, - "code": "\tpublic Sample(int i) {", + "code": "\tpublic Sample(int i) {" }, { "line": 6, "code": "\t\tint j = i++;", - "itLineHits": 1 + "utLineHits": 1 }, { "line": 7, - "code": "\t}", + "code": "\t}" }, { "line": 8, - "code": "\t", + "code": "\t" }, { "line": 9, - "code": "\tprivate String myMethod() {", + "code": "\tprivate String myMethod() {" }, { "line": 10, "code": "\t\tif (foo == bar) {", - "itLineHits": 0, - "itConditions": 2, - "itCoveredConditions": 1 + "utLineHits": 0, + "utConditions": 2, + "utCoveredConditions": 1 }, { "line": 11, "code": "\t\t\treturn \"hello\";", - "itLineHits": 1 + "utLineHits": 1 }, { "line": 12, - "code": "\t\t} else {", + "code": "\t\t} else {" }, { "line": 13, "code": "\t\t\tthrow new IllegalStateException();", - "itLineHits": 0 + "utLineHits": 0 }, { "line": 14, - "code": "\t\t}", + "code": "\t\t}" }, { "line": 15, - "code": "\t}", + "code": "\t}" }, { "line": 16, - "code": "}", + "code": "}" }, { "line": 17, - "code": "", + "code": "" } ] } diff --git a/it/it-tests/src/test/resources/test/CoverageTest/ut_and_it_coverage-expected.json b/it/it-tests/src/test/resources/test/CoverageTest/ut_and_it_coverage-expected.json index 9d12abbba9c..59ca44b2acb 100644 --- a/it/it-tests/src/test/resources/test/CoverageTest/ut_and_it_coverage-expected.json +++ b/it/it-tests/src/test/resources/test/CoverageTest/ut_and_it_coverage-expected.json @@ -2,83 +2,77 @@ "sources": [ { "line": 1, - "code": "package sample;", + "code": "package sample;" }, { "line": 2, - "code": "", + "code": "" }, { "line": 3, - "code": "public class Sample {", + "code": "public class Sample {" }, { "line": 4, - "code": "\t", + "code": "\t" }, { "line": 5, - "code": "\tpublic Sample(int i) {", + "code": "\tpublic Sample(int i) {" }, { "line": 6, "code": "\t\tint j = i++;", - "utLineHits": 1, - "itLineHits": 1 + "utLineHits": 1 }, { "line": 7, - "code": "\t}", + "code": "\t}" }, { "line": 8, - "code": "\t", + "code": "\t" }, { "line": 9, - "code": "\tprivate String myMethod() {", + "code": "\tprivate String myMethod() {" }, { "line": 10, "code": "\t\tif (foo == bar && biz > 1) {", "utLineHits": 0, "utConditions": 4, - "utCoveredConditions": 1, - "itLineHits": 0, - "itConditions": 4, - "itCoveredConditions": 1 + "utCoveredConditions": 1 }, { "line": 11, "code": "\t\t\treturn \"hello\";", - "utLineHits": 1, - "itLineHits": 0 + "utLineHits": 1 }, { "line": 12, - "code": "\t\t} else {", + "code": "\t\t} else {" }, { "line": 13, "code": "\t\t\tthrow new IllegalStateException();", - "utLineHits": 0, - "itLineHits": 1 + "utLineHits": 1 }, { "line": 14, - "code": "\t\t}", + "code": "\t\t}" }, { "line": 15, - "code": "\t}", + "code": "\t}" }, { "line": 16, - "code": "}", + "code": "}" }, { "line": 17, - "code": "", + "code": "" } ] diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReader.java index a54a20f6e8a..1f3fdedbf5f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReader.java @@ -23,11 +23,8 @@ import java.util.Iterator; import javax.annotation.CheckForNull; import org.sonar.db.protobuf.DbFileSources; import org.sonar.scanner.protocol.output.ScannerReport; -import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItCoveredConditionsCase; -import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItHitsCase; -import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasOverallCoveredConditionsCase; -import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtCoveredConditionsCase; -import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtHitsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasCoveredConditionsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasHitsCase; public class CoverageLineReader implements LineReader { @@ -43,39 +40,28 @@ public class CoverageLineReader implements LineReader { ScannerReport.LineCoverage reportCoverage = getNextLineCoverageIfMatchLine(lineBuilder.getLine()); if (reportCoverage != null) { processUnitTest(lineBuilder, reportCoverage); - processIntegrationTest(lineBuilder, reportCoverage); processOverallTest(lineBuilder, reportCoverage); coverage = null; } } private static void processUnitTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS) { - lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0); + if (reportCoverage.getHasHitsCase() == HasHitsCase.HITS) { + lineBuilder.setUtLineHits(reportCoverage.getHits() ? 1 : 0); } - if (reportCoverage.getHasUtCoveredConditionsCase() == HasUtCoveredConditionsCase.UT_COVERED_CONDITIONS) { + if (reportCoverage.getHasCoveredConditionsCase() == HasCoveredConditionsCase.COVERED_CONDITIONS) { lineBuilder.setUtConditions(reportCoverage.getConditions()); - lineBuilder.setUtCoveredConditions(reportCoverage.getUtCoveredConditions()); - } - } - - private static void processIntegrationTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - if (reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) { - lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0); - } - if (reportCoverage.getHasItCoveredConditionsCase() == HasItCoveredConditionsCase.IT_COVERED_CONDITIONS) { - lineBuilder.setItConditions(reportCoverage.getConditions()); - lineBuilder.setItCoveredConditions(reportCoverage.getItCoveredConditions()); + lineBuilder.setUtCoveredConditions(reportCoverage.getCoveredConditions()); } } private static void processOverallTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS || reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) { - lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0); + if (reportCoverage.getHasHitsCase() == HasHitsCase.HITS) { + lineBuilder.setOverallLineHits(reportCoverage.getHits() ? 1 : 0); } - if (reportCoverage.getHasOverallCoveredConditionsCase() == HasOverallCoveredConditionsCase.OVERALL_COVERED_CONDITIONS) { + if (reportCoverage.getHasCoveredConditionsCase() == HasCoveredConditionsCase.COVERED_CONDITIONS) { lineBuilder.setOverallConditions(reportCoverage.getConditions()); - lineBuilder.setOverallCoveredConditions(reportCoverage.getOverallCoveredConditions()); + lineBuilder.setOverallCoveredConditions(reportCoverage.getCoveredConditions()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReaderTest.java index dede32111a5..7a756748e8d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/CoverageLineReaderTest.java @@ -34,11 +34,8 @@ public class CoverageLineReaderTest { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtHits(true) - .setUtCoveredConditions(2) - .setItHits(true) - .setItCoveredConditions(3) - .setOverallCoveredConditions(4) + .setHits(true) + .setCoveredConditions(2) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -46,11 +43,6 @@ public class CoverageLineReaderTest { assertThat(lineBuilder.getUtLineHits()).isEqualTo(1); assertThat(lineBuilder.getUtConditions()).isEqualTo(10); - assertThat(lineBuilder.getItLineHits()).isEqualTo(1); - assertThat(lineBuilder.getItConditions()).isEqualTo(10); - assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3); - assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1); - assertThat(lineBuilder.getOverallConditions()).isEqualTo(10); } // Some tools are only able to report condition coverage @@ -59,8 +51,7 @@ public class CoverageLineReaderTest { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtCoveredConditions(2) - .setItCoveredConditions(3) + .setCoveredConditions(2) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -69,10 +60,9 @@ public class CoverageLineReaderTest { assertThat(lineBuilder.hasUtLineHits()).isFalse(); assertThat(lineBuilder.getUtConditions()).isEqualTo(10); assertThat(lineBuilder.hasItLineHits()).isFalse(); - assertThat(lineBuilder.getItConditions()).isEqualTo(10); - assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3); assertThat(lineBuilder.hasOverallLineHits()).isFalse(); - assertThat(lineBuilder.hasOverallConditions()).isFalse(); + assertThat(lineBuilder.hasOverallConditions()).isTrue(); + assertThat(lineBuilder.getOverallConditions()).isEqualTo(10); } @Test @@ -80,8 +70,8 @@ public class CoverageLineReaderTest { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtHits(true) - .setUtCoveredConditions(2) + .setHits(true) + .setCoveredConditions(2) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -89,40 +79,20 @@ public class CoverageLineReaderTest { assertThat(lineBuilder.getUtLineHits()).isEqualTo(1); assertThat(lineBuilder.getUtConditions()).isEqualTo(10); + assertThat(lineBuilder.getUtCoveredConditions()).isEqualTo(2); assertThat(lineBuilder.hasItLineHits()).isFalse(); assertThat(lineBuilder.hasItConditions()).isFalse(); assertThat(lineBuilder.hasItCoveredConditions()).isFalse(); assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1); - assertThat(lineBuilder.hasOverallCoveredConditions()).isFalse(); - } - - @Test - public void set_coverage_only_it() { - CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() - .setLine(1) - .setConditions(10) - .setItHits(true) - .setItCoveredConditions(3) - .build()).iterator()); - - DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); - computeCoverageLine.read(lineBuilder); - - assertThat(lineBuilder.hasUtLineHits()).isFalse(); - assertThat(lineBuilder.hasUtConditions()).isFalse(); - assertThat(lineBuilder.getItLineHits()).isEqualTo(1); - assertThat(lineBuilder.getItConditions()).isEqualTo(10); - assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3); - assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1); - assertThat(lineBuilder.hasOverallConditions()).isFalse(); + assertThat(lineBuilder.hasOverallCoveredConditions()).isTrue(); + assertThat(lineBuilder.getOverallCoveredConditions()).isEqualTo(2); } @Test public void set_coverage_on_uncovered_lines() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) - .setUtHits(false) - .setItHits(false) + .setHits(false) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -130,8 +100,6 @@ public class CoverageLineReaderTest { assertThat(lineBuilder.hasUtLineHits()).isTrue(); assertThat(lineBuilder.getUtLineHits()).isEqualTo(0); - assertThat(lineBuilder.hasItLineHits()).isTrue(); - assertThat(lineBuilder.getItLineHits()).isEqualTo(0); assertThat(lineBuilder.hasOverallLineHits()).isTrue(); assertThat(lineBuilder.getOverallLineHits()).isEqualTo(0); } @@ -140,7 +108,7 @@ public class CoverageLineReaderTest { public void set_overall_line_hits_with_only_ut() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) - .setUtHits(true) + .setHits(true) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -153,7 +121,7 @@ public class CoverageLineReaderTest { public void set_overall_line_hits_with_only_it() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) - .setItHits(true) + .setHits(true) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -166,8 +134,7 @@ public class CoverageLineReaderTest { public void set_overall_line_hits_with_ut_and_it() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) - .setUtHits(true) - .setItHits(true) + .setHits(true) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -198,11 +165,8 @@ public class CoverageLineReaderTest { ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtHits(true) - .setUtCoveredConditions(2) - .setItHits(true) - .setItCoveredConditions(3) - .setOverallCoveredConditions(4) + .setHits(true) + .setCoveredConditions(2) .build() // No coverage info on line 2 ).iterator()); @@ -225,11 +189,8 @@ public class CoverageLineReaderTest { ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtHits(true) - .setUtCoveredConditions(2) - .setItHits(true) - .setItCoveredConditions(3) - .setOverallCoveredConditions(4) + .setHits(true) + .setCoveredConditions(2) .build() // No coverage info on line 2 ).iterator()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java index a203c3ea411..387241fce2f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistFileSourcesStepTest.java @@ -35,9 +35,9 @@ import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType; import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.duplication.Duplicate; import org.sonar.server.computation.task.projectanalysis.duplication.Duplication; import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryRule; @@ -138,11 +138,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest { reportReader.putCoverage(FILE_REF, newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(10) - .setUtHits(true) - .setUtCoveredConditions(2) - .setItHits(true) - .setItCoveredConditions(3) - .setOverallCoveredConditions(4) + .setHits(true) + .setCoveredConditions(2) .build())); underTest.execute(); @@ -156,12 +153,6 @@ public class PersistFileSourcesStepTest extends BaseStepTest { assertThat(data.getLines(0).getUtLineHits()).isEqualTo(1); assertThat(data.getLines(0).getUtConditions()).isEqualTo(10); assertThat(data.getLines(0).getUtCoveredConditions()).isEqualTo(2); - assertThat(data.getLines(0).hasItLineHits()).isTrue(); - assertThat(data.getLines(0).getItConditions()).isEqualTo(10); - assertThat(data.getLines(0).getItCoveredConditions()).isEqualTo(3); - assertThat(data.getLines(0).getOverallLineHits()).isEqualTo(1); - assertThat(data.getLines(0).getOverallConditions()).isEqualTo(10); - assertThat(data.getLines(0).getOverallCoveredConditions()).isEqualTo(4); } @Test 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<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> 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<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> 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<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> 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<LineCoverage> 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()); } diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto index f0ab94c1e2a..1c4c2752427 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -217,24 +217,12 @@ message LineCoverage { // Number of conditions to cover (if set, the value must be greater than 0) int32 conditions = 2; // Is the line has been touched by a unit test ? Returning false means that no test has touched this executable line. - oneof has_ut_hits { - bool ut_hits = 3; + oneof has_hits { + bool hits = 3; } - // Is the line has been touched by a integration test ? Returning false means that no test has touched this executable line. - oneof has_it_hits { - bool it_hits = 4; - } - // Number of conditions covered by unit tests - oneof has_ut_covered_conditions { - int32 ut_covered_conditions = 5; - } - // Number of conditions covered by integration tests - oneof has_it_covered_conditions { - int32 it_covered_conditions = 6; - } - // Number of conditions covered by overall tests - oneof has_overall_covered_conditions { - int32 overall_covered_conditions = 7; + // Number of conditions covered by tests + oneof has_covered_conditions { + int32 covered_conditions = 5; } } diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java index 98b7c7ac71d..5a5c5323caf 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java @@ -277,20 +277,14 @@ public class ScannerReportReaderTest { ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(1) - .setUtHits(true) - .setItHits(false) - .setUtCoveredConditions(1) - .setItCoveredConditions(1) - .setOverallCoveredConditions(1) + .setHits(true) + .setCoveredConditions(1) .build(), ScannerReport.LineCoverage.newBuilder() .setLine(2) .setConditions(5) - .setUtHits(false) - .setItHits(false) - .setUtCoveredConditions(4) - .setItCoveredConditions(5) - .setOverallCoveredConditions(5) + .setHits(false) + .setCoveredConditions(4) .build())); underTest = new ScannerReportReader(dir); @@ -298,11 +292,8 @@ public class ScannerReportReaderTest { ScannerReport.LineCoverage coverage = it.next(); assertThat(coverage.getLine()).isEqualTo(1); assertThat(coverage.getConditions()).isEqualTo(1); - assertThat(coverage.getUtHits()).isTrue(); - assertThat(coverage.getItHits()).isFalse(); - assertThat(coverage.getUtCoveredConditions()).isEqualTo(1); - assertThat(coverage.getItCoveredConditions()).isEqualTo(1); - assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1); + assertThat(coverage.getHits()).isTrue(); + assertThat(coverage.getCoveredConditions()).isEqualTo(1); } } diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java index c55abc01c9b..2bd380d55b5 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java @@ -272,11 +272,8 @@ public class ScannerReportWriterTest { ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(1) - .setUtHits(true) - .setItHits(false) - .setUtCoveredConditions(1) - .setItCoveredConditions(1) - .setOverallCoveredConditions(1) + .setHits(true) + .setCoveredConditions(1) .build())); assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isTrue(); |