]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/PropertyManager.java
4 PropertyManager class wraps Project.setProperty and tracks overrided properties.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.build
.global
;
17 import java
.util
.HashMap
;
18 import java
.util
.Hashtable
;
19 import java
.util
.Iterator
;
21 import java
.util
.Stack
;
23 import org
.apache
.tools
.ant
.Project
;
24 import org
.apache
.tools
.ant
.PropertyHelper
;
27 PropertyManager uses a incremental way to to track overrided properties when
28 setProperty. This is useful for property recovery in nestly calling build files.
29 Another functionality of this class is to prevent warning message printed when
30 building with "verbose" mode.
32 public class PropertyManager
{
34 // Property table stack, keeps track the history of properties changes
36 private static Stack
<HashMap
<String
, String
>> propertyTableStack
= new Stack
<HashMap
<String
, String
>>();
38 // The very original properties
40 private static HashMap
<String
, String
> orgPropertyTable
= null;
42 // The last changes of properties
44 private static HashMap
<String
, String
> oldPropertyTable
= null;
46 // The current changes of properties
48 private static HashMap
<String
, String
> bakPropertyTable
= null;
50 // The Project of tracking properties
52 private static Project prj
= null;
54 // PropertyHelper of this project for setting property quietly
56 private static PropertyHelper ph
= null;
59 Backup properties that have been overrided onto the stack for later recovery.
61 public static void save() {
63 // If this is the first time to save properties changes, keep all properties
64 // of this project as the original property table.
66 if (orgPropertyTable
== null) {
67 Hashtable prjProperties
= prj
.getProperties();
68 orgPropertyTable
= new HashMap
<String
, String
>();
70 Set keys
= prjProperties
.keySet();
71 Iterator iter
= keys
.iterator();
72 while (iter
.hasNext()) {
73 String item
= (String
)iter
.next();
74 orgPropertyTable
.put(item
, (String
)prjProperties
.get(item
));
79 // If there're already overrided properties, push it onto stack; otherwise
80 // prepare taking new overrided property by allocating space for it.
82 if (bakPropertyTable
!= null) {
83 propertyTableStack
.push(bakPropertyTable
);
84 oldPropertyTable
= bakPropertyTable
;
86 oldPropertyTable
= orgPropertyTable
;
88 bakPropertyTable
= new HashMap
<String
, String
>();
92 Restore the properties backup
94 public static void restore() {
95 if (bakPropertyTable
== null) {
97 // No properties backup, do nothing
101 Set keys
= bakPropertyTable
.keySet();
104 // Re-set properties in backup
106 Iterator iter
= keys
.iterator();
107 while (iter
.hasNext()) {
108 String name
= (String
)iter
.next();
109 String value
= (String
)bakPropertyTable
.get(name
);
110 ph
.setProperty(null, name
, value
, false);
114 // If there's backup history, get top one for next recovery
116 if (propertyTableStack
.size() > 0) {
117 bakPropertyTable
= (HashMap
<String
, String
>)propertyTableStack
.pop();
119 bakPropertyTable
= null; // no recovery any more
123 // Determine last overrided properties for incremental judgement
125 if (propertyTableStack
.size() == 0) {
126 oldPropertyTable
= orgPropertyTable
;
128 oldPropertyTable
= (HashMap
<String
, String
>)propertyTableStack
.peek();
133 Set current Project for save() and restore() use.
137 public static void setProject(Project prj
) {
138 PropertyManager
.prj
= prj
;
139 PropertyManager
.ph
= PropertyHelper
.getPropertyHelper(prj
);
143 Set a property for current project. It will also be put into property
144 history record if the record table has been setup.
146 @param name Property name
147 @param value Property value
149 public static void setProperty(String name
, String value
) {
154 setProperty(prj
, name
, value
);
158 Set a property for current project. It will also be put into property
159 history record if the record table has been setup.
161 @param project The Project for which the property will be set
162 @param name Property name
163 @param value Property value
165 public static void setProperty(Project project
, String name
, String value
) {
166 if (project
== null) {
168 return; // a Project must be given; otherwise nothing can be set
174 // Using PropertyHelper to set a property can be quiet (no override
177 PropertyHelper
.getPropertyHelper(project
).setProperty(null, name
, value
, false);
180 // If no property override history record is found, do nothing further
182 if (oldPropertyTable
== null || bakPropertyTable
== null) {
187 // Put a copy of given property in history record.
189 String oldValue
= oldPropertyTable
.get(name
);
190 if (oldValue
== null) {
193 bakPropertyTable
.put(name
, oldValue
);