From 6cc4d52f9791ad2547111543e41662c7522f89b8 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 13 Jul 2012 20:28:40 +0200 Subject: 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. --- .../main/java/org/sonar/api/config/Settings.java | 57 +++++++++------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'sonar-plugin-api/src/main/java') 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 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() { + } } -- cgit v1.2.3