Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / EnvProxy.java
blob7001b93b33024c2fd7f0bf7924083c9b2783cf85
1 package com.google.appengine.api.datastore;
3 import com.google.common.collect.ImmutableMap;
5 import java.util.Map;
7 /**
8 * Proxy around System.getenv() to enable testing and prevent errors in
9 * situations where the security manager does not allow access to environment
10 * variables.
12 class EnvProxy {
14 private static ImmutableMap<String, String> envOverride;
16 /**
17 * Updates to {@code envOverride} made after calling this method will not be
18 * reflected in calls to {@link #getenv(String)}.
20 static synchronized void setEnvOverrideForTest(Map<String, String> envOverride) {
21 EnvProxy.envOverride = ImmutableMap.copyOf(envOverride);
24 static synchronized void clearEnvOverrideForTest() {
25 envOverride = null;
28 static String getenv(String name) {
29 synchronized (EnvProxy.class) {
30 if (envOverride != null) {
31 return envOverride.get(name);
34 try {
35 return System.getenv(name);
36 } catch (SecurityException e) {
37 return null;