Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / EnvProxy.java
blob07bb4183796925318048c0433fd6654c15e57d71
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 private EnvProxy() {}
18 /**
19 * Updates to {@code envOverride} made after calling this method will not be
20 * reflected in calls to {@link #getenv(String)}.
22 static synchronized void setEnvOverrideForTest(Map<String, String> envOverride) {
23 EnvProxy.envOverride = ImmutableMap.copyOf(envOverride);
26 static synchronized void clearEnvOverrideForTest() {
27 envOverride = null;
30 static String getenv(String name) {
31 synchronized (EnvProxy.class) {
32 if (envOverride != null) {
33 return envOverride.get(name);
36 try {
37 return System.getenv(name);
38 } catch (SecurityException e) {
39 return null;