aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 20:28:40 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 20:33:35 +0200
commit6cc4d52f9791ad2547111543e41662c7522f89b8 (patch)
treef10b9fb8965965f5c8ef504f6634c05a86f561bf /sonar-plugin-api/src/main/java
parent6df8db4603834eeb4d3b897487650ff6348da1d5 (diff)
downloadsonarqube-6cc4d52f9791ad2547111543e41662c7522f89b8.tar.gz
sonarqube-6cc4d52f9791ad2547111543e41662c7522f89b8.zip
SONAR-3633 improve the management of server-side settings
* do not save default resource permissions in a db migration but in a server-side extension * new component to save settings from server-side components. It will have to be used by ruby app later.
Diffstat (limited to 'sonar-plugin-api/src/main/java')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java57
1 files changed, 23 insertions, 34 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 2b8423a67d7..5b118ecd4fc 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
@@ -210,43 +210,34 @@ public class Settings implements BatchComponent, ServerComponent {
} else {
newValue += "," + StringUtils.trim(value);
}
- properties.put(key, newValue);
- return this;
+ return setProperty(key, newValue);
}
public final Settings setProperty(String key, @Nullable String value) {
- if (!clearIfNullValue(key, value)) {
+ if (value == null) {
+ properties.remove(key);
+ doOnRemoveProperty(key);
+ } else {
properties.put(key, StringUtils.trim(value));
+ doOnSetProperty(key, value);
}
return this;
}
public final Settings setProperty(String key, @Nullable Boolean value) {
- if (!clearIfNullValue(key, value)) {
- properties.put(key, String.valueOf(value));
- }
- return this;
+ return setProperty(key, String.valueOf(value));
}
public final Settings setProperty(String key, @Nullable Integer value) {
- if (!clearIfNullValue(key, value)) {
- properties.put(key, String.valueOf(value));
- }
- return this;
+ return setProperty(key, String.valueOf(value));
}
public final Settings setProperty(String key, @Nullable Long value) {
- if (!clearIfNullValue(key, value)) {
- properties.put(key, String.valueOf(value));
- }
- return this;
+ return setProperty(key, String.valueOf(value));
}
public final Settings setProperty(String key, @Nullable Double value) {
- if (!clearIfNullValue(key, value)) {
- properties.put(key, String.valueOf(value));
- }
- return this;
+ return setProperty(key, String.valueOf(value));
}
public final Settings setProperty(String key, @Nullable Date date) {
@@ -276,24 +267,21 @@ public class Settings implements BatchComponent, ServerComponent {
}
public final Settings setProperties(Map<String, String> props) {
- properties.clear();
+ clear();
return addProperties(props);
}
public final Settings setProperty(String key, @Nullable Date date, boolean includeTime) {
- if (!clearIfNullValue(key, date)) {
- properties.put(key, includeTime ? DateUtils.formatDateTime(date) : DateUtils.formatDate(date));
- }
- return this;
+ return setProperty(key, includeTime ? DateUtils.formatDateTime(date) : DateUtils.formatDate(date));
}
public final Settings removeProperty(String key) {
- properties.remove(key);
- return this;
+ return setProperty(key, (String) null);
}
public final Settings clear() {
properties.clear();
+ doOnClearProperties();
return this;
}
@@ -308,14 +296,6 @@ public class Settings implements BatchComponent, ServerComponent {
return definitions;
}
- private boolean clearIfNullValue(String key, @Nullable Object value) {
- if (value == null) {
- properties.remove(key);
- return true;
- }
- return false;
- }
-
/**
* Create empty settings. Definition of available properties is loaded from the given annotated class.
* This method is usually used by unit tests.
@@ -323,4 +303,13 @@ public class Settings implements BatchComponent, ServerComponent {
public static Settings createForComponent(Object component) {
return new Settings(new PropertyDefinitions(component));
}
+
+ protected void doOnSetProperty(String key, @Nullable String value) {
+ }
+
+ protected void doOnRemoveProperty(String key) {
+ }
+
+ protected void doOnClearProperties() {
+ }
}