Fix for OODT-929: EnvUtilities should only load environment variables one time and statically cache them.
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/26116853 Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/26116853 Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/26116853 Branch: refs/heads/master Commit: 261168532b918eacb41a3689b20f1fe196b3411b Parents: e55f2cd Author: Chris Mattmann <[email protected]> Authored: Tue Jul 5 10:57:46 2016 -0700 Committer: Lewis John McGibbney <[email protected]> Committed: Thu Mar 9 21:09:17 2017 -0800 ---------------------------------------------------------------------- CHANGES.txt | 9 ++++++++- .../org/apache/oodt/commons/exec/EnvUtilities.java | 16 ++++++++++------ .../apache/oodt/commons/exec/TestEnvUtilities.java | 9 +++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/26116853/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index d88b954..7d0b1b2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,13 @@ Apache OODT Change Log ====================== -Release 0.13 - 06/21/2016 + +Release 1.1 - Current Development + +* OODT-929 EnvUtilities should only load environment variables one time and + statically cache them (mattmann) + + +Release 1.0 - 06/21/2016 * OODT-925 - Update schema.xml field defs for SOLR 5.x * OODT-926 - Fix pom versioning http://git-wip-us.apache.org/repos/asf/oodt/blob/26116853/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java b/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java index 5e630a7..18fbf39 100644 --- a/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java +++ b/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java @@ -48,6 +48,14 @@ public final class EnvUtilities { private EnvUtilities() throws InstantiationException { throw new InstantiationException("Don't construct utility classes!"); } + + private final static Properties environment = new Properties(); + static{ + System.getenv().entrySet(); + for (Map.Entry<String, String> entry : System.getenv().entrySet()) { + environment.setProperty(entry.getKey(), entry.getValue()); + } + } /** * This method returns a particular named environment variable from the user's @@ -57,7 +65,7 @@ public final class EnvUtilities { * @return The environment variable value, as a String. */ public static String getEnv(String envVarName) { - return System.getenv(envVarName); + return environment.getProperty(envVarName); } /** @@ -67,11 +75,7 @@ public final class EnvUtilities { * @return The user's current environment, in a {@link Properties} object. */ public static Properties getEnv() { - Properties envProps = new Properties(); - for (Map.Entry<String, String> entry : System.getenv().entrySet()) { - envProps.setProperty(entry.getKey(), entry.getValue()); - } - return envProps; + return environment; } /** http://git-wip-us.apache.org/repos/asf/oodt/blob/26116853/commons/src/test/java/org/apache/oodt/commons/exec/TestEnvUtilities.java ---------------------------------------------------------------------- diff --git a/commons/src/test/java/org/apache/oodt/commons/exec/TestEnvUtilities.java b/commons/src/test/java/org/apache/oodt/commons/exec/TestEnvUtilities.java index 61d02dc..eaef9d9 100644 --- a/commons/src/test/java/org/apache/oodt/commons/exec/TestEnvUtilities.java +++ b/commons/src/test/java/org/apache/oodt/commons/exec/TestEnvUtilities.java @@ -124,4 +124,13 @@ public class TestEnvUtilities extends TestCase { assertEquals(userNameTest1,userNameTest2); } } + + public void testStaticEnvironment(){ + if(SystemUtils.IS_OS_UNIX){ + Properties env = EnvUtilities.getEnv(); + Properties env2 = EnvUtilities.getEnv(); + + assertEquals(env, env2); + } + } }
