Skip to content

Commit

Permalink
Removes duplicate exception from EnvConfigLoader (#84)
Browse files Browse the repository at this point in the history
## 1.2.2

### Fixed

- Removes duplicate exception from EnvConfigLoader
  • Loading branch information
haroon-sheikh authored Sep 16, 2022
1 parent b594080 commit 6642465
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.2.2

### Fixed

- Removes duplicate exception from EnvConfigLoader

## 1.2.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.github.sitture</groupId>
<artifactId>env-config</artifactId>
<packaging>jar</packaging>
<version>1.2.1</version>
<version>1.2.2</version>

<name>env-config</name>
<description>A simple utility to manage environment configs in Java-based projects by merging *.properties files with environment variables overrides.</description>
Expand Down
44 changes: 21 additions & 23 deletions src/main/java/com/github/sitture/envconfig/EnvConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,15 @@ private void loadEnvConfigurations(final List<String> envs) {
LOG.debug("Loading properties from system.properties");
this.configuration.addConfiguration(envVars.getSystemConfiguration());
final Configuration envOverrides = envVars.getEnvironmentConfiguration();

if (envs.size() > MIN_ENVIRONMENTS) {
try {
for (final File file : new EnvConfigFileList(configProperties.getConfigPath(EnvConfigUtils.CONFIG_ENV_DEFAULT)).listFiles()) {
final Configuration defaultConfig = new Configurations().properties(file);
defaultConfig.getKeys().forEachRemaining(property -> {
if (envOverrides.containsKey(property)
&& envOverrides.getProperty(property).equals(defaultConfig.getProperty(property))) {
envOverrides.clearProperty(property);
}
});
}
} catch (ConfigurationException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Could not load configuration files. \n {}", e.getMessage());
}
for (final File file : new EnvConfigFileList(configProperties.getConfigPath(EnvConfigUtils.CONFIG_ENV_DEFAULT)).listFiles()) {
final Configuration properties = getConfigurationProperties(file);
properties.getKeys().forEachRemaining(property -> {
if (envOverrides.containsKey(property)
&& envOverrides.getProperty(property).equals(properties.getProperty(property))) {
envOverrides.clearProperty(property);
}
});
}
}
LOG.debug("Loading properties from system.env");
Expand All @@ -80,18 +73,23 @@ private void loadFileConfigurations(final EnvConfigFileList fileList) {

private Map<String, Object> getFileConfigurationMap(final File file) {
final Map<String, Object> configurationMap = new HashMap<>();
final Configuration properties = getConfigurationProperties(file);
properties.getKeys().forEachRemaining(key -> {
final Object value = properties.getProperty(key);
configurationMap.put(key, value);
configurationMap.put(EnvConfigUtils.getProcessedEnvKey(key), value);
});
return configurationMap;
}

private Configuration getConfigurationProperties(final File file) {
final Configuration configurationProperties;
try {
LOG.debug("Loading properties from {}", file);
final Configuration config = new Configurations().properties(file);
config.getKeys().forEachRemaining(key -> {
final Object value = config.getProperty(key);
configurationMap.put(key, value);
configurationMap.put(EnvConfigUtils.getProcessedEnvKey(key), value);
});
configurationProperties = new Configurations().properties(file);
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
return configurationMap;
return configurationProperties;
}

}

0 comments on commit 6642465

Please sign in to comment.