]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9198 Support comma in sonar.sources/sonar.tests
authorJulien HENRY <henryju@yahoo.fr>
Thu, 6 Jul 2017 12:50:36 +0000 (14:50 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 7 Jul 2017 07:42:54 +0000 (09:42 +0200)
Add a medium test

sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java

index f642396ddeaa325e3554950653216f9c8a183ec1..8026c29d5791bf8ab71056a43fc4a5456b9f69c9 100644 (file)
@@ -35,7 +35,6 @@ import java.util.Map.Entry;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
@@ -46,6 +45,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
 import org.sonar.scanner.analysis.AnalysisProperties;
 import org.sonar.scanner.bootstrap.DroppedPropertyChecker;
+import org.sonar.scanner.config.DefaultConfiguration;
 import org.sonar.scanner.util.ScannerUtils;
 
 /**
@@ -406,7 +406,11 @@ public class ProjectReactorBuilder {
    *
    */
   static String[] getListFromProperty(Map<String, String> properties, String key) {
-    return (String[]) ObjectUtils.defaultIfNull(StringUtils.stripAll(StringUtils.split(properties.get(key), ',')), new String[0]);
+    String propValue = properties.get(key);
+    if (propValue != null) {
+      return DefaultConfiguration.parseAsCsv(ProjectDefinition.SOURCES_PROPERTY, propValue);
+    }
+    return new String[0];
   }
 
 }
index e369aefeb05094843c8bd35ee35edd6c8d4fc8c7..b2d4722cf1c01852d4171a3a5aa942443ce7028d 100644 (file)
@@ -373,7 +373,7 @@ public class FileSystemMediumTest {
         .put("sonar.sources", "src")
         .build())
       .start();
-    
+
     assertThat(logs.getAllAsString()).containsOnlyOnce("- Exclusion pattern 'pattern'");
     assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' generating issue exclusions");
   }
@@ -674,4 +674,35 @@ public class FileSystemMediumTest {
     assertThat(result.inputDirs()).hasSize(4);
   }
 
+  @Test
+  public void scanProjectWithCommaInSourcePath() throws IOException {
+    File srcDir = new File(baseDir, "src");
+    srcDir.mkdir();
+
+    File xooFile = new File(srcDir, "sample,1.xoo");
+    FileUtils.write(xooFile, "Sample xoo\ncontent");
+
+    File xooFile2 = new File(baseDir, "another,2.xoo");
+    FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
+
+    File testDir = new File(baseDir, "test");
+    testDir.mkdir();
+
+    File xooTestFile = new File(testDir, "sampleTest,1.xoo");
+    FileUtils.write(xooTestFile, "Sample test xoo\ncontent");
+
+    File xooTestFile2 = new File(baseDir, "sampleTest,2.xoo");
+    FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
+
+    TaskResult result = tester.newTask()
+      .properties(builder
+        .put("sonar.sources", "src,\"another,2.xoo\"")
+        .put("sonar.tests", "\"test\",\"sampleTest,2.xoo\"")
+        .build())
+      .start();
+
+    assertThat(result.inputFiles()).hasSize(4);
+    assertThat(result.inputDirs()).hasSize(3);
+  }
+
 }
index 1b63100e7d16a708f0de3d34a025cebfd3bf3cb4..bcc57c46c15190688f494f8f6459da0a700b13c7 100644 (file)
@@ -535,8 +535,16 @@ public class ProjectReactorBuilderTest {
   public void shouldGetList() {
     Map<String, String> props = new HashMap<>();
 
-    props.put("prop", "  foo  ,,  bar  , \n\ntoto,tutu");
-    assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+    props.put("prop", "  foo  ,,  bar  , toto,tutu");
+    assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "", "bar", "toto", "tutu");
+  }
+
+  @Test
+  public void shouldGetListWithComma() {
+    Map<String, String> props = new HashMap<>();
+
+    props.put("prop", "\"foo,bar\",  toto,tutu");
+    assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo,bar", "toto", "tutu");
   }
 
   @Test
@@ -552,7 +560,7 @@ public class ProjectReactorBuilderTest {
     String filePath = "shouldGetList/foo.properties";
     Map<String, String> props = loadPropsFromFile(filePath);
 
-    assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+    assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu", "");
   }
 
   @Test