-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathSystemPropertiesManager.java
More file actions
107 lines (86 loc) · 3.88 KB
/
Copy pathSystemPropertiesManager.java
File metadata and controls
107 lines (86 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.google.appengine.tools.development;
import com.google.appengine.api.utils.SystemProperty;
import com.google.appengine.api.utils.SystemProperty.Environment;
import com.google.appengine.api.utils.SystemProperty.Environment.Value;
import com.google.apphosting.utils.config.AppEngineConfigException;
import com.google.apphosting.utils.config.AppEngineWebXml;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;
public class SystemPropertiesManager
{
private static final Logger LOGGER = Logger.getLogger(SystemPropertiesManager.class.getName());
private final Map<String, File> propertyNameToFileMap;
private final Properties originalSystemProperties;
SystemPropertiesManager()
{
this.propertyNameToFileMap = new HashMap();
this.originalSystemProperties = new Properties();
this.originalSystemProperties.putAll(System.getProperties());
}
Properties getOriginalSystemProperties() {
Properties result = new Properties();
result.putAll(this.originalSystemProperties);
return result;
}
public void setAppengineSystemProperties(String release, String applicationId, String majorVersionId)
{
SystemProperty.environment.set(SystemProperty.Environment.Value.Production);
if (release == null)
{
release = "null";
}
SystemProperty.version.set(release);
SystemProperty.applicationId.set(applicationId);
SystemProperty.applicationVersion.set(majorVersionId + ".1");
}
public synchronized void setSystemProperties(AppEngineWebXml appEngineWebXml, File appengineWebXmlFile) throws AppEngineConfigException
{
Map originalSystemProperties = copySystemProperties();
for (Map.Entry entry : appEngineWebXml.getSystemProperties().entrySet()) {
if ((this.propertyNameToFileMap.containsKey(entry.getKey())) && (!((String)entry.getValue()).equals(System.getProperty((String)entry.getKey()))) && (!((File)this.propertyNameToFileMap.get(entry.getKey())).equals(appengineWebXmlFile)))
{
String template = "Property %s is defined in %s and in %s with different values. Currently Java Development Server requires matching values.";
String message = String.format(template, new Object[] { entry.getKey(), appengineWebXmlFile.getAbsolutePath(), this.propertyNameToFileMap.get(entry.getKey()) });
LOGGER.severe(message);
throw new AppEngineConfigException(message);
}
if (originalSystemProperties.containsKey(entry.getKey())) {
String message = String.format("Overwriting system property key '%s', value '%s' with value '%s' from '%s'", new Object[] { entry.getKey(), originalSystemProperties.get(entry.getKey()), entry.getValue(), appengineWebXmlFile.getAbsolutePath() });
LOGGER.info(message);
}
}
Iterator iterator = this.propertyNameToFileMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry)iterator.next();
if (((File)entry.getValue()).equals(appengineWebXmlFile.getAbsolutePath())) {
iterator.remove();
}
}
for (Map.Entry entry : appEngineWebXml.getSystemProperties().entrySet()) {
this.propertyNameToFileMap.put((String)entry.getKey(), appengineWebXmlFile);
}
System.getProperties().putAll(appEngineWebXml.getSystemProperties());
}
public synchronized void restoreSystemProperties()
{
for (String key : this.propertyNameToFileMap.keySet()) {
System.clearProperty(key);
}
this.propertyNameToFileMap.clear();
System.getProperties().putAll(this.originalSystemProperties);
}
static Map<String, String> copySystemProperties()
{
HashMap copy = new HashMap();
for (String key : System.getProperties().stringPropertyNames()) {
copy.put(key, System.getProperties().getProperty(key));
}
return copy;
}
}