]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8623 Index all source files, even the ones with no supported language
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 7 Mar 2017 16:55:18 +0000 (17:55 +0100)
committerJulien HENRY <henryju@yahoo.fr>
Wed, 8 Mar 2017 09:41:56 +0000 (10:41 +0100)
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java

index 238880b78af822d90014fdbb6de68228cd902e5e..535708283d282ea2fac7d39b6691cb1553a23547 100644 (file)
@@ -82,7 +82,7 @@ public class MeasuresPublisher implements ReportPublisherStep {
   public void publish(ScannerReportWriter writer) {
     final ScannerReport.Measure.Builder builder = ScannerReport.Measure.newBuilder();
 
-    for (final InputComponent c : componentStore.all()) {
+    for (final InputComponent c : componentStore.allFilesToPublish()) {
       DefaultInputComponent component = (DefaultInputComponent) c;
       // Recompute all coverage measures from line data to take into account the possible merge of several reports
       updateCoverageFromLineData(component);
index 96e8df3f64d3f03267ed443959b308c559d4ac59..a5670e4aeeb6ad01f283ccf446e11a5accf0b4ab 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.scanner.mediumtest.fs;
 
 import com.google.common.collect.ImmutableMap;
+
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -215,6 +217,7 @@ public class FileSystemMediumTest {
     assertThat(logs.getAllAsString()).contains("2 files indexed");
     assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata");
     assertThat(logs.getAllAsString()).doesNotContain("'src/sample.java' generated metadata");
+
   }
 
   @Test
@@ -246,25 +249,33 @@ public class FileSystemMediumTest {
   public void dontPublishFilesWithoutDetectedLanguage() throws IOException {
     builder = createBuilder();
 
-    File srcDir = new File(baseDir, "src");
-    srcDir.mkdir();
+    Path mainDir = baseDir.toPath().resolve("src").resolve("main");
+    Files.createDirectories(mainDir);
 
-    File xooFile = new File(srcDir, "sample.xoo");
-    FileUtils.write(xooFile, "Sample xoo\ncontent");
+    Path testDir = baseDir.toPath().resolve("src").resolve("test");
+    Files.createDirectories(testDir);
+    
+    Path testXooFile = testDir.resolve("sample.java");
+    Files.write(testXooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
+    
+    Path xooFile = mainDir.resolve("sample.xoo");
+    Files.write(xooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
 
-    File javaFile = new File(srcDir, "sample.java");
-    FileUtils.write(javaFile, "Sample xoo\ncontent");
+    Path javaFile = mainDir.resolve("sample.java");
+    Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
 
     TaskResult result = tester.newTask()
       .properties(builder
-        .put("sonar.sources", "src")
+        .put("sonar.sources", "src/main")
+        .put("sonar.tests", "src/test")
         .build())
       .start();
 
-    assertThat(logs.getAllAsString()).contains("2 files indexed");
-    assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata");
-    assertThat(logs.getAllAsString()).doesNotContain("'src/sample.java' generated metadata");
-    DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/sample.java");
+    assertThat(logs.getAllAsString()).contains("3 files indexed");
+    assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata");
+    assertThat(logs.getAllAsString()).doesNotContain("'src/main/sample.java' generated metadata");
+    assertThat(logs.getAllAsString()).doesNotContain("'src/test/sample.java' generated metadata");
+    DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
     assertThat(result.getReportComponent(javaInputFile.key())).isNull();
   }