From de070c706ce286370c3e85d8285965200939ad1f Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 11 Mar 2019 14:25:31 -0500 Subject: [PATCH] SONAR-11795 Make metric 'executable_lines_data' available --- .../org/sonar/scanner/sensor/DefaultSensorStorage.java | 3 +-- .../scanner/mediumtest/coverage/CoverageMediumTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java index 42965a37d98..75a7806beab 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java @@ -179,9 +179,8 @@ public class DefaultSensorStorage implements SensorStorage { } else { throw new IllegalArgumentException("Executable lines can only be saved on files"); } - } else { - reportPublisher.getWriter().appendComponentMeasure(((DefaultInputComponent) component).scannerId(), toReportMeasure(measure)); } + reportPublisher.getWriter().appendComponentMeasure(((DefaultInputComponent) component).scannerId(), toReportMeasure(measure)); } public static ScannerReport.Measure toReportMeasure(DefaultMeasure measureToSave) { 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 4730fa8eadb..67659671c80 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 @@ -32,9 +32,11 @@ import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.mediumtest.AnalysisResult; import org.sonar.scanner.mediumtest.ScannerMediumTester; +import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.xoo.XooPlugin; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.tuple; public class CoverageMediumTest { @@ -280,6 +282,10 @@ public class CoverageMediumTest { assertThat(result.coverageFor(file, 3).getHits()).isFalse(); assertThat(result.coverageFor(file, 4)).isNull(); + + assertThat(result.allMeasures().get(file.key())) + .extracting(ScannerReport.Measure::getMetricKey, m -> m.getStringValue().getValue()) + .contains(tuple("executable_lines_data", "2=1;3=1;4=0")); } // SONAR-11641 @@ -294,7 +300,8 @@ public class CoverageMediumTest { File measuresFile = new File(srcDir, "sample.xoo.measures"); File coverageFile = new File(srcDir, "sample.xoo.coverage"); FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); - FileUtils.write(measuresFile, "# The code analyzer disagree with the coverage tool and consider some lines to be executable\nexecutable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8); + FileUtils.write(measuresFile, "# The code analyzer disagree with the coverage tool and consider some lines to be executable\nexecutable_lines_data:2=1;3=1;4=0", + StandardCharsets.UTF_8); FileUtils.write(coverageFile, "# No lines to cover in this file according to the coverage tool", StandardCharsets.UTF_8); AnalysisResult result = tester.newAnalysis() -- 2.39.5