979d49ca39ae52af73eb652eeded9a44500935a1
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
1 /** @file
2 Java class FpdFileContents is used to parse fpd xml file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.platform.ui;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.math.BigInteger;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.ListIterator;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Vector;
27
28 import javax.xml.namespace.QName;
29
30 import org.apache.xmlbeans.XmlCursor;
31 import org.apache.xmlbeans.XmlObject;
32 import org.apache.xmlbeans.XmlOptions;
33 import org.tianocore.AntTaskDocument;
34 import org.tianocore.BuildOptionsDocument;
35 import org.tianocore.DynamicPcdBuildDefinitionsDocument;
36 import org.tianocore.EfiSectionType;
37 import org.tianocore.FlashDefinitionFileDocument;
38 import org.tianocore.FlashDocument;
39 import org.tianocore.FrameworkModulesDocument;
40 import org.tianocore.IntermediateOutputType;
41 import org.tianocore.LibrariesDocument;
42 import org.tianocore.ModuleSADocument;
43 import org.tianocore.ModuleSaBuildOptionsDocument;
44 import org.tianocore.ModuleSurfaceAreaDocument;
45 import org.tianocore.OptionDocument;
46 import org.tianocore.OptionsDocument;
47 import org.tianocore.PcdBuildDefinitionDocument;
48 import org.tianocore.PcdCodedDocument;
49 import org.tianocore.PcdDataTypes;
50 import org.tianocore.PcdDeclarationsDocument;
51 import org.tianocore.PcdItemTypes;
52 import org.tianocore.PlatformDefinitionsDocument;
53 import org.tianocore.PlatformSurfaceAreaDocument;
54 import org.tianocore.FvImageTypes;
55 import org.tianocore.FvImagesDocument;
56 import org.tianocore.LicenseDocument;
57 import org.tianocore.PlatformHeaderDocument;
58 import org.tianocore.SkuInfoDocument;
59 import org.tianocore.UserDefinedAntTasksDocument;
60 import org.tianocore.UserExtensionsDocument;
61 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
62 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
63 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
64 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
65 import org.tianocore.frameworkwizard.workspace.Workspace;
66
67 /**
68 This class processes fpd file contents such as add remove xml elements.
69 @since PackageEditor 1.0
70 **/
71 public class FpdFileContents {
72
73 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
74 static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
75
76 private PlatformSurfaceAreaDocument fpdd = null;
77
78 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
79
80 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
81
82 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
83
84 private FlashDocument.Flash fpdFlash = null;
85
86 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
87
88 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
89
90 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
91
92 private HashMap<String, ArrayList<String>> dynPcdMap = null;
93
94 private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();
95
96 private String itemType (String pcdInfo) {
97
98 return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1);
99 }
100
101 /**
102 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
103 */
104 public void initDynPcdMap() {
105 if (dynPcdMap == null) {
106 dynPcdMap = new HashMap<String, ArrayList<String>>();
107 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
108 if (l == null) {
109 removeElement(getfpdFrameworkModules());
110 fpdFrameworkModules = null;
111 return;
112 }
113 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
114 while (li.hasNext()) {
115 ModuleSADocument.ModuleSA moduleSa = li.next();
116 if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {
117 continue;
118 }
119 String ModuleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() +
120 " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
121 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();
122 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
123 while (lpi.hasNext()) {
124 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
125 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
126 if (dynPcdMap.get(pcdKey) == null) {
127 ArrayList<String> al = new ArrayList<String>();
128 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
129 dynPcdMap.put(pcdKey, al);
130 }
131 else{
132 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
133 }
134 }
135 }
136 }
137 }
138
139 public ArrayList<String> getDynPcdMapValue(String key) {
140 return dynPcdMap.get(key);
141 }
142 /**
143 Constructor to create a new spd file
144 **/
145 public FpdFileContents() {
146
147 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
148 fpdRoot = fpdd.addNewPlatformSurfaceArea();
149
150 }
151
152 /**
153 Constructor for existing document object
154 @param psa
155 **/
156 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
157 fpdRoot = fpd;
158 fpdHdr = fpdRoot.getPlatformHeader();
159 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
160 fpdBuildOpts = fpdRoot.getBuildOptions();
161 fpdFrameworkModules = fpdRoot.getFrameworkModules();
162 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
163 fpdFlash = fpdRoot.getFlash();
164 }
165
166 /**
167 Constructor based on an existing spd file
168
169 @param f Existing spd file
170 **/
171 public FpdFileContents(File f) {
172 try {
173 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
174 fpdRoot = fpdd.getPlatformSurfaceArea();
175 } catch (Exception e) {
176 System.out.println(e.toString());
177 }
178 }
179
180 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
181 if (fpdDynPcdBuildDefs == null){
182 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
183 }
184 return fpdDynPcdBuildDefs;
185 }
186
187 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
188 if (fpdFrameworkModules == null){
189 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
190 }
191 return fpdFrameworkModules;
192 }
193
194 public void getFrameworkModuleSAByFvBinding (String fvName, Vector<String[]> vGuid) {
195 if (getFrameworkModulesCount() == 0){
196 return;
197 }
198
199 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
200 while(li.hasNext()) {
201 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
202 if (moduleSa.getModuleSaBuildOptions() == null) {
203 continue;
204 }
205 String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();
206 if (fvBinding == null) {
207 continue;
208 }
209
210 String[] fvNames = fvBinding.split(" ");
211 for (int i = 0; i < fvNames.length; ++i) {
212 //
213 // BugBug : underscore "_" should not be replaced!!!
214 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
215 //
216 if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {
217 String[] sa = new String[] {moduleSa.getModuleGuid(), moduleSa.getModuleVersion(),
218 moduleSa.getPackageGuid(), moduleSa.getPackageVersion(),
219 listToString(moduleSa.getSupArchList())};
220 vGuid.add(sa);
221 break;
222 }
223 }
224 }
225 }
226
227 public int getFrameworkModulesCount() {
228 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
229 removeElement(getfpdFrameworkModules());
230 fpdFrameworkModules = null;
231 return 0;
232 }
233 return getfpdFrameworkModules().getModuleSAList().size();
234 }
235
236 public void getFrameworkModulesInfo(String[][] saa) {
237 if (getFrameworkModulesCount() == 0){
238 return;
239 }
240
241 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
242 int i = 0;
243 while(li.hasNext()) {
244 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
245 saa[i][0] = moduleSa.getModuleGuid();
246 saa[i][1] = moduleSa.getModuleVersion();
247
248 saa[i][2] = moduleSa.getPackageGuid();
249 saa[i][3] = moduleSa.getPackageVersion();
250 saa[i][4] = listToString(moduleSa.getSupArchList());
251 ++i;
252 }
253 }
254
255 public void getFrameworkModuleInfo(int i, String[] sa) {
256 ModuleSADocument.ModuleSA msa = getModuleSA(i);
257 if (msa == null) {
258 return;
259 }
260 sa[0] = msa.getModuleGuid();
261 sa[1] = msa.getModuleVersion();
262 sa[2] = msa.getPackageGuid();
263 sa[3] = msa.getPackageVersion();
264 sa[4] = listToString(msa.getSupArchList());
265 }
266
267 public ModuleSADocument.ModuleSA getModuleSA(String key) {
268
269 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
270 removeElement(getfpdFrameworkModules());
271 fpdFrameworkModules = null;
272 return null;
273 }
274 String[] s = key.split(" ");
275 String archsInKey = "";
276 if (s.length > 4) {
277 for (int i = 4; i < s.length; ++i) {
278 archsInKey += s[i];
279 archsInKey += " ";
280 }
281 archsInKey = archsInKey.trim();
282 }
283
284 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
285 while(li.hasNext()) {
286 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
287 if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {
288 if (moduleSa.getModuleVersion() != null) {
289 if (!moduleSa.getModuleVersion().equals(s[1])) {
290 continue;
291 }
292 }
293 if (moduleSa.getPackageVersion() != null) {
294 if (!moduleSa.getPackageVersion().equals(s[3])) {
295 continue;
296 }
297 }
298 //ToDo add arch check .
299 if (moduleSa.getSupArchList() != null) {
300 if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) {
301 return moduleSa;
302 }
303 }
304 else {
305 if (archsInKey.length() == 0) {
306 return moduleSa;
307 }
308 }
309 }
310 }
311 return null;
312 }
313
314 private ModuleSADocument.ModuleSA getModuleSA(int i) {
315 ModuleSADocument.ModuleSA moduleSa = null;
316 if (fpdRoot.getFrameworkModules() == null) {
317 return null;
318 }
319 XmlCursor cursor = fpdRoot.getFrameworkModules().newCursor();
320 if (cursor.toFirstChild()) {
321 for (int j = 0; j < i; ++j) {
322 cursor.toNextSibling();
323 }
324 moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
325 }
326 cursor.dispose();
327 return moduleSa;
328 }
329
330 public void removeModuleSA(int i) {
331 XmlObject o = fpdRoot.getFrameworkModules();
332 if (o == null) {
333 return;
334 }
335
336 XmlCursor cursor = o.newCursor();
337 if (cursor.toFirstChild()) {
338 for (int j = 0; j < i; ++j) {
339 cursor.toNextSibling();
340 }
341 //
342 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
343 //
344 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
345 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
346 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
347 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
348 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {
349 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();
350 while(li.hasNext()) {
351 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
352 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);
353 }
354 }
355
356 cursor.push();
357 while (cursor.hasPrevToken()) {
358 cursor.toPrevToken();
359 if (!cursor.isText()) {
360 break;
361 }
362 if (cursor.getObject() == null) {
363 break;
364 }
365 String s = cursor.getTextValue();
366 if (s.matches(regExpNewLineAndSpaces)) {
367 continue;
368 }
369 }
370
371 if (cursor.isComment()) {
372 cursor.removeXml();
373 }
374
375 cursor.pop();
376 cursor.removeXml();
377 if (getFrameworkModulesCount() == 0) {
378 cursor.dispose();
379 removeElement(getfpdFrameworkModules());
380 fpdFrameworkModules = null;
381 return;
382 }
383 }
384 cursor.dispose();
385 }
386
387 public boolean adjustPcd (int seqModuleSa, Vector<String> vExceptions) throws Exception {
388 boolean dataModified = false;
389 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
390 int pcdCount = getPcdDataCount(seqModuleSa);
391 String[][] saaModuleSaPcd = new String[pcdCount][7];
392 getPcdData(seqModuleSa, saaModuleSaPcd);
393 String mg = moduleSa.getModuleGuid().toLowerCase();
394 String mv = moduleSa.getModuleVersion();
395 String pg = moduleSa.getPackageGuid().toLowerCase();
396 String pv = moduleSa.getPackageVersion();
397 String arch = listToString(moduleSa.getSupArchList());
398 //
399 // delete pcd in ModuleSA but not in MSA files any longer.
400 //
401 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
402 int libCount = getLibraryInstancesCount(moduleKey);
403 String[][] saaLib = new String[libCount][5];
404 getLibraryInstances(moduleKey, saaLib);
405 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
406 if (mi == null) {
407 vExceptions.add("Module " + mg + " does NOT exist in workspace.");
408 throw new Exception ("Module does NOT exist in workspace.");
409 }
410 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
411 //
412 // create vector for module & library instance MIs.
413 //
414 vMi.add(mi);
415 for (int j = 0; j < saaLib.length; ++j) {
416 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
417 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
418 if (libMi != null) {
419 vMi.add(libMi);
420 }
421 }
422
423 nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {
424
425 for (int j = 0; j < vMi.size(); ++j) {
426 ModuleIdentification nextMi = vMi.get(j);
427 if (nextMi == null) {
428 continue;
429 }
430 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], arch, nextMi)) {
431 continue nextPcd;
432 }
433 }
434 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);
435 dataModified = true;
436 }
437 //
438 // add new Pcd from MSA file to ModuleSA.
439 //
440 for (int i = 0; i < vMi.size(); ++i) {
441 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
442 .getModuleXmlObject(vMi
443 .get(i));
444 if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {
445 continue;
446 }
447 ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();
448 msaPcdIter:while (li.hasNext()) {
449 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
450 ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());
451 if (al != null) {
452 for (int j = 0; j < al.size(); ++j) {
453 if (al.get(j).startsWith(moduleKey)) {
454 continue msaPcdIter;
455 }
456 }
457 }
458 // Check sup arch conformance for the new PCD
459 if (msaPcd.getSupArchList() != null) {
460 String newPcdArch = msaPcd.getSupArchList().toString();
461 if (!newPcdArch.toLowerCase().contains(arch.toLowerCase())) {
462 continue;
463 }
464 }
465
466 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));
467 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
468 if (spdPcd == null) {
469 //
470 // ToDo Error
471 //
472 String errorMessage = "No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "
473 + mi.getName();
474 if (i != 0) {
475 errorMessage += " Library Instance " + vMi.get(i).getName();
476 }
477 vExceptions.add(errorMessage);
478 throw new PcdDeclNotFound(errorMessage);
479 }
480 //
481 // AddItem to ModuleSA PcdBuildDefinitions
482 //
483 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()
484 : msaPcd.getDefaultValue();
485
486 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),
487 msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd);
488 dataModified = true;
489 }
490
491 }
492
493 return dataModified;
494 }
495
496 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {
497
498 ArrayList<String> al = dynPcdMap.get(pcdKey);
499 if (al == null) {
500 return;
501 }
502 String[] s = moduleInfo.split(" ");
503 for(int i = 0; i < al.size(); ++i){
504 String consumer = al.get(i);
505 if (consumer.contains(s[0].toLowerCase()) && consumer.contains(s[2].toLowerCase())){
506 String[] consumerPart = consumer.split(" ");
507 if (!consumerPart[4].equals(s[4])) {
508 continue;
509 }
510 al.remove(consumer);
511 break;
512 }
513 }
514
515 if (al.size() == 0) {
516 defaultPcdValue.remove(pcdKey);
517 dynPcdMap.remove(pcdKey);
518 String[] s1 = pcdKey.split(" ");
519 removeDynamicPcdBuildData(s1[0], s1[1]);
520 }
521
522 }
523 //
524 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
525 //
526 public int getPcdDataCount (int i){
527 ModuleSADocument.ModuleSA msa = getModuleSA(i);
528
529 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
530 return 0;
531 }
532 return msa.getPcdBuildDefinition().getPcdDataList().size();
533
534 }
535
536 public void getPcdData (int i, String[][] saa) {
537 ModuleSADocument.ModuleSA msa = getModuleSA(i);
538
539 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
540 return;
541 }
542 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
543 for (int k = 0; k < saa.length; ++k) {
544 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
545 saa[k][0] = pcdData.getCName();
546 saa[k][1] = pcdData.getTokenSpaceGuidCName();
547 saa[k][2] = pcdData.getItemType()+"";
548 saa[k][3] = pcdData.getToken().toString();
549 saa[k][4] = pcdData.getMaxDatumSize()+"";
550 saa[k][5] = pcdData.getDatumType()+"";
551 saa[k][6] = pcdData.getValue();
552
553 }
554 }
555
556 public void removePcdData (int seqModuleSa, String cName, String tsGuid) {
557 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
558 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
559 return;
560 }
561
562 String mg = moduleSa.getModuleGuid();
563 String mv = moduleSa.getModuleVersion();
564 String pg = moduleSa.getPackageGuid();
565 String pv = moduleSa.getPackageVersion();
566 String arch = listToString(moduleSa.getSupArchList());
567 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
568
569 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
570 if (cursor.toFirstChild()){
571
572 do {
573 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
574 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
575 maintainDynPcdMap(cName + " " + tsGuid, moduleKey);
576 if (getPcdDataCount(seqModuleSa) == 1) {
577 cursor.toParent();
578 }
579 cursor.removeXml();
580 break;
581 }
582 }
583 while(cursor.toNextSibling());
584
585 }
586 cursor.dispose();
587 }
588
589 public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){
590 ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);
591 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
592 return;
593 }
594
595 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
596 if (cursor.toFirstChild()){
597 do {
598 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
599 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
600 //
601 // change item type while not updating dynPcdData????
602 //
603 if (itemType != null) {
604 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
605 }
606
607 if(pcdData.getDatumType().equals("VOID*") && maxSize != null) {
608 pcdData.setMaxDatumSize(new Integer(maxSize));
609 }
610 //
611 // if value input is null, keep old value untouched.
612 //
613 if (value != null) {
614 pcdData.setValue(value);
615 defaultPcdValue.put(cName + " " + tsGuid, value);
616 }
617
618 break;
619 }
620 }
621 while(cursor.toNextSibling());
622 }
623 cursor.dispose();
624 }
625
626 /**Get original Pcd info from MSA & SPD files.
627 * @param mi ModuleIdentification from which MSA & SPD come
628 * @param cName PCD cName
629 * @param sa Results: HelpText, Original item type.
630 * @return
631 */
632 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa, Vector<String> validPcdTypes) throws Exception{
633
634 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
635 .getModuleXmlObject(mi);
636 if (msa.getPcdCoded() == null) {
637 return false;
638 }
639
640 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
641 //
642 // First look through MSA pcd entries.
643 //
644 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
645 ListIterator li = l.listIterator();
646 while (li.hasNext()) {
647 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
648 if (!msaPcd.getCName().equals(cName)) {
649 continue;
650 }
651 if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {
652 continue;
653 }
654 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
655 if (spdPcd == null || spdPcd.getValidUsage() == null) {
656 //
657 // ToDo Error
658 //
659 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());
660 }
661 //
662 // Get Pcd help text and original item type.
663 //
664 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();
665 sa[1] = msaPcd.getPcdItemType() + "";
666 sa[2] = msa.getModuleDefinitions().getBinaryModule() + "";
667 ListIterator iter = spdPcd.getValidUsage().listIterator();
668 while (iter.hasNext()) {
669 String usage = iter.next().toString();
670 validPcdTypes.add(usage);
671 }
672 return true;
673 }
674
675 return false;
676 }
677
678 private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) {
679 int libCount = getLibraryInstancesCount(moduleKey);
680 String[][] saaLib = new String[libCount][5];
681 getLibraryInstances(moduleKey, saaLib);
682 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
683 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
684 //
685 // create vector for module & library instance MIs.
686 //
687 vMi.add(mi);
688 for (int j = 0; j < saaLib.length; ++j) {
689 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
690 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
691 vMi.add(libMi);
692 }
693
694 int pcdSourceCount = 0;
695 for (int i = 0; i < vMi.size(); ++i) {
696 if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, null, vMi.get(i))) {
697 pcdSourceCount++;
698 }
699 }
700
701 if (pcdSourceCount < 2) {
702 return false;
703 }
704 else {
705 return true;
706 }
707
708 }
709
710 /**Remove PCDBuildDefinition entries from ModuleSA
711 * @param moduleKey identifier of ModuleSA.
712 * @param consumer where these entries come from.
713 */
714 public void removePcdData(String moduleKey, ModuleIdentification consumer) {
715
716 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);
717 if (msa.getPcdCoded() == null) {
718 return;
719 }
720
721 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
722 ListIterator li = l.listIterator();
723
724 while(li.hasNext()) {
725 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
726 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);
727 if (moduleSA.getPcdBuildDefinition() != null) {
728 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();
729 cursor.push();
730 if (cursor.toFirstChild()) {
731 do {
732 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor
733 .getObject();
734 String cName = msaPcd.getCName();
735 String tsGuidCName = msaPcd.getTokenSpaceGuidCName();
736 if (cName.equals(pcdData.getCName())
737 && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) {
738
739 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),
740 moduleKey);
741 cursor.removeXml();
742 break;
743 }
744 } while (cursor.toNextSibling());
745 }
746
747 cursor.pop();
748 if (moduleSA.getPcdBuildDefinition().getPcdDataList().size() == 0) {
749 cursor.removeXml();
750 }
751 cursor.dispose();
752 }
753 }
754
755 }
756 //
757 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
758 //
759 public int getLibraryInstancesCount(String key) {
760 ModuleSADocument.ModuleSA msa = getModuleSA(key);
761 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
762 return 0;
763 }
764 return msa.getLibraries().getInstanceList().size();
765 }
766
767 public void getLibraryInstances(String key, String[][] saa){
768 ModuleSADocument.ModuleSA msa = getModuleSA(key);
769 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
770 return ;
771 }
772
773 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
774 for (int i = 0; i < saa.length; ++i) {
775 LibrariesDocument.Libraries.Instance instance = li.next();
776 saa[i][1] = instance.getModuleGuid();
777 saa[i][2] = instance.getModuleVersion();
778 saa[i][3] = instance.getPackageGuid();
779 saa[i][4] = instance.getPackageVersion();
780 }
781 }
782
783 public void removeLibraryInstance(String key, int i) {
784 ModuleSADocument.ModuleSA msa = getModuleSA(key);
785 if (msa == null || msa.getLibraries() == null){
786 return ;
787 }
788
789 XmlCursor cursor = msa.getLibraries().newCursor();
790 if (cursor.toFirstChild()) {
791 for (int j = 0; j < i; ++j) {
792 cursor.toNextSibling();
793 }
794 cursor.push();
795 while (cursor.hasPrevToken()) {
796 cursor.toPrevToken();
797 if (!cursor.isText()) {
798 break;
799 }
800 String s = cursor.getTextValue();
801 if (s.matches(regExpNewLineAndSpaces)) {
802 continue;
803 }
804 }
805
806 if (cursor.isComment()) {
807 cursor.removeXml();
808 }
809 cursor.pop();
810 cursor.removeXml();
811 if (getLibraryInstancesCount(key) == 0) {
812 cursor.toParent();
813 cursor.removeXml();
814 }
815 }
816
817 cursor.dispose();
818 }
819
820 public void genLibraryInstance(ModuleIdentification libMi, String key) {
821 ModuleSADocument.ModuleSA msa = getModuleSA(key);
822 if (msa == null){
823 msa = getfpdFrameworkModules().addNewModuleSA();
824 }
825 LibrariesDocument.Libraries libs = msa.getLibraries();
826 if(libs == null){
827 libs = msa.addNewLibraries();
828 }
829
830 String mn = libMi.getName();
831 String mg = libMi.getGuid();
832 String mv = libMi.getVersion();
833 String pn = libMi.getPackageId().getName();
834 String pg = libMi.getPackageId().getGuid();
835 String pv = libMi.getPackageId().getVersion();
836 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
837 XmlCursor cursor = instance.newCursor();
838 try{
839 String comment = "Pkg: " + pn + " Mod: " + mn
840 + " Path: " + libMi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
841 cursor.insertComment(comment);
842 }
843 catch (Exception e){
844 e.printStackTrace();
845 }
846 finally {
847 cursor.dispose();
848 }
849
850 instance.setModuleGuid(mg);
851 instance.setModuleVersion(mv);
852 instance.setPackageGuid(pg);
853 instance.setPackageVersion(pv);
854
855 }
856
857 public String getFvBinding(String moduleKey){
858 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
859 return getFvBinding (moduleSa);
860 }
861
862 public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {
863 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
864 return null;
865 }
866 return moduleSa.getModuleSaBuildOptions().getFvBinding();
867 }
868
869 public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {
870 if (moduleSa == null ) {
871 return;
872 }
873 if (fvBinding == null || fvBinding.length() == 0) {
874 if(moduleSa.getModuleSaBuildOptions() != null){
875 moduleSa.getModuleSaBuildOptions().unsetFvBinding();
876 }
877 }
878 else {
879 if(moduleSa.getModuleSaBuildOptions() == null){
880 moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
881 return;
882 }
883 moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding);
884 }
885 }
886
887 public void setFvBinding(String moduleKey, String fvBinding){
888 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
889 setFvBinding (moduleSa, fvBinding);
890 }
891
892 private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {
893 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
894 return -1;
895 }
896
897 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
898 String[] fvNamesArray = fvNameList.split(" ");
899 int occursAt = -1;
900 for (int i = 0; i < fvNamesArray.length; ++i) {
901 if (fvNamesArray[i].equals(fvName)) {
902 occursAt = i;
903 break;
904 }
905 }
906 return occursAt;
907 }
908
909 public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
910 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
911 return;
912 }
913
914 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
915 String[] fvNamesArray = fvNameList.split(" ");
916 int occursAt = -1;
917 for (int i = 0; i < fvNamesArray.length; ++i) {
918 if (fvNamesArray[i].equals(fvName)) {
919 occursAt = i;
920 break;
921 }
922 }
923 // jump over where the input fvName occurs in the original Fv list.
924 if (occursAt != -1) {
925 String newFvNameList = " ";
926 for (int i = 0; i < fvNamesArray.length; ++i) {
927 if (i == occursAt) {
928 continue;
929 }
930 newFvNameList += fvNamesArray[i];
931 }
932 setFvBinding (moduleSa, newFvNameList.trim());
933 }
934
935 }
936
937 /**
938 * @param fvName The FV name that to be removed from FvBinding List.
939 */
940 public void removeFvBindingAll (String fvName) {
941 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
942 removeElement(getfpdFrameworkModules());
943 fpdFrameworkModules = null;
944 return;
945 }
946
947 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
948 while (li.hasNext()) {
949 ModuleSADocument.ModuleSA moduleSa = li.next();
950 removeFvBinding (moduleSa, fvName);
951 }
952 }
953
954 public void appendFvBindingAll (String fvName) {
955 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
956 removeElement(getfpdFrameworkModules());
957 fpdFrameworkModules = null;
958 return;
959 }
960
961 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
962 while (li.hasNext()) {
963 ModuleSADocument.ModuleSA moduleSa = li.next();
964 appendFvBinding (moduleSa, fvName);
965 }
966 }
967
968 public void appendFvBindingFor (String oldFvName, String newFvName) {
969 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
970 removeElement(getfpdFrameworkModules());
971 fpdFrameworkModules = null;
972 return;
973 }
974
975 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
976 while (li.hasNext()) {
977 ModuleSADocument.ModuleSA moduleSa = li.next();
978 String fvBinding = getFvBinding (moduleSa);
979 if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {
980 appendFvBinding (moduleSa, newFvName);
981 }
982 }
983 }
984
985 public void appendFvBinding (String moduleKey, String fvName) {
986 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
987 appendFvBinding (moduleSa, fvName);
988 }
989
990 public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
991 if (moduleSa == null) {
992 return;
993 }
994
995 if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
996 setFvBinding(moduleSa, fvName);
997 return;
998 }
999
1000 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
1001 String newFvNameList = fvNameList + " " + fvName;
1002 setFvBinding (moduleSa, newFvNameList.trim());
1003 }
1004
1005 public void updateFvBindingInModuleSA (String moduleKey, String fvName) {
1006
1007 appendFvBinding (moduleKey, fvName);
1008 }
1009
1010 public String getFfsFileNameGuid(String moduleKey){
1011 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
1012 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
1013 return null;
1014 }
1015 return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid();
1016 }
1017
1018 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
1019 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1020 if (msa == null ) {
1021 return;
1022 }
1023 if(msa.getModuleSaBuildOptions() == null){
1024 msa.addNewModuleSaBuildOptions();
1025
1026 }
1027 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();
1028 if (fileGuid != null) {
1029 msaBuildOpts.setFfsFileNameGuid(fileGuid);
1030 }
1031 else{
1032 XmlCursor cursor = msaBuildOpts.newCursor();
1033 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {
1034 cursor.removeXml();
1035 }
1036 cursor.dispose();
1037 }
1038
1039 }
1040
1041 public String getFfsFormatKey(String moduleKey){
1042 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1043 if (msa == null || msa.getModuleSaBuildOptions() == null) {
1044 return null;
1045 }
1046 return msa.getModuleSaBuildOptions().getFfsFormatKey();
1047 }
1048
1049 public void setFfsFormatKey(String moduleKey, String ffsKey){
1050 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1051 if (msa == null ) {
1052 return;
1053 }
1054 if(msa.getModuleSaBuildOptions() == null){
1055 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1056 return;
1057 }
1058 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1059 }
1060
1061 public void setModuleSAForceDebug(int i, boolean dbgEnable) {
1062 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1063 moduleSa.setForceDebug(dbgEnable);
1064 }
1065
1066 public boolean getModuleSAForceDebug (int i) {
1067 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1068 if (moduleSa.getForceDebug() == true) {
1069 return true;
1070 }
1071 return false;
1072 }
1073
1074 public void getModuleSAOptions(String moduleKey, String[][] saa) {
1075 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1076 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1077 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1078 return ;
1079 }
1080
1081 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
1082 ListIterator li = lOpt.listIterator();
1083 int i = 0;
1084 while(li.hasNext()) {
1085 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1086 if (opt.getBuildTargets() != null) {
1087 saa[i][0] = listToString(opt.getBuildTargets());
1088 }
1089 saa[i][1] = opt.getToolChainFamily();
1090 saa[i][2] = opt.getTagName();
1091 saa[i][3] = opt.getToolCode();
1092
1093 if (opt.getSupArchList() != null){
1094 saa[i][4] = listToString(opt.getSupArchList());
1095 }
1096 else {
1097 saa[i][4] = "";
1098 }
1099
1100 saa[i][5] = opt.getStringValue();
1101
1102 ++i;
1103 }
1104 }
1105
1106 public int getModuleSAOptionsCount(String moduleKey){
1107 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1108 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1109 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1110 return 0;
1111 }
1112 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
1113 }
1114
1115 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1116 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1117 if (msa.getModuleSaBuildOptions() == null) {
1118 msa.addNewModuleSaBuildOptions();
1119 }
1120 if (msa.getModuleSaBuildOptions().getOptions() == null){
1121 msa.getModuleSaBuildOptions().addNewOptions();
1122 }
1123 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
1124 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1125 }
1126
1127 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
1128 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1129 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1130 return ;
1131 }
1132 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1133 XmlCursor cursor = opts.newCursor();
1134 if (cursor.toFirstChild()) {
1135 for (int j = 0; j < i; ++j){
1136 cursor.toNextSibling();
1137 }
1138 cursor.removeXml();
1139 if (getModuleSAOptionsCount(moduleKey) == 0) {
1140 cursor.toParent();
1141 cursor.removeXml();
1142 }
1143 }
1144 cursor.dispose();
1145 }
1146
1147 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1148 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1149 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1150 return ;
1151 }
1152 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1153 XmlCursor cursor = opts.newCursor();
1154 if (cursor.toFirstChild()) {
1155 for (int j = 0; j < i; ++j){
1156 cursor.toNextSibling();
1157 }
1158 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1159 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1160 }
1161 cursor.dispose();
1162 }
1163
1164 /**add pcd information of module mi to a ModuleSA.
1165 * @param mi
1166 * @param moduleSa if null, generate a new ModuleSA.
1167 */
1168 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
1169 //ToDo add Arch filter
1170
1171 if (moduleSa == null) {
1172 moduleSa = genModuleSA(mi, arch);
1173 }
1174
1175 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
1176 .getModuleXmlObject(mi);
1177 if (msa.getPcdCoded() == null) {
1178 return;
1179 }
1180
1181 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
1182 //
1183 // Implementing InitializePlatformPcdBuildDefinitions
1184 //
1185 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
1186 ListIterator li = l.listIterator();
1187 while (li.hasNext()) {
1188 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
1189 if (msaPcd.getSupArchList() != null) {
1190 if (!msaPcd.getSupArchList().toString().toLowerCase().contains(arch.toLowerCase())) {
1191 continue;
1192 }
1193 }
1194 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
1195 if (spdPcd == null) {
1196 //
1197 // ToDo Error
1198 //
1199 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + "\n used by Module "
1200 + mi.getName() + " or its Library Instances.");
1201 }
1202 //
1203 // AddItem to ModuleSA PcdBuildDefinitions
1204 //
1205 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
1206
1207 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType()
1208 .toString(),
1209 spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd);
1210 }
1211
1212 }
1213
1214 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
1215
1216 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
1217 for (int i = 0; i < depPkgs.length; ++i) {
1218
1219 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);
1220 if (xo == null) {
1221 continue;
1222 }
1223 for (int j = 0; j < xo.length; ++j) {
1224 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
1225 if (msaPcd.getTokenSpaceGuidCName() == null) {
1226 if (spdPcd.getCName().equals(msaPcd.getCName())) {
1227 return spdPcd;
1228 }
1229 }
1230 else{
1231 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
1232 return spdPcd;
1233 }
1234 }
1235
1236 }
1237
1238 }
1239 return null;
1240 }
1241
1242 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
1243 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
1244 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
1245 XmlCursor cursor = msa.newCursor();
1246 try{
1247 String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "
1248 + mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
1249 cursor.insertComment(comment);
1250 }
1251 catch(Exception e){
1252 e.printStackTrace();
1253 }
1254 finally {
1255 cursor.dispose();
1256 }
1257 msa.setModuleGuid(mi.getGuid());
1258 msa.setModuleVersion(mi.getVersion());
1259 msa.setPackageGuid(pi.getGuid());
1260 msa.setPackageVersion(pi.getVersion());
1261 if (arch != null) {
1262 Vector<String> v = new Vector<String>();
1263 v.add(arch);
1264 msa.setSupArchList(v);
1265 }
1266
1267 return msa;
1268 }
1269
1270 private String chooseDefaultPcdType (List validPcdTypes) {
1271 String choosedType = "";
1272 if (validPcdTypes.contains("FIXED_AT_BUILD")) {
1273 choosedType = "FIXED_AT_BUILD";
1274 }
1275 else if (validPcdTypes.contains("DYNAMIC")) {
1276 choosedType = "DYNAMIC";
1277 }
1278 else if (validPcdTypes.contains("PATCHABLE_IN_MODULE")) {
1279 choosedType = "PATCHABLE_IN_MODULE";
1280 }
1281 else if (validPcdTypes.contains("DYNAMIC_EX")) {
1282 choosedType = "DYNAMIC_EX";
1283 }
1284 return choosedType;
1285 }
1286
1287 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal,
1288 ModuleSADocument.ModuleSA moduleSa, PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd)
1289 throws PcdItemTypeConflictException, PcdValueMalFormed{
1290 if (moduleSa.getPcdBuildDefinition() == null){
1291 moduleSa.addNewPcdBuildDefinition();
1292 }
1293 //
1294 // constructe pcd to modulesa mapping first.
1295 // Attention : for any error condition, remove from map this pcd.
1296 //
1297 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1298 if (pcdConsumer == null) {
1299 pcdConsumer = new ArrayList<String>();
1300 }
1301 //
1302 // Check whether this PCD has already added to ModuleSA, if so, just return.
1303 //
1304 String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion()
1305 + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
1306 for (int i = 0; i < pcdConsumer.size(); ++i) {
1307 String pcdInfo = pcdConsumer.get(i);
1308 if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){
1309 return;
1310 }
1311 }
1312 // if pcd type from MSA file is Dynamic
1313 // we must choose one default type from SPD file for it.
1314 //
1315 List validPcdTypes = spdPcd.getValidUsage();
1316 //
1317 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1318 //
1319 if (pcdConsumer.size() > 0) {
1320 //
1321 // platform should only contain one type for each pcd.
1322 //
1323 String existingItemType = itemType (pcdConsumer.get(0));
1324 for (int i = 1; i < pcdConsumer.size(); ++i) {
1325 if (!existingItemType.equals(itemType(pcdConsumer.get(i)))) {
1326 throw new PcdItemTypeConflictException (cName, pcdConsumer.get(0), pcdConsumer.get(i));
1327 }
1328 }
1329
1330 if (itemType.equals("DYNAMIC")) {
1331 if (!validPcdTypes.contains(existingItemType)) {
1332 throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0));
1333 }
1334 itemType = existingItemType;
1335 }
1336 else {
1337 if (!itemType.equals(existingItemType)) {
1338 throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0));
1339 }
1340 }
1341 }
1342 //
1343 // if this is the first occurence of this pcd.
1344 //
1345 else {
1346 if (itemType.equals("DYNAMIC")) {
1347 itemType = chooseDefaultPcdType (validPcdTypes);
1348 }
1349 }
1350 String listValue = moduleInfo + " " + itemType;
1351 pcdConsumer.add(listValue);
1352 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1353
1354 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1355 fpdPcd.setCName(cName);
1356 fpdPcd.setToken(token);
1357 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1358 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1359 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1360
1361 if (defaultVal != null && defaultVal.length() > 0){
1362 fpdPcd.setValue(defaultVal);
1363 }
1364 else {
1365 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1366 fpdPcd.setValue("0");
1367 }
1368 if (dataType.equals("BOOLEAN")){
1369 fpdPcd.setValue("FALSE");
1370 }
1371 if (dataType.equals("VOID*")) {
1372 fpdPcd.setValue("L\"\"");
1373 }
1374 }
1375 //
1376 // Using existing pcd value, if this pcd already exists in other moduleSa.
1377 //
1378 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1379 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1380 }
1381 else {
1382 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1383 }
1384
1385 if (dataType.equals("UINT8")){
1386 fpdPcd.setMaxDatumSize(1);
1387 }
1388 if (dataType.equals("UINT16")) {
1389 fpdPcd.setMaxDatumSize(2);
1390 }
1391 if (dataType.equals("UINT32")) {
1392 fpdPcd.setMaxDatumSize(4);
1393 }
1394 if (dataType.equals("UINT64")){
1395 fpdPcd.setMaxDatumSize(8);
1396 }
1397 if (dataType.equals("BOOLEAN")){
1398 fpdPcd.setMaxDatumSize(1);
1399 }
1400 if (dataType.equals("VOID*")) {
1401 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1402 fpdPcd.setMaxDatumSize(maxSize);
1403 }
1404
1405
1406 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1407 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1408 //
1409 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1410 // so need to add one dyn pcd.
1411 //
1412 if (al.size() == 1) {
1413 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1414 }
1415 }
1416
1417 }
1418
1419 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1420 if (datum == null) {
1421 return 0;
1422 }
1423 char ch = datum.charAt(0);
1424 int start, end;
1425 String strValue;
1426 //
1427 // For void* type PCD, only three datum is support:
1428 // 1) Unicode: string with start char is "L"
1429 // 2) Ansci: String is ""
1430 // 3) byte array: String start char "{"
1431 //
1432 if (ch == 'L') {
1433 start = datum.indexOf('\"');
1434 end = datum.lastIndexOf('\"');
1435 if ((start > end) ||
1436 (end > datum.length())||
1437 ((start == end) && (datum.length() > 0))) {
1438 //ToDo Error handling here
1439 throw new PcdValueMalFormed (datum);
1440 }
1441
1442 strValue = datum.substring(start + 1, end);
1443 return strValue.length() * 2;
1444 } else if (ch == '\"'){
1445 start = datum.indexOf('\"');
1446 end = datum.lastIndexOf('\"');
1447 if ((start > end) ||
1448 (end > datum.length())||
1449 ((start == end) && (datum.length() > 0))) {
1450 throw new PcdValueMalFormed (datum);
1451 }
1452 strValue = datum.substring(start + 1, end);
1453 return strValue.length();
1454 } else if (ch =='{') {
1455 String[] strValueArray;
1456
1457 start = datum.indexOf('{');
1458 end = datum.lastIndexOf('}');
1459 strValue = datum.substring(start + 1, end);
1460 strValue = strValue.trim();
1461 if (strValue.length() == 0) {
1462 return 0;
1463 }
1464 strValueArray = strValue.split(",");
1465 for (int index = 0; index < strValueArray.length; index ++) {
1466 Integer value = Integer.decode(strValueArray[index].trim());
1467
1468 if (value > 0xFF) {
1469 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1470 // "it must be a byte array. But the element of %s exceed the byte range",
1471 throw new PcdValueMalFormed (datum);
1472 }
1473 }
1474 return strValueArray.length;
1475
1476
1477 } else {
1478 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1479 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1480 // "2) ANSIC string: like \"xxx\";\r\n"+
1481 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1482 // "but the datum in seems does not following above format!",
1483 throw new PcdValueMalFormed (datum);
1484
1485 }
1486 }
1487
1488 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1489 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1490
1491 return al;
1492 }
1493
1494 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1495
1496 return dynPcdMap.get(pcdKey);
1497 }
1498
1499 public int getDynamicPcdBuildDataCount() {
1500 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1501 removeElement(getfpdDynPcdBuildDefs());
1502 fpdDynPcdBuildDefs = null;
1503 return 0;
1504 }
1505 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1506 }
1507
1508 public void getDynamicPcdBuildData(String[][] saa) {
1509 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1510 removeElement(getfpdDynPcdBuildDefs());
1511 fpdDynPcdBuildDefs = null;
1512 return ;
1513 }
1514 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1515 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1516 int i = 0;
1517 while(li.hasNext()) {
1518 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1519 saa[i][0] = dynPcd.getCName();
1520 saa[i][1] = dynPcd.getToken().toString();
1521 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1522 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1523 saa[i][4] = dynPcd.getDatumType()+"";
1524
1525 ++i;
1526 }
1527 }
1528
1529 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1530 throws PcdValueMalFormed{
1531 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1532 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1533 dynPcdData.setCName(cName);
1534 dynPcdData.setToken(token);
1535 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1536 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1537
1538 BigInteger bigInt = new BigInteger("0");
1539 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1540 skuInfo.setSkuId(bigInt);
1541 if (defaultVal != null){
1542 skuInfo.setValue(defaultVal);
1543 }
1544 else {
1545 if (dataType.equals("UINT8")){
1546 skuInfo.setValue("0");
1547 }
1548 if (dataType.equals("UINT16")) {
1549 skuInfo.setValue("0");
1550 }
1551 if (dataType.equals("UINT32")) {
1552 skuInfo.setValue("0");
1553 }
1554 if (dataType.equals("UINT64")){
1555 skuInfo.setValue("0");
1556 }
1557 if (dataType.equals("BOOLEAN")){
1558 skuInfo.setValue("false");
1559 }
1560 if (dataType.equals("VOID*")) {
1561 skuInfo.setValue("");
1562 }
1563 }
1564 if (dataType.equals("UINT8")){
1565 dynPcdData.setMaxDatumSize(1);
1566 }
1567 if (dataType.equals("UINT16")) {
1568 dynPcdData.setMaxDatumSize(2);
1569 }
1570 if (dataType.equals("UINT32")) {
1571 dynPcdData.setMaxDatumSize(4);
1572 }
1573 if (dataType.equals("UINT64")){
1574 dynPcdData.setMaxDatumSize(8);
1575 }
1576 if (dataType.equals("BOOLEAN")){
1577 dynPcdData.setMaxDatumSize(1);
1578 }
1579 if (dataType.equals("VOID*")) {
1580 int maxSize = setMaxSizeForPointer(defaultVal);
1581 dynPcdData.setMaxDatumSize(maxSize);
1582 }
1583 }
1584
1585 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1586 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1587 if (o == null) {
1588 return;
1589 }
1590
1591 XmlCursor cursor = o.newCursor();
1592 if (cursor.toFirstChild()) {
1593 do {
1594 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1595 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1596 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1597
1598 if (getDynamicPcdBuildDataCount() == 1) {
1599 cursor.dispose();
1600 removeElement(o);
1601 fpdDynPcdBuildDefs = null;
1602 return;
1603 }
1604 cursor.removeXml();
1605 cursor.dispose();
1606 return;
1607 }
1608 }
1609 while (cursor.toNextSibling());
1610 }
1611 cursor.dispose();
1612 }
1613 //
1614 // Get the Sku Info count of ith dyn pcd element.
1615 //
1616 public int getDynamicPcdSkuInfoCount(int i){
1617 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1618 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1619 removeElement(getfpdDynPcdBuildDefs());
1620 fpdDynPcdBuildDefs = null;
1621 return 0;
1622 }
1623
1624 int skuInfoCount = 0;
1625 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1626 if (cursor.toFirstChild()) {
1627 for (int j = 0; j < i; ++j) {
1628 cursor.toNextSibling();
1629 }
1630 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1631 if (pcdData.getSkuInfoList() == null) {
1632 skuInfoCount = 0;
1633 }
1634 else {
1635 skuInfoCount = pcdData.getSkuInfoList().size();
1636 }
1637 }
1638 cursor.dispose();
1639 return skuInfoCount;
1640 }
1641
1642 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1643 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1644 removeElement(getfpdDynPcdBuildDefs());
1645 fpdDynPcdBuildDefs = null;
1646 return;
1647 }
1648
1649 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1650 if (cursor.toFirstChild()) {
1651 for (int j = 0; j < i; ++j) {
1652 cursor.toNextSibling();
1653 }
1654 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1655 if (pcdData.getSkuInfoList() == null) {
1656 cursor.dispose();
1657 return;
1658 }
1659 else {
1660 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1661 int k = 0;
1662 while (li.hasNext()) {
1663 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1664 saa[k][0] = skuInfo.getSkuId()+"";
1665 saa[k][1] = skuInfo.getVariableName();
1666 saa[k][2] = skuInfo.getVariableGuid();
1667 saa[k][3] = skuInfo.getVariableOffset();
1668 saa[k][4] = skuInfo.getHiiDefaultValue();
1669 saa[k][5] = skuInfo.getVpdOffset();
1670 saa[k][6] = skuInfo.getValue();
1671 ++k;
1672 }
1673
1674 }
1675 }
1676 cursor.dispose();
1677
1678 }
1679
1680 public String getDynamicPcdBuildDataValue(int i){
1681 String value = null;
1682 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1683 removeElement(getfpdDynPcdBuildDefs());
1684 fpdDynPcdBuildDefs = null;
1685 return value;
1686 }
1687
1688 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1689 if (cursor.toFirstChild()) {
1690 for (int j = 0; j < i; ++j) {
1691 cursor.toNextSibling();
1692 }
1693 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1694 if (pcdData.getSkuInfoList() == null) {
1695 value = null;
1696 }
1697 else {
1698 value = pcdData.getSkuInfoArray(0).getValue();
1699 }
1700 }
1701 cursor.dispose();
1702 return value;
1703 }
1704
1705 public String getDynamicPcdBuildDataVpdOffset(int i){
1706 String vpdOffset = null;
1707 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1708 removeElement(getfpdDynPcdBuildDefs());
1709 fpdDynPcdBuildDefs = null;
1710 return vpdOffset;
1711 }
1712
1713 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1714 if (cursor.toFirstChild()) {
1715 for (int j = 0; j < i; ++j) {
1716 cursor.toNextSibling();
1717 }
1718 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1719 if (pcdData.getSkuInfoList() == null) {
1720 vpdOffset = null;
1721 }
1722 else {
1723 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1724 }
1725 }
1726 cursor.dispose();
1727 return vpdOffset;
1728 }
1729
1730 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1731 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1732 removeElement(getfpdDynPcdBuildDefs());
1733 fpdDynPcdBuildDefs = null;
1734 return;
1735 }
1736
1737 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1738 if (cursor.toFirstChild()) {
1739 for (int j = 0; j < i; ++j) {
1740 cursor.toNextSibling();
1741 }
1742 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1743 if (pcdData.getSkuInfoList() == null) {
1744 cursor.dispose();
1745 return;
1746 }
1747 else {
1748 pcdData.getSkuInfoList().clear();
1749 // QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1750 // cursor.toChild(qSkuInfo);
1751 // cursor.removeXml();
1752 }
1753 }
1754 cursor.dispose();
1755 }
1756 //
1757 // generate sku info for ith dyn pcd build data.
1758 //
1759 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1760 String hiiDefault, String vpdOffset, String value, int i) {
1761 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1762 // return;
1763 // }
1764
1765 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1766 if (cursor.toFirstChild()) {
1767 for (int j = 0; j < i; ++j) {
1768 cursor.toNextSibling();
1769 }
1770 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1771 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1772 skuInfo.setSkuId(new BigInteger(id));
1773 if (varName != null){
1774 skuInfo.setVariableName(varName);
1775 skuInfo.setVariableGuid(varGuid);
1776 skuInfo.setVariableOffset(varOffset);
1777 skuInfo.setHiiDefaultValue(hiiDefault);
1778 }
1779 else if (vpdOffset != null){
1780 skuInfo.setVpdOffset(vpdOffset);
1781 }
1782 else{
1783 skuInfo.setValue(value);
1784 }
1785 }
1786 }
1787
1788 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1789 String hiiDefault, String vpdOffset, String value, int i){
1790 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1791 removeElement(getfpdDynPcdBuildDefs());
1792 fpdDynPcdBuildDefs = null;
1793 return;
1794 }
1795
1796 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1797 if (cursor.toFirstChild()) {
1798 for (int j = 0; j < i; ++j) {
1799 cursor.toNextSibling();
1800 }
1801 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1802 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1803 while (li.hasNext()) {
1804 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1805 if (skuInfo.getSkuId().toString().equals(id)){
1806 if (varName != null){
1807 skuInfo.setVariableName(varName);
1808 skuInfo.setVariableGuid(varGuid);
1809 skuInfo.setVariableOffset(varOffset);
1810 skuInfo.setHiiDefaultValue(hiiDefault);
1811 }
1812 else if (vpdOffset != null){
1813 skuInfo.setVpdOffset(vpdOffset);
1814 }
1815 else{
1816 skuInfo.setValue(value);
1817 }
1818 break;
1819 }
1820 }
1821 }
1822 }
1823
1824 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1825 if (fpdBuildOpts == null) {
1826 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1827 }
1828 return fpdBuildOpts;
1829 }
1830
1831 public void genBuildOptionsUserExtensions(String fvName, String userId, String id, String outputFileName, Vector<String[]> includeModules) {
1832 QName elementFvName = new QName (xmlNs, "FvName");
1833 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1834 QName elementInfFileName = new QName(xmlNs, "InfFileName");
1835 QName elementModule = new QName(xmlNs, "Module");
1836
1837 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1838 userExts.setUserID(userId);
1839 userExts.setIdentifier(new BigInteger(id));
1840 XmlCursor cursor = userExts.newCursor();
1841 cursor.toEndToken();
1842
1843 cursor.beginElement(elementFvName);
1844 cursor.insertChars(fvName);
1845 cursor.toNextToken();
1846
1847 cursor.beginElement(elementInfFileName);
1848 cursor.insertChars(outputFileName);
1849 cursor.toNextToken();
1850
1851 cursor.beginElement(elementIncludeModules);
1852 for (int i = 0; i < includeModules.size(); ++i) {
1853 cursor.beginElement(elementModule);
1854 cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);
1855 if (!includeModules.get(i)[1].equals("null") && includeModules.get(i)[1].length() != 0) {
1856 cursor.insertAttributeWithValue("ModuleVersion", includeModules.get(i)[1]);
1857 }
1858 cursor.insertAttributeWithValue("PackageGuid", includeModules.get(i)[2]);
1859 if (!includeModules.get(i)[3].equals("null") && includeModules.get(i)[3].length() != 0) {
1860 cursor.insertAttributeWithValue("PackageVersion", includeModules.get(i)[3]);
1861 }
1862
1863 cursor.insertAttributeWithValue("Arch", includeModules.get(i)[4]);
1864 cursor.toEndToken();
1865 cursor.toNextToken();
1866 }
1867 cursor.dispose();
1868 }
1869
1870 public int getUserExtsIncModCount (String fvName, String userId, int id) {
1871 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1872 return -1;
1873 }
1874
1875 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1876 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1877 while (li.hasNext()) {
1878 UserExtensionsDocument.UserExtensions ues = li.next();
1879 if (!ues.getUserID().equals(userId)) {
1880 continue;
1881 }
1882 if (ues.getIdentifier() == null || ues.getIdentifier().intValue() != id) {
1883 continue;
1884 }
1885 XmlCursor cursor = ues.newCursor();
1886 cursor.toFirstChild();
1887 String elementName = cursor.getTextValue();
1888 if (elementName.equals(fvName)) {
1889 cursor.toNextSibling(elementIncludeModules);
1890 if (cursor.toFirstChild()) {
1891 int i = 1;
1892 for (i = 1; cursor.toNextSibling(); ++i);
1893 cursor.dispose();
1894 return i;
1895 }
1896 cursor.dispose();
1897 return 0;
1898 }
1899 cursor.dispose();
1900 }
1901 return -1;
1902 }
1903
1904 public void getUserExtsIncMods(String fvName, String userId, int id, String[][] saa) {
1905 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1906 return;
1907 }
1908
1909 XmlCursor cursor = getfpdBuildOpts().newCursor();
1910 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1911 QName attribUserId = new QName ("UserID");
1912 QName attribId = new QName ("Identifier");
1913 QName elementFvName = new QName (xmlNs, "FvName");
1914 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1915 QName attribModuleGuid = new QName("ModuleGuid");
1916 QName attribModuleVersion = new QName("ModuleVersion");
1917 QName attribPackageGuid = new QName("PackageGuid");
1918 QName attribPackageVersion = new QName("PackageVersion");
1919 QName attribArch = new QName("Arch");
1920
1921 if (cursor.toChild(elementUserExts)) {
1922 do {
1923 cursor.push();
1924 if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {
1925 cursor.toChild(elementFvName);
1926 String elementName = cursor.getTextValue();
1927 if (elementName.equals(fvName)) {
1928 cursor.toNextSibling(elementIncludeModules);
1929 if (cursor.toFirstChild()) {
1930 int i = 0;
1931 do {
1932 saa[i][0] = cursor.getAttributeText(attribModuleGuid);
1933 saa[i][1] = cursor.getAttributeText(attribModuleVersion);
1934 saa[i][2] = cursor.getAttributeText(attribPackageGuid);
1935 saa[i][3] = cursor.getAttributeText(attribPackageVersion);
1936 saa[i][4] = cursor.getAttributeText(attribArch);
1937 ++i;
1938 }while (cursor.toNextSibling());
1939 }
1940 break;
1941 }
1942 }
1943 cursor.pop();
1944 }while (cursor.toNextSibling(elementUserExts));
1945 }
1946 cursor.dispose();
1947
1948 }
1949
1950 public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {
1951 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1952 return;
1953 }
1954 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1955 while (li.hasNext()) {
1956 UserExtensionsDocument.UserExtensions ues = li.next();
1957 if (!ues.getUserID().equals("IMAGES")) {
1958 continue;
1959 }
1960 XmlCursor cursor = ues.newCursor();
1961 cursor.toFirstChild();
1962 String elementName = cursor.getTextValue();
1963 if (elementName.equals(oldFvName)) {
1964 cursor.setTextValue(newFvName);
1965 }
1966 cursor.dispose();
1967 }
1968
1969 }
1970
1971 public void removeBuildOptionsUserExtensions (String fvName, String userId, int id) {
1972 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1973 return;
1974 }
1975
1976 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1977 while (li.hasNext()) {
1978 UserExtensionsDocument.UserExtensions ues = li.next();
1979 if (!ues.getUserID().equals(userId)) {
1980 continue;
1981 }
1982 if (ues.getIdentifier()== null || ues.getIdentifier().intValue() != id) {
1983 continue;
1984 }
1985 XmlCursor cursor = ues.newCursor();
1986 cursor.toFirstChild();
1987 String elementName = cursor.getTextValue();
1988 if (elementName.equals(fvName)) {
1989 cursor.toParent();
1990 cursor.removeXml();
1991 cursor.dispose();
1992 return;
1993 }
1994 cursor.dispose();
1995 }
1996
1997 }
1998
1999 private boolean versionEqual (String v1, String v2) {
2000
2001 if ((v1 == null || v1.length() == 0 || v1.equalsIgnoreCase("null"))
2002 && (v2 == null || v2.length() == 0 || v2.equalsIgnoreCase("null"))) {
2003 return true;
2004 }
2005
2006 if (v1 != null && v1.equals(v2)) {
2007 return true;
2008 }
2009
2010 return false;
2011 }
2012
2013 public boolean moduleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
2014 boolean inList = false;
2015 if (getUserExtsIncModCount(fvName, userId, id) > 0) {
2016 XmlCursor cursor = getfpdBuildOpts().newCursor();
2017 QName elementUserExts = new QName (xmlNs, "UserExtensions");
2018 QName attribUserId = new QName ("UserID");
2019 QName attribId = new QName ("Identifier");
2020 QName elementFvName = new QName (xmlNs, "FvName");
2021 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
2022 QName attribModuleGuid = new QName("ModuleGuid");
2023 QName attribModuleVersion = new QName("ModuleVersion");
2024 QName attribPackageGuid = new QName("PackageGuid");
2025 QName attribPackageVersion = new QName("PackageVersion");
2026 QName attribArch = new QName("Arch");
2027
2028 if (cursor.toChild(elementUserExts)) {
2029 do {
2030 cursor.push();
2031 if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {
2032 cursor.toChild(elementFvName);
2033 String elementName = cursor.getTextValue();
2034 if (elementName.equals(fvName)) {
2035 cursor.toNextSibling(elementIncludeModules);
2036 if (cursor.toFirstChild()) {
2037
2038 do {
2039 String mg = cursor.getAttributeText(attribModuleGuid);
2040 String mv = cursor.getAttributeText(attribModuleVersion);
2041 String pg = cursor.getAttributeText(attribPackageGuid);
2042 String pv = cursor.getAttributeText(attribPackageVersion);
2043 String ar = cursor.getAttributeText(attribArch);
2044 if (!moduleGuid.equalsIgnoreCase(mg)) {
2045 continue;
2046 }
2047 if (!packageGuid.equalsIgnoreCase(pg)) {
2048 continue;
2049 }
2050 if (!arch.equalsIgnoreCase(ar)) {
2051 continue;
2052 }
2053 if (!versionEqual(moduleVersion, mv)) {
2054 continue;
2055 }
2056 if (!versionEqual(packageVersion, pv)) {
2057 continue;
2058 }
2059 inList = true;
2060 break;
2061 }while (cursor.toNextSibling());
2062 }
2063 break;
2064 }
2065 }
2066 cursor.pop();
2067 }while (cursor.toNextSibling(elementUserExts));
2068 }
2069 cursor.dispose();
2070 }
2071 return inList;
2072 }
2073
2074 public void removeModuleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
2075 //
2076 // if there is only one module before remove operation, the whole user extension should be removed.
2077 //
2078 int moduleAmount = getUserExtsIncModCount(fvName, userId, id);
2079 if (moduleAmount == 1) {
2080 removeBuildOptionsUserExtensions(fvName, userId, id);
2081 return;
2082 }
2083
2084 if (moduleAmount > 1) {
2085 XmlCursor cursor = getfpdBuildOpts().newCursor();
2086 QName elementUserExts = new QName (xmlNs, "UserExtensions");
2087 QName attribUserId = new QName ("UserID");
2088 QName attribId = new QName ("Identifier");
2089 QName elementFvName = new QName (xmlNs, "FvName");
2090 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
2091 QName attribModuleGuid = new QName("ModuleGuid");
2092 QName attribModuleVersion = new QName("ModuleVersion");
2093 QName attribPackageGuid = new QName("PackageGuid");
2094 QName attribPackageVersion = new QName("PackageVersion");
2095 QName attribArch = new QName("Arch");
2096
2097 if (cursor.toChild(elementUserExts)) {
2098 do {
2099 cursor.push();
2100 if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {
2101 cursor.toChild(elementFvName);
2102 String elementName = cursor.getTextValue();
2103 if (elementName.equals(fvName)) {
2104 cursor.toNextSibling(elementIncludeModules);
2105 if (cursor.toFirstChild()) {
2106
2107 do {
2108 String mg = cursor.getAttributeText(attribModuleGuid);
2109 String mv = cursor.getAttributeText(attribModuleVersion);
2110 String pg = cursor.getAttributeText(attribPackageGuid);
2111 String pv = cursor.getAttributeText(attribPackageVersion);
2112 String ar = cursor.getAttributeText(attribArch);
2113 if (!moduleGuid.equalsIgnoreCase(mg)) {
2114 continue;
2115 }
2116 if (!packageGuid.equalsIgnoreCase(pg)) {
2117 continue;
2118 }
2119 if (!arch.equalsIgnoreCase(ar)) {
2120 continue;
2121 }
2122 if (!versionEqual(moduleVersion, mv)) {
2123 continue;
2124 }
2125 if (!versionEqual(packageVersion, pv)) {
2126 continue;
2127 }
2128 cursor.removeXml();
2129 }while (cursor.toNextSibling());
2130 }
2131 break;
2132 }
2133 }
2134 cursor.pop();
2135 }while (cursor.toNextSibling(elementUserExts));
2136 }
2137 cursor.dispose();
2138 }
2139 }
2140
2141 public void addModuleIntoBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
2142 if (moduleInBuildOptionsUserExtensions (fvName, userId, id, moduleGuid, moduleVersion, packageGuid, packageVersion, arch)) {
2143 return;
2144 }
2145
2146 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
2147 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
2148 QName elementModule = new QName(xmlNs, "Module");
2149 while (li.hasNext()) {
2150 UserExtensionsDocument.UserExtensions ues = li.next();
2151 if (!ues.getUserID().equals(userId)) {
2152 continue;
2153 }
2154 if (ues.getIdentifier() == null || ues.getIdentifier().intValue() != id) {
2155 continue;
2156 }
2157 XmlCursor cursor = ues.newCursor();
2158 cursor.toFirstChild();
2159 String elementName = cursor.getTextValue();
2160 if (elementName.equals(fvName)) {
2161 cursor.toNextSibling(elementIncludeModules);
2162 cursor.toLastChild();
2163 cursor.toEndToken();
2164 cursor.toNextToken();
2165 cursor.beginElement(elementModule);
2166 cursor.insertAttributeWithValue("ModuleGuid", moduleGuid);
2167 if (!moduleVersion.equals("null") && moduleVersion.length() != 0) {
2168 cursor.insertAttributeWithValue("ModuleVersion", moduleVersion);
2169 }
2170 cursor.insertAttributeWithValue("PackageGuid", packageGuid);
2171 if (!packageVersion.equals("null") && packageVersion.length() != 0) {
2172 cursor.insertAttributeWithValue("PackageVersion", packageVersion);
2173 }
2174
2175 cursor.insertAttributeWithValue("Arch", arch);
2176 cursor.dispose();
2177 return;
2178 }
2179 cursor.dispose();
2180 }
2181
2182 }
2183
2184 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
2185 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2186 if (udats == null) {
2187 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
2188 }
2189
2190 AntTaskDocument.AntTask at = udats.addNewAntTask();
2191 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2192 }
2193
2194 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
2195 at.setId(new Integer(id));
2196 XmlCursor cursor = at.newCursor();
2197 if (fileName != null){
2198 at.setFilename(fileName);
2199 }
2200 else if (cursor.toChild(xmlNs, "Filename")) {
2201 cursor.removeXml();
2202 }
2203 if (execOrder != null) {
2204 at.setAntCmdOptions(execOrder);
2205 }
2206 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
2207 cursor.removeXml();
2208 }
2209 cursor.dispose();
2210 }
2211
2212 public void removeBuildOptionsUserDefAntTask(int i) {
2213 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2214 if (o == null) {
2215 return;
2216 }
2217 XmlCursor cursor = o.newCursor();
2218 if (cursor.toFirstChild()) {
2219 for (int j = 0; j < i; ++j) {
2220 cursor.toNextSibling();
2221 }
2222 cursor.removeXml();
2223 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2224 cursor.toParent();
2225 cursor.removeXml();
2226 }
2227 }
2228 cursor.dispose();
2229 }
2230
2231 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
2232 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2233 if (o == null) {
2234 return;
2235 }
2236 XmlCursor cursor = o.newCursor();
2237 if (cursor.toFirstChild()) {
2238 for (int j = 0; j < i; ++j) {
2239 cursor.toNextSibling();
2240 }
2241 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
2242 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2243 }
2244 cursor.dispose();
2245 }
2246
2247 public int getBuildOptionsUserDefAntTaskCount() {
2248 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2249 if (udats == null || udats.getAntTaskList() == null) {
2250 return 0;
2251 }
2252
2253 return udats.getAntTaskList().size();
2254 }
2255
2256 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
2257 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2258 if (udats == null || udats.getAntTaskList() == null) {
2259 return ;
2260 }
2261
2262 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
2263 ListIterator li = l.listIterator();
2264 int i = 0;
2265 while (li.hasNext()) {
2266 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
2267 saa[i][0] = at.getId() + "";
2268 saa[i][1] = saa[i][2] = "";
2269 if (at.getFilename() != null){
2270 saa[i][1] = at.getFilename();
2271 }
2272 if (at.getAntCmdOptions() != null) {
2273 saa[i][2] = at.getAntCmdOptions();
2274 }
2275 ++i;
2276 }
2277 }
2278 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2279 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
2280 if (opts == null) {
2281 opts = getfpdBuildOpts().addNewOptions();
2282 }
2283 OptionDocument.Option opt = opts.addNewOption();
2284 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2285 }
2286
2287 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
2288 opt.setStringValue(contents);
2289 if (buildTargets != null) {
2290 opt.setBuildTargets(buildTargets);
2291 }
2292 else {
2293 if (opt.isSetBuildTargets()) {
2294 opt.unsetBuildTargets();
2295 }
2296 }
2297
2298 if (toolChain != null && toolChain.length() > 0) {
2299 opt.setToolChainFamily(toolChain);
2300 }
2301 else {
2302 if (opt.isSetToolChainFamily()) {
2303 opt.unsetToolChainFamily();
2304 }
2305 }
2306
2307 if (tagName != null && tagName.length() > 0) {
2308 opt.setTagName(tagName);
2309 }
2310 else {
2311 if (opt.isSetTagName()) {
2312 opt.unsetTagName();
2313 }
2314 }
2315
2316 if (toolCmd != null && toolCmd.length() > 0) {
2317 opt.setToolCode(toolCmd);
2318 }
2319 else {
2320 if (opt.isSetToolCode()) {
2321 opt.unsetToolCode();
2322 }
2323 }
2324
2325
2326 if (archList != null) {
2327 opt.setSupArchList(archList);
2328 }
2329 else {
2330 if (opt.isSetSupArchList()) {
2331 opt.unsetSupArchList();
2332 }
2333 }
2334 }
2335
2336 public void removeBuildOptionsOpt(int i){
2337
2338 XmlObject o = getfpdBuildOpts().getOptions();
2339 if (o == null) {
2340 return;
2341 }
2342
2343 XmlCursor cursor = o.newCursor();
2344 if (cursor.toFirstChild()) {
2345 for (int j = 0; j < i; ++j) {
2346 cursor.toNextSibling();
2347 }
2348 cursor.removeXml();
2349 if (getBuildOptionsOptCount() == 0) {
2350 cursor.toParent();
2351 cursor.removeXml();
2352 }
2353 }
2354 cursor.dispose();
2355 }
2356
2357 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2358 XmlObject o = getfpdBuildOpts().getOptions();
2359 if (o == null) {
2360 return;
2361 }
2362
2363 XmlCursor cursor = o.newCursor();
2364 if (cursor.toFirstChild()) {
2365 for (int j = 0; j < i; ++j) {
2366 cursor.toNextSibling();
2367 }
2368 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
2369 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2370 }
2371 cursor.dispose();
2372 }
2373
2374 public int getBuildOptionsOptCount(){
2375 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2376 return 0;
2377 }
2378 return getfpdBuildOpts().getOptions().getOptionList().size();
2379 }
2380
2381 public void getBuildOptionsOpts(String[][] saa) {
2382 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2383 return ;
2384 }
2385
2386 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
2387 ListIterator li = lOpt.listIterator();
2388 int i = 0;
2389 while(li.hasNext()) {
2390 OptionDocument.Option opt = (OptionDocument.Option)li.next();
2391 if (opt.getBuildTargets() != null) {
2392 saa[i][0] = listToString(opt.getBuildTargets());
2393 }
2394 saa[i][1] = opt.getToolChainFamily();
2395 if (opt.getSupArchList() != null){
2396 saa[i][2] = listToString(opt.getSupArchList());
2397
2398 }
2399 saa[i][3] = opt.getToolCode();
2400 saa[i][4] = opt.getTagName();
2401 saa[i][5] = opt.getStringValue();
2402
2403 ++i;
2404 }
2405 }
2406
2407 public void genBuildOptionsFfs(String ffsKey, String type) {
2408 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2409 ffs.setFfsKey(ffsKey);
2410 if (type != null) {
2411 ffs.addNewSections().setEncapsulationType(type);
2412 }
2413 }
2414
2415 public void updateBuildOptionsFfsSectionsType(int i, String type) {
2416 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2417 ffs.getSections().setEncapsulationType(type);
2418 }
2419
2420 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2421 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2422 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2423 attrib.setName(name);
2424 attrib.setValue(value);
2425 }
2426
2427 /**update jth attribute of ith ffs.
2428 * @param i
2429 * @param j
2430 */
2431 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2432 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2433 XmlCursor cursor = ffs.newCursor();
2434 QName qAttrib = new QName(xmlNs, "Attribute");
2435 if (cursor.toChild(qAttrib)) {
2436 for (int k = 0; k < j; ++k) {
2437 cursor.toNextSibling(qAttrib);
2438 }
2439 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2440 attrib.setName(name);
2441 attrib.setValue(value);
2442 }
2443 cursor.dispose();
2444 }
2445
2446 public void removeBuildOptionsFfsAttribute(int i, int j){
2447 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2448 XmlCursor cursor = ffs.newCursor();
2449 QName qAttrib = new QName(xmlNs, "Attribute");
2450 if (cursor.toChild(qAttrib)) {
2451 for (int k = 0; k < j; ++k) {
2452 cursor.toNextSibling(qAttrib);
2453 }
2454 cursor.removeXml();
2455 }
2456 cursor.dispose();
2457 }
2458
2459 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2460 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2461 if (ffs == null) {
2462 return;
2463 }
2464 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2465
2466 if (sections == null){
2467 sections = ffs.addNewSections();
2468 }
2469 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2470 }
2471
2472 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2473 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2474 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2475 if (sections == null) {
2476 return;
2477 }
2478 XmlCursor cursor = sections.newCursor();
2479 QName qSection = new QName(xmlNs, "Section");
2480 if (cursor.toChild(qSection)) {
2481 for (int k = 0; k < j; ++k) {
2482 cursor.toNextSibling(qSection);
2483 }
2484 cursor.removeXml();
2485 }
2486 cursor.dispose();
2487 }
2488
2489 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2490 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2491 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2492 if (sections == null) {
2493 return;
2494 }
2495 XmlCursor cursor = sections.newCursor();
2496 QName qSection = new QName(xmlNs, "Section");
2497 if (cursor.toChild(qSection)) {
2498 for (int k = 0; k < j; ++k) {
2499 cursor.toNextSibling(qSection);
2500 }
2501 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2502 section.setSectionType(EfiSectionType.Enum.forString(type));
2503 }
2504 cursor.dispose();
2505 }
2506
2507 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2508 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2509 if (ffs == null) {
2510 return;
2511 }
2512 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2513
2514 if (sections == null){
2515 sections = ffs.addNewSections();
2516 }
2517 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections();
2518 sections2.setEncapsulationType(encapType);
2519 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32"));
2520 }
2521
2522 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2523 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2524 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2525 if (sections == null) {
2526 return;
2527 }
2528 XmlCursor cursor = sections.newCursor();
2529 QName qSections = new QName(xmlNs, "Sections");
2530 if (cursor.toChild(qSections)) {
2531 for (int k = 0; k < j; ++k) {
2532 cursor.toNextSibling(qSections);
2533 }
2534 cursor.removeXml();
2535 }
2536 cursor.dispose();
2537 }
2538
2539 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2540 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2541 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2542 if (sections == null) {
2543 return;
2544 }
2545 XmlCursor cursor = sections.newCursor();
2546 QName qSections = new QName(xmlNs, "Sections");
2547 if (cursor.toChild(qSections)) {
2548 for (int k = 0; k < j; ++k) {
2549 cursor.toNextSibling(qSections);
2550 }
2551 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2552 sections2.setEncapsulationType(type);
2553 }
2554 cursor.dispose();
2555 }
2556
2557 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2558 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2559 if (ffs == null) {
2560 return;
2561 }
2562 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2563 XmlCursor cursor = sections.newCursor();
2564 QName qSections = new QName(xmlNs, "Sections");
2565 if (cursor.toChild(qSections)){
2566 for (int k = 0; k < j; ++k) {
2567 cursor.toNextSibling(qSections);
2568 }
2569 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2570 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2571 }
2572 cursor.dispose();
2573 }
2574
2575 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2576 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2577 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2578 if (sections == null) {
2579 return;
2580 }
2581 XmlCursor cursor = sections.newCursor();
2582 QName qSections = new QName(xmlNs, "Sections");
2583 if (cursor.toChild(qSections)) {
2584 for (int l = 0; l < j; ++l) {
2585 cursor.toNextSibling(qSections);
2586 }
2587 if (cursor.toFirstChild()) {
2588 int m = 0;
2589 for (; m < k; ++m) {
2590 cursor.toNextSibling();
2591 }
2592 cursor.removeXml();
2593 if (m == 0) {
2594 cursor.toParent();
2595 cursor.removeXml();
2596 }
2597 }
2598 }
2599 cursor.dispose();
2600 }
2601
2602 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2603 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2604 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2605 if (sections == null) {
2606 return;
2607 }
2608 XmlCursor cursor = sections.newCursor();
2609 QName qSections = new QName(xmlNs, "Sections");
2610 if (cursor.toChild(qSections)) {
2611 for (int l = 0; l < j; ++l) {
2612 cursor.toNextSibling(qSections);
2613 }
2614 if (cursor.toFirstChild()) {
2615 for (int m = 0; m &