]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/PropertyManager.java
Added to fix the issue of many property override warning when build with -v option...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / PropertyManager.java
1 package org.tianocore.build.global;
2
3 import java.util.HashMap;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7 import java.util.Stack;
8
9 import org.apache.tools.ant.Project;
10 import org.apache.tools.ant.PropertyHelper;
11
12 public class PropertyManager {
13 private static Stack<HashMap<String, String>> propertyTableStack = new Stack<HashMap<String, String>>();
14 private static HashMap<String, String> orgPropertyTable = null;
15 private static HashMap<String, String> oldPropertyTable = null;
16 private static HashMap<String, String> bakPropertyTable = null;
17 private static Project prj = null;
18
19 public static void save() {
20 if (orgPropertyTable == null) {
21 Hashtable prjProperties = prj.getProperties();
22 orgPropertyTable = new HashMap<String, String>();
23
24 Set keys = prjProperties.keySet();
25 Iterator iter = keys.iterator();
26 while (iter.hasNext()) {
27 String item = (String)iter.next();
28 orgPropertyTable.put(item, (String)prjProperties.get(item));
29 }
30 }
31
32 if (bakPropertyTable != null) {
33 propertyTableStack.push(bakPropertyTable);
34 oldPropertyTable = bakPropertyTable;
35 } else {
36 oldPropertyTable = orgPropertyTable;
37 }
38 bakPropertyTable = new HashMap<String, String>();
39 }
40
41 public static void restore() {
42 if (bakPropertyTable == null) {
43 return;
44 }
45 Set keys = bakPropertyTable.keySet();
46
47 Iterator iter = keys.iterator();
48 while (iter.hasNext()) {
49 String name = (String)iter.next();
50 String value = (String)bakPropertyTable.get(name);
51 setProperty(prj, name, value);
52 }
53
54 if (propertyTableStack.size() > 0) {
55 bakPropertyTable = (HashMap<String, String>)propertyTableStack.pop();
56 } else {
57 bakPropertyTable = null;
58 }
59
60 if (propertyTableStack.size() == 0) {
61 oldPropertyTable = orgPropertyTable;
62 } else {
63 oldPropertyTable = (HashMap<String, String>)propertyTableStack.peek();
64 }
65 }
66
67 public static void setProject(Project prj) {
68 PropertyManager.prj = prj;
69 }
70
71 public static void setProperty(String name, String value) {
72 if (prj == null) {
73 return;
74 }
75
76 setProperty(prj, name, value);
77
78 if (oldPropertyTable == null || bakPropertyTable == null) {
79 return;
80 }
81
82 String oldValue = oldPropertyTable.get(name);
83 if (oldValue == null) {
84 oldValue = value;
85 }
86 bakPropertyTable.put(name, oldValue);
87 }
88
89 public static void setProperty(Project project, String name, String value) {
90 if (project == null) {
91 if (prj == null) {
92 return;
93 }
94 project = prj;
95 }
96
97 PropertyHelper.getPropertyHelper(project).setProperty(null, name, value, false);
98 }
99 }
100