1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainInfo.java
CommitLineData
5f42a4ba 1/** @file\r
d2059d05 2ToolChainInfo class\r
3\r
4This file is to define ToolChainInfo class.\r
5f42a4ba 5\r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14**/\r
15\r
a29c47e0 16package org.tianocore.build.toolchain;\r
17\r
a29c47e0 18import java.util.LinkedHashSet;\r
a29c47e0 19import java.util.Set;\r
20\r
d2059d05 21/**\r
22 ToolChainInfo collects valid build targets, tool chain tag, ARCHs and commands \r
23 information for real build use.\r
24 **/\r
a29c47e0 25public class ToolChainInfo {\r
5f42a4ba 26 //\r
27 // build target set\r
28 // \r
a29c47e0 29 private Set<String> targets = new LinkedHashSet<String>();\r
5f42a4ba 30 //\r
31 // tool chain tag name set\r
32 // \r
a29c47e0 33 private Set<String> tagnames = new LinkedHashSet<String>();\r
5f42a4ba 34 //\r
35 // build archs set\r
36 // \r
a29c47e0 37 private Set<String> archs = new LinkedHashSet<String>();\r
5f42a4ba 38 //\r
39 // build commands set\r
40 // \r
a29c47e0 41 private Set<String> commands = new LinkedHashSet<String>();\r
d2059d05 42\r
5f42a4ba 43 /**\r
44 Add a list of targets in the form of string separated by space\r
45\r
46 @param targetList target list string\r
47 **/\r
a29c47e0 48 public void addTargets(String targetList) {\r
49 //\r
50 // targetList some targets separated by space " "\r
51 //\r
d2059d05 52 if (targetList == null || targetList.length() == 0) {\r
a29c47e0 53 targets.add("*");\r
d2059d05 54 } else {\r
55 addTargets(targetList.split(" "));\r
a29c47e0 56 }\r
a29c47e0 57 }\r
d2059d05 58\r
5f42a4ba 59 /**\r
60 Add a list of targets in the form of string array\r
61 \r
62 @param targetArray target string array\r
63 **/\r
a29c47e0 64 public void addTargets(String[] targetArray) {\r
d2059d05 65 if (targetArray != null ) {\r
66 for (int i = 0; i < targetArray.length; i++) {\r
67 targets.add(targetArray[i]);\r
68 }\r
a29c47e0 69 }\r
70 }\r
d2059d05 71\r
5f42a4ba 72 /**\r
73 Add a list of target in the form of set\r
74 \r
75 @param targetSet target string set\r
76 **/\r
a29c47e0 77 public void addTargets(Set<String> targetSet) {\r
d2059d05 78 if (targetSet != null) {\r
79 targets.addAll(targetSet);\r
80 }\r
a29c47e0 81 }\r
d2059d05 82\r
5f42a4ba 83 /**\r
84 Add a list of tool chain tag name in the form of string separated by space\r
85\r
d2059d05 86 @param tagnameList Tool chain tag name list string\r
5f42a4ba 87 **/\r
a29c47e0 88 public void addTagnames(String tagnameList) {\r
89 //\r
90 // tagnameList some tagnames separated by space " "\r
91 //\r
d2059d05 92 if (tagnameList == null || tagnameList.length() == 0) {\r
a29c47e0 93 tagnames.add("*");\r
d2059d05 94 } else {\r
95 addTagnames(tagnameList.split(" "));\r
a29c47e0 96 }\r
a29c47e0 97 }\r
d2059d05 98\r
99 /**\r
100 Add a list of tool chain tag name in the form of string array\r
101 \r
102 @param tagnameArray Tool chain tag names array\r
103 **/\r
a29c47e0 104 public void addTagnames(String[] tagnameArray) {\r
d2059d05 105 if (tagnameArray != null ) {\r
106 for (int i = 0; i < tagnameArray.length; i++) {\r
107 tagnames.add(tagnameArray[i]);\r
108 }\r
a29c47e0 109 }\r
110 }\r
d2059d05 111\r
112 /**\r
113 Add a list of tool chain tag name in the form of Set\r
114 \r
115 @param tagnameSet Tool chain tag names set\r
116 **/\r
a29c47e0 117 public void addTagnames(Set<String> tagnameSet) {\r
d2059d05 118 if (tagnameSet != null) {\r
119 tagnames.addAll(tagnameSet);\r
120 }\r
a29c47e0 121 }\r
d2059d05 122\r
123 /**\r
124 Add a list of ARCH in the form of string\r
125 \r
126 @param archList ARCH string\r
127 **/\r
a29c47e0 128 public void addArchs(String archList) {\r
129 //\r
130 // archList some archs separated by space " "\r
131 //\r
d2059d05 132 if (archList == null || archList.length() == 0) {\r
a29c47e0 133 archs.add("*");\r
d2059d05 134 } else {\r
135 addArchs(archList.split(" "));\r
a29c47e0 136 }\r
a29c47e0 137 }\r
d2059d05 138\r
139 /**\r
140 Add a list of ARCH in the form of string array\r
141 \r
142 @param archArray ARCH array\r
143 **/\r
a29c47e0 144 public void addArchs(String[] archArray) {\r
d2059d05 145 if (archArray != null ) {\r
146 for (int i = 0; i < archArray.length; i++) {\r
147 archs.add(archArray[i]);\r
148 }\r
a29c47e0 149 }\r
150 }\r
d2059d05 151\r
152 /**\r
153 Add a list of ARCH in the form of set\r
154 \r
155 @param archSet ARCH set\r
156 **/\r
a29c47e0 157 public void addArchs(Set<String> archSet) {\r
d2059d05 158 if (archSet != null) {\r
159 archs.addAll(archSet);\r
160 }\r
a29c47e0 161 }\r
d2059d05 162\r
163 /**\r
164 Add a list of command in the form of string\r
165 \r
166 @param commandList Command list string\r
167 **/\r
168 public void addCommands(String commandList) {\r
a29c47e0 169 //\r
170 // archList some archs separated by space " "\r
171 //\r
172 if (commandList == null || commandList.length() == 0) {\r
d2059d05 173 commands.add("*");\r
174 } else {\r
175 addCommands(commandList.split(" "));\r
a29c47e0 176 }\r
a29c47e0 177 }\r
d2059d05 178\r
179 /**\r
180 Add a list of ARCH in the form of array\r
181 \r
182 @param commandArray Commands array\r
183 **/\r
a29c47e0 184 public void addCommands(String[] commandArray) {\r
d2059d05 185 if (commandArray != null ) {\r
186 for (int i = 0; i < commandArray.length; i++) {\r
187 commands.add(commandArray[i]);\r
188 }\r
a29c47e0 189 }\r
190 }\r
a29c47e0 191\r
d2059d05 192 /**\r
193 Add a list of ARCH in the form of set\r
194 \r
195 @param commandSet Commands set\r
196 **/\r
197 public void addCommands(Set<String> commandSet) {\r
198 if (commandSet != null) {\r
199 commands.addAll(commandSet);\r
a29c47e0 200 }\r
a29c47e0 201 }\r
d2059d05 202\r
203 /**\r
204 Make a union operation on this ToolChainInfo and the given one.\r
205\r
206 @param info Another ToolChainInfo object to merge with\r
207 \r
208 @return ToolChainInfo Merged ToolChainInfo object\r
209 **/\r
a29c47e0 210 public ToolChainInfo union(ToolChainInfo info) {\r
211 ToolChainInfo result = new ToolChainInfo();\r
212 result.addTargets(union(this.targets, info.targets));\r
213 result.addTagnames(union(this.tagnames, info.tagnames));\r
214 result.addArchs(union(this.archs, info.archs));\r
a29c47e0 215 return result;\r
216 }\r
d2059d05 217\r
218 /**\r
219 Make a intersection operation on this ToolChainInfo and the given one\r
220\r
221 @param info Another ToolChainInfo object to intersect with\r
222 \r
223 @return ToolChainInfo Intersected ToolChainInfo object\r
224 **/\r
a29c47e0 225 public ToolChainInfo intersection(ToolChainInfo info) {\r
a29c47e0 226 ToolChainInfo result = new ToolChainInfo();\r
227 result.addTargets(intersection(this.targets, info.targets));\r
228 result.addTagnames(intersection(this.tagnames, info.tagnames));\r
229 result.addArchs(intersection(this.archs, info.archs));\r
a29c47e0 230 return result;\r
231 }\r
d2059d05 232\r
233 /**\r
234 Make a union operation on two Sets\r
235\r
236 @param set1 One Set\r
237 @param set2 Another Set\r
238 \r
239 @return Set<String> Merged Set object\r
240 **/\r
a29c47e0 241 private Set<String> union(Set<String> set1, Set<String> set2) {\r
242 Set<String> result = new LinkedHashSet<String>();\r
243 result.addAll(set1);\r
244 result.addAll(set2);\r
245 result.remove("*");\r
246 return result;\r
247 }\r
d2059d05 248\r
249 /**\r
250 Make a intersection operation on two Sets with the consideration of wildcard.\r
251\r
252 @param set1 One Set\r
253 @param set2 Another Set\r
254 \r
255 @return Set<String> The intersected Set object\r
256 **/\r
a29c47e0 257 private Set<String> intersection(Set<String> set1, Set<String> set2) {\r
258 Set<String> result = new LinkedHashSet<String>();\r
259 boolean set1HasWildcard = set1.contains("*");\r
260 boolean set2HasWildcard = set2.contains("*");\r
261\r
262 if (set1HasWildcard && set2HasWildcard) {\r
d2059d05 263 //\r
264 // Both Sets have wildcard, the result will have all elements in them\r
265 // \r
a29c47e0 266 result.addAll(set1);\r
267 result.addAll(set2);\r
268 } else if (set1HasWildcard) {\r
d2059d05 269 //\r
270 // Only set1 has wildcard, then result will have only set2 elements.\r
271 // \r
a29c47e0 272 result.addAll(set2);\r
273 } else if (set2HasWildcard) {\r
d2059d05 274 //\r
275 // Only set2 has wildcard, then result will have only set1 elements.\r
276 // \r
a29c47e0 277 result.addAll(set1);\r
278 } else {\r
d2059d05 279 //\r
280 // No wildcard in both Sets, the result will have the elements in both Sets.\r
281 // \r
a29c47e0 282 result.addAll(set1);\r
283 result.retainAll(set2);\r
284 }\r
285\r
a29c47e0 286 return result;\r
287 }\r
d2059d05 288\r
289 /**\r
290 Get target array.\r
291\r
292 @return String[]\r
293 **/\r
a29c47e0 294 public String[] getTargets() {\r
295 return (String[])targets.toArray(new String[targets.size()]);\r
296 }\r
d2059d05 297\r
298 /**\r
299 Get tool chain tag name array.\r
300\r
301 @return String[]\r
302 **/\r
a29c47e0 303 public String[] getTagnames() {\r
304 return (String[])tagnames.toArray(new String[tagnames.size()]);\r
305 }\r
d2059d05 306\r
307 /**\r
308 Get ARCH array.\r
309\r
310 @return String[]\r
311 **/\r
a29c47e0 312 public String[] getArchs() {\r
313 return (String[])archs.toArray(new String[archs.size()]);\r
314 }\r
315\r
d2059d05 316 /**\r
317 Get command name array.\r
318\r
319 @return String[]\r
320 **/\r
a29c47e0 321 public String[] getCommands() {\r
322 return (String[])commands.toArray(new String[commands.size()]);\r
323 }\r
324\r
d2059d05 325 /**\r
326 Override the Object's toString().\r
327\r
328 @return String\r
329 **/\r
a29c47e0 330 public String toString() {\r
caa44816 331 return " TARGET :" + targets + "\n" + \r
332 " TAGNAME:" + tagnames + "\n" + \r
333 " ARCH :" + archs + "\n" + \r
334 " COMMAND:" + commands;\r
a29c47e0 335 }\r
d2059d05 336\r
337 /**\r
338 Remove the wildcard element in the tool chain information because they\r
339 are useless when retrieved.\r
340 **/\r
a29c47e0 341 public void normalize() {\r
342 targets.remove("*");\r
343 tagnames.remove("*");\r
344 archs.remove("*");\r
345 commands.remove("*");\r
346 }\r
347}\r