]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11795 Make metric 'executable_lines_data' available
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 11 Mar 2019 19:25:31 +0000 (14:25 -0500)
committerSonarTech <sonartech@sonarsource.com>
Tue, 12 Mar 2019 19:20:54 +0000 (20:20 +0100)
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java

index 42965a37d98155380e316c2f967877fbd91c4200..75a7806beab7798385afc1b1d777797e542c922d 100644 (file)
@@ -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) {
index 4730fa8eadbf7fb288e318788ea2195a4fed154b..67659671c80c7773f3dcc650b718b8a2270db110 100644 (file)
@@ -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()