aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2017-07-06 14:50:36 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-07-07 09:42:54 +0200
commit34ec38c33a375755fe97db021175d2008367bb90 (patch)
tree0736f5fba5f74f4af591065cd672bd9ebee11a14 /sonar-scanner-engine
parent3ccd84ac94178c482f78644630d623b92adf6e49 (diff)
downloadsonarqube-34ec38c33a375755fe97db021175d2008367bb90.tar.gz
sonarqube-34ec38c33a375755fe97db021175d2008367bb90.zip
SONAR-9198 Support comma in sonar.sources/sonar.tests
Add a medium test
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java8
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java33
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java14
3 files changed, 49 insertions, 6 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
index f642396ddea..8026c29d579 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
@@ -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];
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
index e369aefeb05..b2d4722cf1c 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
@@ -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);
+ }
+
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
index 1b63100e7d1..bcc57c46c15 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
@@ -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