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