aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-15 00:27:27 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-15 11:41:02 +0100
commitb665fb73e69b0cf7abcad3cac769ca4da0cb2dcf (patch)
treef3a8161deca2b9551e3a62f0027f7cbf9e44bc5f /sonar-plugin-api/src
parentfae66e786aa5ce4fecc1ea89f7da0bb872094295 (diff)
downloadsonarqube-b665fb73e69b0cf7abcad3cac769ca4da0cb2dcf.tar.gz
sonarqube-b665fb73e69b0cf7abcad3cac769ca4da0cb2dcf.zip
SONAR-3316 trim all the properties
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java15
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java15
2 files changed, 23 insertions, 7 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java
index 57047d6585c..70fc4012415 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java
@@ -173,9 +173,9 @@ public class Settings implements BatchComponent, ServerComponent {
public final Settings appendProperty(String key, String value) {
String newValue = properties.get(key);
if (StringUtils.isEmpty(newValue)) {
- newValue = value;
+ newValue = StringUtils.trim(value);
} else {
- newValue += "," + value;
+ newValue += "," + StringUtils.trim(value);
}
properties.put(key, newValue);
return this;
@@ -183,7 +183,7 @@ public class Settings implements BatchComponent, ServerComponent {
public final Settings setProperty(String key, String value) {
if (!clearIfNullValue(key, value)) {
- properties.put(key, value);
+ properties.put(key, StringUtils.trim(value));
}
return this;
}
@@ -221,13 +221,15 @@ public class Settings implements BatchComponent, ServerComponent {
}
public final Settings addProperties(Map<String, String> props) {
- properties.putAll(props);
+ for (Map.Entry<String, String> entry : props.entrySet()) {
+ setProperty(entry.getKey(), entry.getValue());
+ }
return this;
}
public final Settings addProperties(Properties props) {
for (Map.Entry<Object, Object> entry : props.entrySet()) {
- properties.put(entry.getKey().toString(), entry.getValue().toString());
+ setProperty(entry.getKey().toString(), entry.getValue().toString());
}
return this;
}
@@ -242,8 +244,7 @@ public class Settings implements BatchComponent, ServerComponent {
public final Settings setProperties(Map<String, String> props) {
properties.clear();
- properties.putAll(props);
- return this;
+ return addProperties(props);
}
public final Settings setProperty(String key, Date date, boolean includeTime) {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
index ee4c4e6e3d0..4e88f6c939d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.config;
+import com.google.common.collect.ImmutableMap;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
@@ -59,6 +60,20 @@ public class SettingsTest {
}
@Test
+ public void allValuesShouldBeTrimmed_set_property() {
+ Settings settings = new Settings();
+ settings.setProperty("foo", " FOO ");
+ assertThat(settings.getString("foo"), is("FOO"));
+ }
+
+ @Test
+ public void allValuesShouldBeTrimmed_set_properties() {
+ Settings settings = new Settings();
+ settings.setProperties(ImmutableMap.of("foo", " FOO "));
+ assertThat(settings.getString("foo"), is("FOO"));
+ }
+
+ @Test
public void testGetDefaultValue() {
Settings settings = new Settings(definitions);
assertThat(settings.getDefaultValue("unknown"), nullValue());