com.github.sitture.env.config.EnvironmentVariables Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of env-config Show documentation
Show all versions of env-config Show documentation
A simple utility to manage environment configs in Java-based projects by merging *.properties files with environment variables overrides.
package com.github.sitture.env.config;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.MapConfiguration;
import org.apache.commons.configuration2.SystemConfiguration;
class EnvironmentVariables {
private static Configuration systemConfiguration;
private static Configuration environmentConfiguration;
EnvironmentVariables() {
systemConfiguration = new SystemConfiguration();
environmentConfiguration = new MapConfiguration(getEnvMap());
}
Configuration getSystemConfiguration() {
return systemConfiguration;
}
Configuration getEnvironmentConfiguration() {
return environmentConfiguration;
}
private static Map getEnvMap() {
Map envMap = new HashMap();
System.getenv().entrySet().forEach(entry -> {
envMap.put(entry.getKey(), entry.getValue());
envMap.put(getProcessedEnvKey(entry.getKey()), entry.getValue());
});
return envMap;
}
private static String getProcessedEnvKey(final String envVar) {
return envVar.replaceAll("_", ".").toLowerCase();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy