- Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed.
[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
e3cc4061 162 applyUserExtensions(document, root);\r
163\r
a29c47e0 164 document.appendChild(rootComment);\r
165 document.appendChild(root);\r
166 //\r
167 // Prepare the DOM document for writing\r
168 //\r
169 Source source = new DOMSource(document);\r
170 //\r
a29c47e0 171 // generate all directory path\r
172 //\r
02c768ee 173 (new File(platformBuildFile.getParent())).mkdirs();\r
174 Result result = new StreamResult(platformBuildFile);\r
a29c47e0 175 //\r
176 // Write the DOM document to the file\r
177 //\r
178 Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
179 xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
180 xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
181 xformer.transform(source, result);\r
182 } catch (Exception ex) {\r
02c768ee 183 throw new BuildException("Generating platform build file [" + platformBuildFile.getPath() + "_build.xml] failed. \n" + ex.getMessage());\r
a29c47e0 184 }\r
185 }\r
8031d48d 186 \r
4b5f5549 187 /**\r
188 1. Get All valid Fv Image Names in sequence\r
189 2. For each FV, get modules by sequences\r
190 3. Get other modules\r
191 \r
192 @param document XML document\r
193 @param root Node\r
194 **/\r
01413f0c 195 private void applyModules(Document document, Node root) {\r
a29c47e0 196 root.appendChild(document.createComment("Modules target"));\r
197 Element ele = document.createElement("target");\r
01413f0c 198 ele.setAttribute("name", "modules");\r
a29c47e0 199\r
4b5f5549 200 //\r
380191dd 201 // Try to build apriori if necessary\r
202 //\r
203 //\r
204 // For every Target and ToolChain\r
205 //\r
206 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
207 for (int i = 0; i < targetList.length; i++){\r
208 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
209 for(int j = 0; j < toolchainList.length; j++){\r
210 //\r
211 // Prepare FV_DIR\r
212 //\r
213 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
214 + targetList[i] + "_" \r
215 + toolchainList[j];\r
216 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
217 Element fvEle = document.createElement("var");\r
218 fvEle.setAttribute("name", "FV_DIR");\r
219 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
220 ele.appendChild(fvEle);\r
221 \r
222 Iterator<String> aprIter = aprioriType.keySet().iterator();\r
223 while (aprIter.hasNext()) {\r
224 String fvName = aprIter.next();\r
225 Element moduleEle = document.createElement("Build_Apriori");\r
226 moduleEle.setAttribute("FILENAME", fvName);\r
227 moduleEle.setAttribute("GUID", aprioriType.get(fvName));\r
228 ele.appendChild(moduleEle);\r
229 }\r
230 }\r
231 }\r
232 \r
233 //\r
4b5f5549 234 // Get all valid FV name\r
235 //\r
83fba802 236 String[] validFv = saq.getFpdValidImageNames();\r
4b5f5549 237 \r
238 //\r
239 // For each valid FV, get all modules in sequence\r
240 //\r
241 for (int i = 0; i < validFv.length; i++) {\r
242 if (fvs.containsKey(validFv[i])) {\r
243 Set<FpdModuleIdentification> set = fvs.get(validFv[i]);\r
244 Iterator<FpdModuleIdentification> iter = set.iterator();\r
245 while (iter.hasNext()) {\r
246 FpdModuleIdentification fpdModuleId = iter.next();\r
247 applySingleModule(document, ele, fpdModuleId);\r
248 }\r
249 }\r
a29c47e0 250 }\r
4b5f5549 251 \r
252 //\r
253 // Get all other modules\r
254 //\r
255 Iterator<String> fvsNameIter = fvs.keySet().iterator();\r
256 \r
257 while (fvsNameIter.hasNext()) {\r
258 String fvName = fvsNameIter.next();\r
259 if (!isContain(validFv, fvName)) {\r
260 Set<FpdModuleIdentification> set = fvs.get(fvName);\r
261 Iterator iter = set.iterator();\r
262 while (iter.hasNext()) {\r
263 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
264 applySingleModule(document, ele, fpdModuleId);\r
265 }\r
266 }\r
267 }\r
268\r
a29c47e0 269 root.appendChild(ele);\r
270 }\r
271 \r
4b5f5549 272 private void applySingleModule(Document document, Node root, FpdModuleIdentification fpdModuleId) {\r
273 ModuleIdentification moduleId = fpdModuleId.getModule();\r
274 Element moduleEle = document.createElement("GenBuild");\r
275 moduleEle.setAttribute("type", "build");\r
276 //\r
277 // Inherit Properties.\r
278 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
279 //\r
280 \r
281 //\r
282 // ARCH\r
283 //\r
284 Element property = document.createElement("property");\r
285 property.setAttribute("name", "ARCH");\r
286 property.setAttribute("value", fpdModuleId.getArch());\r
287 moduleEle.appendChild(property);\r
288\r
289 //\r
290 // MODULE_GUID\r
291 //\r
292 property = document.createElement("property");\r
293 property.setAttribute("name", "MODULE_GUID");\r
294 property.setAttribute("value", moduleId.getGuid());\r
295 moduleEle.appendChild(property);\r
296 \r
297 //\r
298 // MODULE_VERSION\r
299 //\r
300 property = document.createElement("property");\r
301 property.setAttribute("name", "MODULE_VERSION");\r
302 property.setAttribute("value", moduleId.getVersion());\r
303 moduleEle.appendChild(property);\r
304 \r
305 //\r
306 // PACKAGE_GUID\r
307 //\r
308 property = document.createElement("property");\r
309 property.setAttribute("name", "PACKAGE_GUID");\r
310 property.setAttribute("value", moduleId.getPackage().getGuid());\r
311 moduleEle.appendChild(property);\r
312 \r
313 //\r
314 // PACKAGE_VERSION\r
315 //\r
316 property = document.createElement("property");\r
317 property.setAttribute("name", "PACKAGE_VERSION");\r
318 property.setAttribute("value", moduleId.getPackage().getVersion());\r
319 moduleEle.appendChild(property);\r
320 \r
321 root.appendChild(moduleEle);\r
322 }\r
323 \r
324 private boolean isContain(String[] list, String item) {\r
325 for (int i = 0; i < list.length; i++) {\r
326 if (list[i].equalsIgnoreCase(item)) {\r
327 return true;\r
328 }\r
329 }\r
330 return false;\r
331 }\r
332 \r
01413f0c 333 private void applyFvs(Document document, Node root) {\r
a29c47e0 334 //\r
335 // FVS Target\r
336 //\r
337 root.appendChild(document.createComment("FVs target"));\r
338 Element ele = document.createElement("target");\r
01413f0c 339 ele.setAttribute("name", "fvs");\r
a29c47e0 340\r
341 //\r
342 // For every Target and ToolChain\r
343 //\r
344 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
345 for (int i = 0; i < targetList.length; i++){\r
346 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
347 for(int j = 0; j < toolchainList.length; j++){\r
348 String fvOutputDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 349 + targetList[i] + "_" \r
bdaa67b1 350 + toolchainList[j] + File.separatorChar + "FV";\r
83fba802 351 String[] validFv = saq.getFpdValidImageNames();\r
a29c47e0 352 for (int k = 0; k < validFv.length; k++) {\r
01413f0c 353 String inputFile = fvOutputDir + "" + File.separatorChar + validFv[k].toUpperCase() + ".inf";\r
354 Element fvEle = document.createElement("genfvimage");\r
355 fvEle.setAttribute("infFile", inputFile);\r
356 fvEle.setAttribute("outputDir", fvOutputDir);\r
357 ele.appendChild(fvEle);\r
a29c47e0 358 }\r
359 }\r
360 }\r
361 root.appendChild(ele);\r
362 }\r
363 \r
364 private void applyClean(Document document, Node root) {\r
365 //\r
366 // Clean Target\r
367 //\r
368 root.appendChild(document.createComment("Clean target"));\r
369 Element ele = document.createElement("target");\r
370 ele.setAttribute("name", "clean");\r
371\r
372 if (isUnified) {\r
373 Element cleanEle = document.createElement("delete");\r
374 cleanEle.setAttribute("includeemptydirs", "true");\r
375 Element filesetEle = document.createElement("fileset");\r
376 filesetEle.setAttribute("dir", project.getProperty("BUILD_DIR"));\r
377 filesetEle.setAttribute("includes", "**\\OUTPUT\\**");\r
378 cleanEle.appendChild(filesetEle);\r
379 ele.appendChild(cleanEle);\r
380 } else {\r
381 Set set = outfiles.keySet();\r
382 Iterator iter = set.iterator();\r
383 while (iter.hasNext()) {\r
384 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
385 ModuleIdentification moduleId = fpdModuleId.getModule();\r
386\r
387 Element ifEle = document.createElement("if");\r
388 Element availableEle = document.createElement("available");\r
389 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
390 + "build.xml");\r
391 ifEle.appendChild(availableEle);\r
392 Element elseEle = document.createElement("then");\r
393\r
394 Element moduleEle = document.createElement("ant");\r
395 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
396 + "build.xml");\r
397 moduleEle.setAttribute("target", "clean");\r
398 //\r
399 // Inherit Properties.\r
400 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
401 //\r
402 \r
403 //\r
404 // ARCH\r
405 //\r
406 Element property = document.createElement("property");\r
407 property.setAttribute("name", "ARCH");\r
408 property.setAttribute("value", fpdModuleId.getArch());\r
409 moduleEle.appendChild(property);\r
410\r
411 //\r
412 // PACKAGE\r
413 //\r
414 property = document.createElement("property");\r
415 property.setAttribute("name", "PACKAGE");\r
416 property.setAttribute("value", moduleId.getPackage().getName());\r
417 moduleEle.appendChild(property);\r
418 \r
419 //\r
420 // PACKAGE_GUID\r
421 //\r
422 property = document.createElement("property");\r
423 property.setAttribute("name", "PACKAGE_GUID");\r
424 property.setAttribute("value", moduleId.getPackage().getGuid());\r
425 moduleEle.appendChild(property);\r
426 \r
427 //\r
428 // PACKAGE_VERSION\r
429 //\r
430 property = document.createElement("property");\r
431 property.setAttribute("name", "PACKAGE_VERSION");\r
432 property.setAttribute("value", moduleId.getPackage().getVersion());\r
433 moduleEle.appendChild(property);\r
434 \r
435 //\r
436 // MODULE_DIR\r
437 //\r
438 property = document.createElement("property");\r
439 property.setAttribute("name", "MODULE_DIR");\r
440 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
441 moduleEle.appendChild(property);\r
442 elseEle.appendChild(moduleEle);\r
443 ifEle.appendChild(elseEle);\r
444 ele.appendChild(ifEle);\r
445 }\r
446 }\r
447 root.appendChild(ele);\r
448 }\r
449 \r
450 private void applyCleanall(Document document, Node root) {\r
451 //\r
452 // Deep Clean Target\r
453 //\r
391dbbb1 454 root.appendChild(document.createComment("Target: cleanall"));\r
a29c47e0 455 Element ele = document.createElement("target");\r
456 ele.setAttribute("name", "cleanall");\r
457\r
458 if (isUnified) {\r
d3dfaf4b 459 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
460 for (int i = 0; i < targetList.length; ++i) {\r
6ae1510e 461 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
462 for(int j = 0; j < toolchainList.length; j++) {\r
463 Element cleanAllEle = document.createElement("delete");\r
464 cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR") + File.separatorChar + targetList[i] + "_" + toolchainList[j]);\r
465 ele.appendChild(cleanAllEle);\r
466 }\r
d3dfaf4b 467 }\r
a29c47e0 468 } else {\r
469 Set set = outfiles.keySet();\r
470 Iterator iter = set.iterator();\r
471 while (iter.hasNext()) {\r
472 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
473 ModuleIdentification moduleId = fpdModuleId.getModule();\r
474\r
475 Element ifEle = document.createElement("if");\r
476 Element availableEle = document.createElement("available");\r
477 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
478 + "build.xml");\r
479 ifEle.appendChild(availableEle);\r
480 Element elseEle = document.createElement("then");\r
481\r
482 Element moduleEle = document.createElement("ant");\r
483 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
484 + "build.xml");\r
485 moduleEle.setAttribute("target", "cleanall");\r
486 //\r
487 // Inherit Properties.\r
488 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
489 //\r
490 \r
491 //\r
492 // ARCH\r
493 //\r
494 Element property = document.createElement("property");\r
495 property.setAttribute("name", "ARCH");\r
496 property.setAttribute("value", fpdModuleId.getArch());\r
497 moduleEle.appendChild(property);\r
498\r
499 //\r
500 // PACKAGE\r
501 //\r
502 property = document.createElement("property");\r
503 property.setAttribute("name", "PACKAGE");\r
504 property.setAttribute("value", moduleId.getPackage().getName());\r
505 moduleEle.appendChild(property);\r
506 \r
507 //\r
508 // PACKAGE_GUID\r
509 //\r
510 property = document.createElement("property");\r
511 property.setAttribute("name", "PACKAGE_GUID");\r
512 property.setAttribute("value", moduleId.getPackage().getGuid());\r
513 moduleEle.appendChild(property);\r
514 \r
515 //\r
516 // PACKAGE_VERSION\r
517 //\r
518 property = document.createElement("property");\r
519 property.setAttribute("name", "PACKAGE_VERSION");\r
520 property.setAttribute("value", moduleId.getPackage().getVersion());\r
521 moduleEle.appendChild(property);\r
522 \r
523 //\r
524 // MODULE_DIR\r
525 //\r
526 property = document.createElement("property");\r
527 property.setAttribute("name", "MODULE_DIR");\r
528 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
529 moduleEle.appendChild(property);\r
530 elseEle.appendChild(moduleEle);\r
531 ifEle.appendChild(elseEle);\r
532 ele.appendChild(ifEle);\r
533 }\r
534 }\r
535 root.appendChild(ele);\r
536 }\r
537 \r
8cf5da75 538 private void applyUserExtensionsPreBuild(Document document, Node root) {\r
539 //\r
540 // User Extensions\r
541 //\r
391dbbb1 542 root.appendChild(document.createComment("Pre-Build Processing"));\r
8cf5da75 543 Element ele = document.createElement("target");\r
544 ele.setAttribute("name", "prebuild");\r
545 \r
83fba802 546 Node node = saq.getFpdUserExtensionPreBuild();\r
8cf5da75 547 if (node != null) {\r
548 //\r
549 // For every Target and ToolChain\r
550 //\r
551 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
552 for (int i = 0; i < targetList.length; i++){\r
553 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
554 for(int j = 0; j < toolchainList.length; j++){\r
555 //\r
556 // Prepare FV_DIR\r
557 //\r
558 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 559 + targetList[i] + "_" \r
8cf5da75 560 + toolchainList[j];\r
561 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
562 Element fvEle = document.createElement("var");\r
563 fvEle.setAttribute("name", "FV_DIR");\r
564 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
565 ele.appendChild(fvEle);\r
566 \r
4250be6c 567 Element targetDirEle = document.createElement("var");\r
568 targetDirEle.setAttribute("name", "TARGET_DIR");\r
569 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
570 ele.appendChild(targetDirEle);\r
571 \r
8cf5da75 572 NodeList childNodes = node.getChildNodes();\r
573 for (int k = 0; k < childNodes.getLength(); k++) {\r
574 Node childItem = childNodes.item(k);\r
575 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
576 ele.appendChild(recursiveNode(childItem, document));\r
577 }\r
578 }\r
8cf5da75 579 }\r
580 }\r
581 }\r
582 \r
583 root.appendChild(ele);\r
584 }\r
585 \r
586 private void applyUserExtensionsPostBuild(Document document, Node root) {\r
a29c47e0 587 //\r
588 // User Extensions\r
589 //\r
391dbbb1 590 root.appendChild(document.createComment("Post-Build Processing"));\r
a29c47e0 591 Element ele = document.createElement("target");\r
8cf5da75 592 ele.setAttribute("name", "postbuild");\r
a29c47e0 593 \r
83fba802 594 Node node = saq.getFpdUserExtensionPostBuild();\r
8031d48d 595 if (node != null) {\r
596 //\r
597 // For every Target and ToolChain\r
598 //\r
599 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
600 for (int i = 0; i < targetList.length; i++){\r
601 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
602 for(int j = 0; j < toolchainList.length; j++){\r
603 //\r
604 // Prepare FV_DIR\r
605 //\r
606 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 607 + targetList[i] + "_" \r
8031d48d 608 + toolchainList[j];\r
609 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
610 Element fvEle = document.createElement("var");\r
611 fvEle.setAttribute("name", "FV_DIR");\r
612 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
613 ele.appendChild(fvEle);\r
614 \r
4250be6c 615 Element targetDirEle = document.createElement("var");\r
616 targetDirEle.setAttribute("name", "TARGET_DIR");\r
617 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
618 ele.appendChild(targetDirEle);\r
619 \r
8031d48d 620 NodeList childNodes = node.getChildNodes();\r
621 for (int k = 0; k < childNodes.getLength(); k++) {\r
622 Node childItem = childNodes.item(k);\r
623 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
624 ele.appendChild(recursiveNode(childItem, document));\r
625 }\r
626 }\r
627 \r
628 }\r
629 }\r
630 }\r
631 \r
a29c47e0 632 root.appendChild(ele);\r
633 }\r
e3cc4061 634\r
635 private void applyUserExtensions(Document document, Node root) {\r
636 Node[] nodeList = saq.getFpdUserExtensions();\r
637 for (int nodeIndex = 0; nodeIndex < nodeList.length; ++nodeIndex) {\r
638 Node node = nodeList[nodeIndex];\r
639 //\r
640 // User Extensions\r
641 //\r
642 root.appendChild(document.createComment("User Defined Target"));\r
643 Element ele = document.createElement("target");\r
644 ele.setAttribute("name", node.getAttributes().getNamedItem("Identifier").getNodeValue());\r
645\r
646 if (node != null) {\r
647 //\r
648 // For every Target and ToolChain\r
649 //\r
650 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
651 for (int i = 0; i < targetList.length; i++){\r
652 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
653 for(int j = 0; j < toolchainList.length; j++){\r
654 //\r
655 // Prepare FV_DIR\r
656 //\r
657 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
658 + targetList[i] + "_" \r
659 + toolchainList[j];\r
660 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
661 Element fvEle = document.createElement("var");\r
662 fvEle.setAttribute("name", "FV_DIR");\r
663 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
664 ele.appendChild(fvEle);\r
665\r
666 Element targetDirEle = document.createElement("var");\r
667 targetDirEle.setAttribute("name", "TARGET_DIR");\r
668 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
669 ele.appendChild(targetDirEle);\r
670\r
671 NodeList childNodes = node.getChildNodes();\r
672 for (int k = 0; k < childNodes.getLength(); k++) {\r
673 Node childItem = childNodes.item(k);\r
674 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
675 ele.appendChild(recursiveNode(childItem, document));\r
676 }\r
677 }\r
678\r
679 }\r
680 }\r
681 }\r
682\r
683 root.appendChild(ele);\r
684 }\r
685 }\r
686\r
8031d48d 687 private Element recursiveNode(Node node, Document document) {\r
688 Element root = document.createElement(node.getNodeName());\r
689 NamedNodeMap attr = node.getAttributes();\r
690 for (int i = 0; i < attr.getLength(); i++) {\r
691 Node attrItem = attr.item(i);\r
692 root.setAttribute(attrItem.getNodeName(), attrItem.getNodeValue());\r
693 }\r
694 NodeList childNodes = node.getChildNodes();\r
695 for (int i = 0; i < childNodes.getLength(); i++) {\r
696 Node childItem = childNodes.item(i);\r
697 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
698 root.appendChild(recursiveNode(childItem, document));\r
699 }\r
700 else if (childItem.getNodeType() == Node.TEXT_NODE){\r
91f7d582 701 if (!childItem.getNodeValue().trim().equalsIgnoreCase("")) {\r
8031d48d 702 root.setTextContent(childItem.getNodeValue());\r
703 }\r
704 }\r
705 }\r
706 return root;\r
707 }\r
a29c47e0 708}\r