import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
*
*/
static String[] getListFromProperty(Properties properties, String key) {
- String value = properties.getProperty(key, "");
+ String value = properties.getProperty(key, "").trim();
+ if (value.isEmpty()) {
+ return new String[0];
+ }
String[] values = value.split(",");
+ List<String> trimmedValues = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
- values[i] = values[i].trim();
+ String trimmedValue = values[i].trim();
+ if (!trimmedValue.isEmpty()) {
+ trimmedValues.add(trimmedValue);
+ }
}
- return values;
+ return trimmedValues.toArray(new String[trimmedValues.size()]);
}
}
*/
package org.sonar.runner.cli;
+import java.io.File;
+import java.util.Properties;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.runner.cli.Cli;
-import org.sonar.runner.cli.Conf;
-import java.io.File;
-import java.util.Properties;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2");
}
+ @Test
+ public void ignoreEmptyModule() throws Exception {
+ File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/emptyModules/project").toURI());
+ args.setProperty("project.home", temp.newFolder().getCanonicalPath());
+ args.setProperty("sonar.projectBaseDir", projectHome.getCanonicalPath());
+
+ conf.properties();
+ }
+
+ @Test
+ public void shouldGetList() {
+ Properties props = new Properties();
+
+ props.put("prop", " foo ,, bar , \n\ntoto,tutu");
+ assertThat(Conf.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+ }
+
}