Repository: incubator-tamaya Updated Branches: refs/heads/configjsr 6ddfdf923 -> 2bebc0e4e
Added JSR feature of special environment variable resolution handling. Signed-off-by: Anatole Tresch <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/cf11395a Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/cf11395a Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/cf11395a Branch: refs/heads/configjsr Commit: cf11395a5d90c65333e9531e93f8b93aa8791df7 Parents: 6ddfdf9 Author: Anatole Tresch <[email protected]> Authored: Tue Jun 5 11:27:45 2018 +0200 Committer: Anatole Tresch <[email protected]> Committed: Tue Jun 5 11:27:45 2018 +0200 ---------------------------------------------------------------------- .../configsource/EnvironmentConfigSource.java | 30 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cf11395a/code/base/src/main/java/org/apache/tamaya/base/configsource/EnvironmentConfigSource.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/configsource/EnvironmentConfigSource.java b/code/base/src/main/java/org/apache/tamaya/base/configsource/EnvironmentConfigSource.java index 2e45bb0..b9e42ab 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/configsource/EnvironmentConfigSource.java +++ b/code/base/src/main/java/org/apache/tamaya/base/configsource/EnvironmentConfigSource.java @@ -80,6 +80,21 @@ import java.util.Map; * * <p>The output of application would be {@code moon}.</p> * + * <h1>Environment Variable Resolution</h1> + * + * <p>As defined in the current configuration JSR, the environment config source will + * use an enhanced resolution mechanism to handle some constraints of operating + * systems not being able to handle dots in environment variable keys: + * + * Depending on the operating system type, environment variables with . are not always allowed. This ConfigSource searches 3 environment variables for a given property name (e.g. com.ACME.size): + * <ol> + * <li>Exact match (i.e. com.ACME.size)</li> + * <li>Replace all . by _ (i.e. com_ACME_size)</li> + * <li>Replace all . by _ and convert to upper case (i.e. COM_ACME_SIZE)</li> + * </ol> + * The first environment variable that is found is returned by this ConfigSource. + * </p> + * * <h1>Disabling the access to environment variables</h1> * * <p>The access to environment variables could be simply @@ -195,9 +210,20 @@ public class EnvironmentConfigSource extends BaseConfigSource { if (isDisabled()) { return null; } + // Exact match (i.e. com.ACME.size) String effectiveKey = hasPrefix() ? getPrefix() + "." + key - : key; - return getPropertiesProvider().getenv(effectiveKey); + : key; + String value = getPropertiesProvider().getenv(effectiveKey); + // Replace all . by _ (i.e. com_ACME_size) + if(value==null){ + value = getPropertiesProvider().getenv(effectiveKey.replaceAll(".", "_")); + } + // Replace all . by _ and convert to upper case (i.e. COM_ACME_SIZE) + if(value==null){ + value = getPropertiesProvider().getenv(effectiveKey.replaceAll(".", "_") + .toUpperCase()); + } + return value; } private boolean hasPrefix() {
