Skip to content

Commit

Permalink
Move rationale to code and implement invalidate cache
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Mar 21, 2019
1 parent 4571c79 commit 87dc17d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,6 @@ With this option enabled only environment variables starting with
i.e. The environment variable `CONFIG_FORCE_a_b__c___d` set the
configuration key `a.b-c_d`

Rationale the name mangling:

Most shells (e.g. bash, sh, etc.) doesn't support any character other
than alphanumeric and `_` in environment variables names.
In HOCON the default separator is `.` so it is directly translated to a
single `_` for convenience; `-` and `_` are less often present in config
keys but they have to be representable and the only possible mapping is
`_` repeated.

### Concatenation

Values _on the same line_ are concatenated (for strings and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public static void invalidateCaches() {
// all caches
ConfigImpl.reloadSystemPropertiesConfig();
ConfigImpl.reloadEnvVariablesConfig();
ConfigImpl.reloadEnvVariablesOverridesConfig();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions config/src/main/java/com/typesafe/config/impl/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ public static void reloadEnvVariablesConfig() {
private static AbstractConfigObject loadEnvVariablesOverrides() {
Map<String, String> env = new HashMap(System.getenv());
Map<String, String> result = new HashMap(System.getenv());
// Rationale on name mangling:
//
// Most shells (e.g. bash, sh, etc.) doesn't support any character other
// than alphanumeric and `_` in environment variables names.
// In HOCON the default separator is `.` so it is directly translated to a
// single `_` for convenience; `-` and `_` are less often present in config
// keys but they have to be representable and the only possible mapping is
// `_` repeated.
for (String key : env.keySet()) {
if (key.startsWith(ENV_VAR_OVERRIDE_PREFIX)) {
StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -412,6 +420,12 @@ public static Config envVariablesOverridesAsConfig() {
return envVariablesOverridesAsConfigObject().toConfig();
}

public static void reloadEnvVariablesOverridesConfig() {
// ConfigFactory.invalidateCaches() relies on this having the side
// effect that it drops all caches
EnvVariablesOverridesHolder.envVariables = loadEnvVariablesOverrides();
}

public static Config defaultReference(final ClassLoader loader) {
return computeCachedConfig(loader, "defaultReference", new Callable<Config>() {
@Override
Expand Down

0 comments on commit 87dc17d

Please sign in to comment.