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;
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;
/**
*
*/
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];
}
}
.put("sonar.sources", "src")
.build())
.start();
-
+
assertThat(logs.getAllAsString()).containsOnlyOnce("- Exclusion pattern 'pattern'");
assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' generating issue exclusions");
}
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);
+ }
+
}
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
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