aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java31
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java11
3 files changed, 25 insertions, 26 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
index 8aae3ed9289..58820d07115 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
@@ -93,20 +93,23 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
categories.put(definition.getKey(), StringUtils.defaultIfBlank(definition.getCategory(), defaultCategory));
if (!Strings.isNullOrEmpty(definition.getDeprecatedKey()) && !definition.getDeprecatedKey().equals(definition.getKey())) {
deprecatedKeys.put(definition.getDeprecatedKey(), definition.getKey());
- definitions.put(definition.getDeprecatedKey(), definition);
}
}
return this;
}
public PropertyDefinition get(String key) {
- return definitions.get(key);
+ return definitions.get(validKey(key));
}
public Collection<PropertyDefinition> getAll() {
return definitions.values();
}
+ public String validKey(String key) {
+ return StringUtils.defaultString(deprecatedKeys.get(key), key);
+ }
+
static enum PropertyDefinitionFilter {
GLOBAL {
@Override
@@ -172,7 +175,7 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
}
public String getCategory(String key) {
- return categories.get(key);
+ return categories.get(validKey(key));
}
public String getCategory(Property prop) {
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 c3c6f46fc9e..74b1436aafb 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
@@ -107,9 +107,10 @@ public class Settings implements BatchComponent, ServerComponent {
* Does not decrypt value.
*/
protected String getClearString(String key) {
- String value = properties.get(key);
+ String validKey = definitions.validKey(key);
+ String value = properties.get(validKey);
if (value == null) {
- value = getDefaultValue(key);
+ value = getDefaultValue(validKey);
}
return value;
}
@@ -247,7 +248,7 @@ public class Settings implements BatchComponent, ServerComponent {
}
public final Settings appendProperty(String key, String value) {
- String newValue = properties.get(key);
+ String newValue = properties.get(definitions.validKey(key));
if (StringUtils.isEmpty(newValue)) {
newValue = StringUtils.trim(value);
} else {
@@ -280,27 +281,13 @@ public class Settings implements BatchComponent, ServerComponent {
}
public final Settings setProperty(String key, @Nullable String value) {
- return setProperty(key, value, true);
- }
-
- private Settings setProperty(String key, @Nullable String value, boolean recursive) {
+ String validKey = definitions.validKey(key);
if (value == null) {
- properties.remove(key);
- doOnRemoveProperty(key);
+ properties.remove(validKey);
+ doOnRemoveProperty(validKey);
} else {
- properties.put(key, StringUtils.trim(value));
- doOnSetProperty(key, value);
- }
- if (recursive) {
- String newKey = definitions.getNewKey(key);
- if (newKey != null) {
- setProperty(newKey, value, false);
- } else {
- String deprecatedKey = definitions.getDeprecatedKey(key);
- if (deprecatedKey != null) {
- setProperty(deprecatedKey, value, false);
- }
- }
+ properties.put(validKey, StringUtils.trim(value));
+ doOnSetProperty(validKey, value);
}
return this;
}
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 0993b09063f..745c28d0990 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
@@ -398,7 +398,7 @@ public class SettingsTest {
}
@Test
- public void should_load_value_set_on_deprecated_key() {
+ public void should_load_value_of_deprecated_key() {
// it's used for example when deprecated settings are set through command-line
Settings settings = new Settings(definitions);
settings.setProperty("oldKey", "value of oldKey");
@@ -408,6 +408,15 @@ public class SettingsTest {
}
@Test
+ public void should_load_values_of_deprecated_key() {
+ Settings settings = new Settings(definitions);
+ settings.setProperty("oldKey", "a,b");
+
+ assertThat(settings.getStringArray("newKey")).containsOnly("a", "b");
+ assertThat(settings.getStringArray("oldKey")).containsOnly("a", "b");
+ }
+
+ @Test
public void should_support_deprecated_props_with_multi_values() {
Settings settings = new Settings(definitions);
settings.setProperty("new_multi_values", new String[]{" A ", " B "});