This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit 06f4e118753e3fddb4454394c78c6e18a4529d05 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 10:43:16 2016 +0200 Do not store option value for value equals to default option (Fixes #1807) --- .../java/org/nuiton/config/ApplicationConfig.java | 58 +++++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfig.java b/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfig.java index 6af8fb4..fae7728 100644 --- a/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfig.java +++ b/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfig.java @@ -853,7 +853,7 @@ public class ApplicationConfig { * @return the system config file location * @throws ApplicationConfigFileNameNotInitializedException if no config file name found in configuration */ - public File getSystemConfigFile() throws ApplicationConfigFileNameNotInitializedException{ + public File getSystemConfigFile() throws ApplicationConfigFileNameNotInitializedException { String configFileName = getConfigFileName(); if (configFileName == null) { throw new ApplicationConfigFileNameNotInitializedException(); @@ -868,7 +868,7 @@ public class ApplicationConfig { * @return the user config file location * @throws ApplicationConfigFileNameNotInitializedException if no config file name found in configuration */ - public File getUserConfigFile() throws ApplicationConfigFileNameNotInitializedException{ + public File getUserConfigFile() throws ApplicationConfigFileNameNotInitializedException { String configFileName = getConfigFileName(); if (configFileName == null) { throw new ApplicationConfigFileNameNotInitializedException(); @@ -1411,16 +1411,46 @@ public class ApplicationConfig { * @param value property value */ public void setOption(String key, String value) { - Properties props; + + ApplicationConfigScope optionScope; + if (inParseOptionPhase) { - props = getProperties(ApplicationConfigScope.LINE); + optionScope = ApplicationConfigScope.LINE; } else { - props = getProperties(ApplicationConfigScope.OPTIONS); + optionScope = ApplicationConfigScope.OPTIONS; } + + boolean setOption = true; if (value == null) { - props.remove(key); + + setOption = false; + + } else { + + Properties defaults = getProperties(ApplicationConfigScope.DEFAULTS); + if (defaults != null) { + String defaultValue = defaults.getProperty(key); + if (defaultValue != null) { + defaultValue = replaceRecursiveOptions(defaultValue); + if (value.equals(defaultValue)) { + + // on supprime l'option, car c'est la valeur par défaut + setOption = false; + } + } + } + + } + + if (setOption) { + + getProperties(optionScope).setProperty(key, value); + } else { - props.setProperty(key, value); + + // delete from props, or home, or system if not found in previous scope + remove(key, optionScope, ApplicationConfigScope.HOME, ApplicationConfigScope.SYSTEM); + } } @@ -2324,6 +2354,20 @@ public class ApplicationConfig { return msg; } + protected void remove(String key, ApplicationConfigScope... scopes) { + for (ApplicationConfigScope scope : scopes) { + + Properties properties = getProperties(scope); + if (properties == null) { + continue; + } + Object remove = properties.remove(key); + if (remove != null) { + return; + } + } + } + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { pcs.firePropertyChange(propertyName, oldValue, newValue); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.