1 package org.codehaus.mojo.jaxb2.shared.environment.sysprops;
2
3 import org.apache.maven.plugin.logging.Log;
4 import org.codehaus.mojo.jaxb2.shared.environment.AbstractLogAwareFacet;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public final class SystemPropertySaveEnvironmentFacet extends AbstractLogAwareFacet {
20 private final String key;
21 private final String originalValue;
22
23
24
25
26
27
28
29
30 public SystemPropertySaveEnvironmentFacet(final String key, final Log log) {
31
32 super(log);
33
34
35 this.key = key;
36 this.originalValue = System.getProperty(key);
37 }
38
39
40
41
42 @Override
43 public void restore() {
44 if (originalValue != null) {
45 System.setProperty(key, originalValue);
46 } else {
47 System.clearProperty(key);
48 }
49
50 if (log.isDebugEnabled()) {
51 log.debug("Restored " + toString());
52 }
53 }
54
55
56
57
58 @Override
59 public void setup() {
60
61
62 if (log.isDebugEnabled()) {
63 log.debug("Setup " + toString());
64 }
65 }
66
67 @Override
68 public String toString() {
69 return "SysProp key [" + key + "], saved value: [" + originalValue + "]";
70 }
71 }