Commit 96b469b9 by amir

## 1.1.4: overriding config file properties with env

parent ae92bfbd
### general utils
## 1.1.4: overriding config file properties with env
## 1.2.3:
- add "mavenLocal", for local repository. enables to check this dependency locally
- Handle correctly Exceptions in http requsts/responses
......
group 'com.ipgallery.common'
version '1.1.3'
version '1.1.4'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -193,11 +193,18 @@ public class ConfigProperties
try
{
propFile = new FileInputStream(CONFIG_FILE_LOCATION);
Properties p = new Properties(System.getProperties());
p.load(propFile);
addPropertiesFromProviders(p);
Properties fileProperties = new Properties();
fileProperties.load(propFile);
Properties sysProperties = System.getProperties();
// Adding properties from file only if absent in env
fileProperties.entrySet().forEach(prop ->
sysProperties.putIfAbsent(prop.getKey(),prop.getValue()));
// Adding other providers properties - override system
configurationProviderList.forEach(provider ->
provider.getAllProperties().forEach(propEntry ->
sysProperties.setProperty(propEntry.getKey(),propEntry.getValue())));
// set the system properties
System.setProperties(p);
System.setProperties(sysProperties);
// display new properties
System.getProperties().list(System.out);
} catch (FileNotFoundException e)
......@@ -212,16 +219,6 @@ public class ConfigProperties
}
}
private void addPropertiesFromProviders(Properties p) {
for (IConfigurationProvider provider: configurationProviderList)
{
for (Entry<String, String> propEntry: provider.getAllProperties())
{
p.setProperty(propEntry.getKey(),propEntry.getValue());
}
}
}
public Object addConfigurationPropertyToHash(String key,String defaultValue, EnumPropertyType eType)
{
String valueStr = System.getProperty(key, defaultValue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment