Adding a couple of features for far processing, including detecting duplicate files.
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / fpd / PlatformBuildFileGenerator.java
CommitLineData
a29c47e0 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 **/\r
12package org.tianocore.build.fpd;\r
13\r
14import java.io.File;\r
4b5f5549 15import java.util.HashMap;\r
a29c47e0 16import java.util.Iterator;\r
17import java.util.Map;\r
18import java.util.Set;\r
19\r
20import javax.xml.parsers.DocumentBuilder;\r
21import javax.xml.parsers.DocumentBuilderFactory;\r
22import javax.xml.transform.OutputKeys;\r
23import javax.xml.transform.Result;\r
24import javax.xml.transform.Source;\r
25import javax.xml.transform.Transformer;\r
26import javax.xml.transform.TransformerFactory;\r
27import javax.xml.transform.dom.DOMSource;\r
28import javax.xml.transform.stream.StreamResult;\r
29\r
30import org.apache.tools.ant.BuildException;\r
31import org.apache.tools.ant.Project;\r
32import org.tianocore.build.global.GlobalData;\r
33import org.tianocore.build.global.SurfaceAreaQuery;\r
34import org.tianocore.build.id.FpdModuleIdentification;\r
35import org.tianocore.build.id.ModuleIdentification;\r
36import org.w3c.dom.Comment;\r
37import org.w3c.dom.Document;\r
38import org.w3c.dom.Element;\r
8031d48d 39import org.w3c.dom.NamedNodeMap;\r
a29c47e0 40import org.w3c.dom.Node;\r
8031d48d 41import org.w3c.dom.NodeList;\r
a29c47e0 42\r
82516887 43/**\r
44 class PlatformBuildFileGenerator is used to generate ${PLATFORM}_build.xml file. \r
45\r
46 @since GenBuild 1.0\r
47**/\r
a29c47e0 48public class PlatformBuildFileGenerator {\r
49\r
a29c47e0 50 ///\r
51 /// Mapping from modules identification to out put file name\r
52 ///\r
53 private Map<FpdModuleIdentification, String> outfiles;\r
4b5f5549 54 \r
55 ///\r
56 /// Mapping from FV name to its modules\r
57 ///\r
58 private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
59\r
a29c47e0 60\r
a29c47e0 61 private boolean isUnified = true;\r
62 \r
83fba802 63 private SurfaceAreaQuery saq = null;\r
64 \r
02c768ee 65 private File platformBuildFile = null;\r
66 \r
380191dd 67 private Map<String, String> aprioriType = null;\r
68 \r
a29c47e0 69 private Project project;\r
70 \r
71 private String info = "DO NOT EDIT \n" \r
391dbbb1 72 + "This file is auto-generated by the build utility\n" \r
a29c47e0 73 + "\n" \r
74 + "Abstract:\n"\r
391dbbb1 75 + "Auto-generated ANT build file for building EFI Modules and Platforms\n";\r
a29c47e0 76\r
380191dd 77 public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile, Map<String, String> aprioriType){\r
a29c47e0 78 this.project = project;\r
79 this.outfiles = outfiles;\r
a29c47e0 80 this.isUnified = isUnified;\r
4b5f5549 81 this.fvs = fvs;\r
83fba802 82 this.saq = saq;\r
02c768ee 83 this.platformBuildFile = new File(platformBuildFile);\r
380191dd 84 this.aprioriType = aprioriType;\r
a29c47e0 85 }\r
86 \r
87 /**\r
88 Generate build.out.xml file.\r
89 \r
90 @throws BuildException\r
91 build.out.xml XML document create error\r
92 **/\r
93 public void genBuildFile() throws BuildException {\r
94 DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
95 try {\r
96 DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
97 Document document = dombuilder.newDocument();\r
98 Comment rootComment = document.createComment(info);\r
99 //\r
100 // create root element and its attributes\r
101 //\r
102 Element root = document.createElement("project");\r
103 root.setAttribute("name", project.getProperty("PLATFORM"));\r
104 root.setAttribute("default", "all");\r
105 root.setAttribute("basedir", ".");\r
106 \r
107 //\r
108 // element for External ANT tasks\r
109 //\r
110 root.appendChild(document.createComment("Apply external ANT tasks"));\r
111 Element ele = document.createElement("taskdef");\r
112 ele.setAttribute("resource", "GenBuild.tasks");\r
113 root.appendChild(ele);\r
114\r
115 ele = document.createElement("taskdef");\r
116 ele.setAttribute("resource", "frameworktasks.tasks");\r
117 root.appendChild(ele);\r
118\r
e1347472 119 ele = document.createElement("taskdef");\r
120 ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");\r
121 root.appendChild(ele);\r
122 \r
a29c47e0 123 ele = document.createElement("property");\r
124 ele.setAttribute("environment", "env");\r
125 root.appendChild(ele);\r
126 \r
a29c47e0 127 //\r
128 // Default Target\r
129 //\r
130 root.appendChild(document.createComment("Default target"));\r
131 ele = document.createElement("target");\r
132 ele.setAttribute("name", "all");\r
01413f0c 133 ele.setAttribute("depends", "prebuild, modules, fvs, postbuild");\r
a29c47e0 134 root.appendChild(ele);\r
135 \r
136 //\r
137 // Modules and Fvs Target\r
138 //\r
01413f0c 139 applyModules(document, root);\r
140 \r
141 applyFvs(document, root);\r
a29c47e0 142\r
143 //\r
144 // Clean Target\r
145 //\r
146 applyClean(document, root);\r
147 \r
148 //\r
149 // Deep Clean Target\r
150 //\r
151 applyCleanall(document, root);\r
152 \r
153 //\r
8cf5da75 154 // User Extension pre build\r
a29c47e0 155 //\r
8cf5da75 156 applyUserExtensionsPreBuild(document, root);\r
157 \r
158 //\r
159 // User Extension Post build\r
160 //\r
161 applyUserExtensionsPostBuild(document, root);\r
a29c47e0 162 \r
163 document.appendChild(rootComment);\r
164 document.appendChild(root);\r
165 //\r
166 // Prepare the DOM document for writing\r
167 //\r
168 Source source = new DOMSource(document);\r
169 //\r
a29c47e0 170 // generate all directory path\r
171 //\r
02c768ee 172 (new File(platformBuildFile.getParent())).mkdirs();\r
173 Result result = new StreamResult(platformBuildFile);\r
a29c47e0 174 //\r
175 // Write the DOM document to the file\r
176 //\r
177 Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
178 xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
179 xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
180 xformer.transform(source, result);\r
181 } catch (Exception ex) {\r
02c768ee 182 throw new BuildException("Generating platform build file [" + platformBuildFile.getPath() + "_build.xml] failed. \n" + ex.getMessage());\r
a29c47e0 183 }\r
184 }\r
8031d48d 185 \r
4b5f5549 186 /**\r
187 1. Get All valid Fv Image Names in sequence\r
188 2. For each FV, get modules by sequences\r
189 3. Get other modules\r
190 \r
191 @param document XML document\r
192 @param root Node\r
193 **/\r
01413f0c 194 private void applyModules(Document document, Node root) {\r
a29c47e0 195 root.appendChild(document.createComment("Modules target"));\r
196 Element ele = document.createElement("target");\r
01413f0c 197 ele.setAttribute("name", "modules");\r
a29c47e0 198\r
4b5f5549 199 //\r
380191dd 200 // Try to build apriori if necessary\r
201 //\r
202 //\r
203 // For every Target and ToolChain\r
204 //\r
205 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
206 for (int i = 0; i < targetList.length; i++){\r
207 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
208 for(int j = 0; j < toolchainList.length; j++){\r
209 //\r
210 // Prepare FV_DIR\r
211 //\r
212 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
213 + targetList[i] + "_" \r
214 + toolchainList[j];\r
215 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
216 Element fvEle = document.createElement("var");\r
217 fvEle.setAttribute("name", "FV_DIR");\r
218 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
219 ele.appendChild(fvEle);\r
220 \r
221 Iterator<String> aprIter = aprioriType.keySet().iterator();\r
222 while (aprIter.hasNext()) {\r
223 String fvName = aprIter.next();\r
224 Element moduleEle = document.createElement("Build_Apriori");\r
225 moduleEle.setAttribute("FILENAME", fvName);\r
226 moduleEle.setAttribute("GUID", aprioriType.get(fvName));\r
227 ele.appendChild(moduleEle);\r
228 }\r
229 }\r
230 }\r
231 \r
232 //\r
4b5f5549 233 // Get all valid FV name\r
234 //\r
83fba802 235 String[] validFv = saq.getFpdValidImageNames();\r
4b5f5549 236 \r
237 //\r
238 // For each valid FV, get all modules in sequence\r
239 //\r
240 for (int i = 0; i < validFv.length; i++) {\r
241 if (fvs.containsKey(validFv[i])) {\r
242 Set<FpdModuleIdentification> set = fvs.get(validFv[i]);\r
243 Iterator<FpdModuleIdentification> iter = set.iterator();\r
244 while (iter.hasNext()) {\r
245 FpdModuleIdentification fpdModuleId = iter.next();\r
246 applySingleModule(document, ele, fpdModuleId);\r
247 }\r
248 }\r
a29c47e0 249 }\r
4b5f5549 250 \r
251 //\r
252 // Get all other modules\r
253 //\r
254 Iterator<String> fvsNameIter = fvs.keySet().iterator();\r
255 \r
256 while (fvsNameIter.hasNext()) {\r
257 String fvName = fvsNameIter.next();\r
258 if (!isContain(validFv, fvName)) {\r
259 Set<FpdModuleIdentification> set = fvs.get(fvName);\r
260 Iterator iter = set.iterator();\r
261 while (iter.hasNext()) {\r
262 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
263 applySingleModule(document, ele, fpdModuleId);\r
264 }\r
265 }\r
266 }\r
267\r
a29c47e0 268 root.appendChild(ele);\r
269 }\r
270 \r
4b5f5549 271 private void applySingleModule(Document document, Node root, FpdModuleIdentification fpdModuleId) {\r
272 ModuleIdentification moduleId = fpdModuleId.getModule();\r
273 Element moduleEle = document.createElement("GenBuild");\r
274 moduleEle.setAttribute("type", "build");\r
275 //\r
276 // Inherit Properties.\r
277 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
278 //\r
279 \r
280 //\r
281 // ARCH\r
282 //\r
283 Element property = document.createElement("property");\r
284 property.setAttribute("name", "ARCH");\r
285 property.setAttribute("value", fpdModuleId.getArch());\r
286 moduleEle.appendChild(property);\r
287\r
288 //\r
289 // MODULE_GUID\r
290 //\r
291 property = document.createElement("property");\r
292 property.setAttribute("name", "MODULE_GUID");\r
293 property.setAttribute("value", moduleId.getGuid());\r
294 moduleEle.appendChild(property);\r
295 \r
296 //\r
297 // MODULE_VERSION\r
298 //\r
299 property = document.createElement("property");\r
300 property.setAttribute("name", "MODULE_VERSION");\r
301 property.setAttribute("value", moduleId.getVersion());\r
302 moduleEle.appendChild(property);\r
303 \r
304 //\r
305 // PACKAGE_GUID\r
306 //\r
307 property = document.createElement("property");\r
308 property.setAttribute("name", "PACKAGE_GUID");\r
309 property.setAttribute("value", moduleId.getPackage().getGuid());\r
310 moduleEle.appendChild(property);\r
311 \r
312 //\r
313 // PACKAGE_VERSION\r
314 //\r
315 property = document.createElement("property");\r
316 property.setAttribute("name", "PACKAGE_VERSION");\r
317 property.setAttribute("value", moduleId.getPackage().getVersion());\r
318 moduleEle.appendChild(property);\r
319 \r
320 root.appendChild(moduleEle);\r
321 }\r
322 \r
323 private boolean isContain(String[] list, String item) {\r
324 for (int i = 0; i < list.length; i++) {\r
325 if (list[i].equalsIgnoreCase(item)) {\r
326 return true;\r
327 }\r
328 }\r
329 return false;\r
330 }\r
331 \r
01413f0c 332 private void applyFvs(Document document, Node root) {\r
a29c47e0 333 //\r
334 // FVS Target\r
335 //\r
336 root.appendChild(document.createComment("FVs target"));\r
337 Element ele = document.createElement("target");\r
01413f0c 338 ele.setAttribute("name", "fvs");\r
a29c47e0 339\r
340 //\r
341 // For every Target and ToolChain\r
342 //\r
343 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
344 for (int i = 0; i < targetList.length; i++){\r
345 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
346 for(int j = 0; j < toolchainList.length; j++){\r
347 String fvOutputDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 348 + targetList[i] + "_" \r
bdaa67b1 349 + toolchainList[j] + File.separatorChar + "FV";\r
83fba802 350 String[] validFv = saq.getFpdValidImageNames();\r
a29c47e0 351 for (int k = 0; k < validFv.length; k++) {\r
01413f0c 352 String inputFile = fvOutputDir + "" + File.separatorChar + validFv[k].toUpperCase() + ".inf";\r
353 Element fvEle = document.createElement("genfvimage");\r
354 fvEle.setAttribute("infFile", inputFile);\r
355 fvEle.setAttribute("outputDir", fvOutputDir);\r
356 ele.appendChild(fvEle);\r
a29c47e0 357 }\r
358 }\r
359 }\r
360 root.appendChild(ele);\r
361 }\r
362 \r
363 private void applyClean(Document document, Node root) {\r
364 //\r
365 // Clean Target\r
366 //\r
367 root.appendChild(document.createComment("Clean target"));\r
368 Element ele = document.createElement("target");\r
369 ele.setAttribute("name", "clean");\r
370\r
371 if (isUnified) {\r
372 Element cleanEle = document.createElement("delete");\r
373 cleanEle.setAttribute("includeemptydirs", "true");\r
374 Element filesetEle = document.createElement("fileset");\r
375 filesetEle.setAttribute("dir", project.getProperty("BUILD_DIR"));\r
376 filesetEle.setAttribute("includes", "**\\OUTPUT\\**");\r
377 cleanEle.appendChild(filesetEle);\r
378 ele.appendChild(cleanEle);\r
379 } else {\r
380 Set set = outfiles.keySet();\r
381 Iterator iter = set.iterator();\r
382 while (iter.hasNext()) {\r
383 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
384 ModuleIdentification moduleId = fpdModuleId.getModule();\r
385\r
386 Element ifEle = document.createElement("if");\r
387 Element availableEle = document.createElement("available");\r
388 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
389 + "build.xml");\r
390 ifEle.appendChild(availableEle);\r
391 Element elseEle = document.createElement("then");\r
392\r
393 Element moduleEle = document.createElement("ant");\r
394 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
395 + "build.xml");\r
396 moduleEle.setAttribute("target", "clean");\r
397 //\r
398 // Inherit Properties.\r
399 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
400 //\r
401 \r
402 //\r
403 // ARCH\r
404 //\r
405 Element property = document.createElement("property");\r
406 property.setAttribute("name", "ARCH");\r
407 property.setAttribute("value", fpdModuleId.getArch());\r
408 moduleEle.appendChild(property);\r
409\r
410 //\r
411 // PACKAGE\r
412 //\r
413 property = document.createElement("property");\r
414 property.setAttribute("name", "PACKAGE");\r
415 property.setAttribute("value", moduleId.getPackage().getName());\r
416 moduleEle.appendChild(property);\r
417 \r
418 //\r
419 // PACKAGE_GUID\r
420 //\r
421 property = document.createElement("property");\r
422 property.setAttribute("name", "PACKAGE_GUID");\r
423 property.setAttribute("value", moduleId.getPackage().getGuid());\r
424 moduleEle.appendChild(property);\r
425 \r
426 //\r
427 // PACKAGE_VERSION\r
428 //\r
429 property = document.createElement("property");\r
430 property.setAttribute("name", "PACKAGE_VERSION");\r
431 property.setAttribute("value", moduleId.getPackage().getVersion());\r
432 moduleEle.appendChild(property);\r
433 \r
434 //\r
435 // MODULE_DIR\r
436 //\r
437 property = document.createElement("property");\r
438 property.setAttribute("name", "MODULE_DIR");\r
439 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
440 moduleEle.appendChild(property);\r
441 elseEle.appendChild(moduleEle);\r
442 ifEle.appendChild(elseEle);\r
443 ele.appendChild(ifEle);\r
444 }\r
445 }\r
446 root.appendChild(ele);\r
447 }\r
448 \r
449 private void applyCleanall(Document document, Node root) {\r
450 //\r
451 // Deep Clean Target\r
452 //\r
391dbbb1 453 root.appendChild(document.createComment("Target: cleanall"));\r
a29c47e0 454 Element ele = document.createElement("target");\r
455 ele.setAttribute("name", "cleanall");\r
456\r
457 if (isUnified) {\r
d3dfaf4b 458 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
459 for (int i = 0; i < targetList.length; ++i) {\r
6ae1510e 460 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
461 for(int j = 0; j < toolchainList.length; j++) {\r
462 Element cleanAllEle = document.createElement("delete");\r
463 cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR") + File.separatorChar + targetList[i] + "_" + toolchainList[j]);\r
464 ele.appendChild(cleanAllEle);\r
465 }\r
d3dfaf4b 466 }\r
a29c47e0 467 } else {\r
468 Set set = outfiles.keySet();\r
469 Iterator iter = set.iterator();\r
470 while (iter.hasNext()) {\r
471 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
472 ModuleIdentification moduleId = fpdModuleId.getModule();\r
473\r
474 Element ifEle = document.createElement("if");\r
475 Element availableEle = document.createElement("available");\r
476 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
477 + "build.xml");\r
478 ifEle.appendChild(availableEle);\r
479 Element elseEle = document.createElement("then");\r
480\r
481 Element moduleEle = document.createElement("ant");\r
482 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
483 + "build.xml");\r
484 moduleEle.setAttribute("target", "cleanall");\r
485 //\r
486 // Inherit Properties.\r
487 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
488 //\r
489 \r
490 //\r
491 // ARCH\r
492 //\r
493 Element property = document.createElement("property");\r
494 property.setAttribute("name", "ARCH");\r
495 property.setAttribute("value", fpdModuleId.getArch());\r
496 moduleEle.appendChild(property);\r
497\r
498 //\r
499 // PACKAGE\r
500 //\r
501 property = document.createElement("property");\r
502 property.setAttribute("name", "PACKAGE");\r
503 property.setAttribute("value", moduleId.getPackage().getName());\r
504 moduleEle.appendChild(property);\r
505 \r
506 //\r
507 // PACKAGE_GUID\r
508 //\r
509 property = document.createElement("property");\r
510 property.setAttribute("name", "PACKAGE_GUID");\r
511 property.setAttribute("value", moduleId.getPackage().getGuid());\r
512 moduleEle.appendChild(property);\r
513 \r
514 //\r
515 // PACKAGE_VERSION\r
516 //\r
517 property = document.createElement("property");\r
518 property.setAttribute("name", "PACKAGE_VERSION");\r
519 property.setAttribute("value", moduleId.getPackage().getVersion());\r
520 moduleEle.appendChild(property);\r
521 \r
522 //\r
523 // MODULE_DIR\r
524 //\r
525 property = document.createElement("property");\r
526 property.setAttribute("name", "MODULE_DIR");\r
527 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
528 moduleEle.appendChild(property);\r
529 elseEle.appendChild(moduleEle);\r
530 ifEle.appendChild(elseEle);\r
531 ele.appendChild(ifEle);\r
532 }\r
533 }\r
534 root.appendChild(ele);\r
535 }\r
536 \r
8cf5da75 537 private void applyUserExtensionsPreBuild(Document document, Node root) {\r
538 //\r
539 // User Extensions\r
540 //\r
391dbbb1 541 root.appendChild(document.createComment("Pre-Build Processing"));\r
8cf5da75 542 Element ele = document.createElement("target");\r
543 ele.setAttribute("name", "prebuild");\r
544 \r
83fba802 545 Node node = saq.getFpdUserExtensionPreBuild();\r
8cf5da75 546 if (node != null) {\r
547 //\r
548 // For every Target and ToolChain\r
549 //\r
550 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
551 for (int i = 0; i < targetList.length; i++){\r
552 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
553 for(int j = 0; j < toolchainList.length; j++){\r
554 //\r
555 // Prepare FV_DIR\r
556 //\r
557 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 558 + targetList[i] + "_" \r
8cf5da75 559 + toolchainList[j];\r
560 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
561 Element fvEle = document.createElement("var");\r
562 fvEle.setAttribute("name", "FV_DIR");\r
563 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
564 ele.appendChild(fvEle);\r
565 \r
4250be6c 566 Element targetDirEle = document.createElement("var");\r
567 targetDirEle.setAttribute("name", "TARGET_DIR");\r
568 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
569 ele.appendChild(targetDirEle);\r
570 \r
8cf5da75 571 NodeList childNodes = node.getChildNodes();\r
572 for (int k = 0; k < childNodes.getLength(); k++) {\r
573 Node childItem = childNodes.item(k);\r
574 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
575 ele.appendChild(recursiveNode(childItem, document));\r
576 }\r
577 }\r
8cf5da75 578 }\r
579 }\r
580 }\r
581 \r
582 root.appendChild(ele);\r
583 }\r
584 \r
585 private void applyUserExtensionsPostBuild(Document document, Node root) {\r
a29c47e0 586 //\r
587 // User Extensions\r
588 //\r
391dbbb1 589 root.appendChild(document.createComment("Post-Build Processing"));\r
a29c47e0 590 Element ele = document.createElement("target");\r
8cf5da75 591 ele.setAttribute("name", "postbuild");\r
a29c47e0 592 \r
83fba802 593 Node node = saq.getFpdUserExtensionPostBuild();\r
8031d48d 594 if (node != null) {\r
595 //\r
596 // For every Target and ToolChain\r
597 //\r
598 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
599 for (int i = 0; i < targetList.length; i++){\r
600 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
601 for(int j = 0; j < toolchainList.length; j++){\r
602 //\r
603 // Prepare FV_DIR\r
604 //\r
605 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 606 + targetList[i] + "_" \r
8031d48d 607 + toolchainList[j];\r
608 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
609 Element fvEle = document.createElement("var");\r
610 fvEle.setAttribute("name", "FV_DIR");\r
611 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
612 ele.appendChild(fvEle);\r
613 \r
4250be6c 614 Element targetDirEle = document.createElement("var");\r
615 targetDirEle.setAttribute("name", "TARGET_DIR");\r
616 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
617 ele.appendChild(targetDirEle);\r
618 \r
8031d48d 619 NodeList childNodes = node.getChildNodes();\r
620 for (int k = 0; k < childNodes.getLength(); k++) {\r
621 Node childItem = childNodes.item(k);\r
622 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
623 ele.appendChild(recursiveNode(childItem, document));\r
624 }\r
625 }\r
626 \r
627 }\r
628 }\r
629 }\r
630 \r
a29c47e0 631 root.appendChild(ele);\r
632 }\r
633 \r
8031d48d 634 private Element recursiveNode(Node node, Document document) {\r
635 Element root = document.createElement(node.getNodeName());\r
636 NamedNodeMap attr = node.getAttributes();\r
637 for (int i = 0; i < attr.getLength(); i++) {\r
638 Node attrItem = attr.item(i);\r
639 root.setAttribute(attrItem.getNodeName(), attrItem.getNodeValue());\r
640 }\r
641 NodeList childNodes = node.getChildNodes();\r
642 for (int i = 0; i < childNodes.getLength(); i++) {\r
643 Node childItem = childNodes.item(i);\r
644 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
645 root.appendChild(recursiveNode(childItem, document));\r
646 }\r
647 else if (childItem.getNodeType() == Node.TEXT_NODE){\r
91f7d582 648 if (!childItem.getNodeValue().trim().equalsIgnoreCase("")) {\r
8031d48d 649 root.setTextContent(childItem.getNodeValue());\r
650 }\r
651 }\r
652 }\r
653 return root;\r
654 }\r
a29c47e0 655}\r