2 Java class FpdFileContents is used to parse fpd xml file.
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
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.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
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
;
26 import java
.util
.Vector
;
28 import javax
.xml
.namespace
.QName
;
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
;
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
70 public class FpdFileContents
{
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)*";
75 private PlatformSurfaceAreaDocument fpdd
= null;
77 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
79 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
81 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
83 private FlashDocument
.Flash fpdFlash
= null;
85 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
87 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
89 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
91 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
93 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
95 private String
itemType (String pcdInfo
) {
97 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
101 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
103 public void initDynPcdMap() {
104 if (dynPcdMap
== null) {
105 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
106 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
108 removeElement(getfpdFrameworkModules());
109 fpdFrameworkModules
= null;
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) {
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
);
131 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
138 public ArrayList
<String
> getDynPcdMapValue(String key
) {
139 return dynPcdMap
.get(key
);
142 Constructor to create a new spd file
144 public FpdFileContents() {
146 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
147 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
152 Constructor for existing document object
155 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea 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();
166 Constructor based on an existing spd file
168 @param f Existing spd file
170 public FpdFileContents(File f
) {
172 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
173 fpdRoot
= fpdd
.getPlatformSurfaceArea();
174 } catch (Exception e
) {
175 System
.out
.println(e
.toString());
179 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
180 if (fpdDynPcdBuildDefs
== null){
181 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
183 return fpdDynPcdBuildDefs
;
186 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
187 if (fpdFrameworkModules
== null){
188 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
190 return fpdFrameworkModules
;
193 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
194 if (getFrameworkModulesCount() == 0){
198 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
199 while(li
.hasNext()) {
200 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
201 if (moduleSa
.getModuleSaBuildOptions() == null) {
204 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
205 if (fvBinding
== null) {
209 String
[] fvNames
= fvBinding
.split(" ");
210 for (int i
= 0; i
< fvNames
.length
; ++i
) {
212 // BugBug : underscore "_" should not be replaced!!!
213 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
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())};
226 public int getFrameworkModulesCount() {
227 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
228 removeElement(getfpdFrameworkModules());
229 fpdFrameworkModules
= null;
232 return getfpdFrameworkModules().getModuleSAList().size();
235 public void getFrameworkModulesInfo(String
[][] saa
) {
236 if (getFrameworkModulesCount() == 0){
240 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
242 while(li
.hasNext()) {
243 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
244 saa
[i
][0] = moduleSa
.getModuleGuid();
245 saa
[i
][1] = moduleSa
.getModuleVersion();
247 saa
[i
][2] = moduleSa
.getPackageGuid();
248 saa
[i
][3] = moduleSa
.getPackageVersion();
249 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
254 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
255 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
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());
266 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
268 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
269 removeElement(getfpdFrameworkModules());
270 fpdFrameworkModules
= null;
273 String
[] s
= key
.split(" ");
274 String archsInKey
= "";
276 for (int i
= 4; i
< s
.length
; ++i
) {
280 archsInKey
= archsInKey
.trim();
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])) {
292 if (moduleSa
.getPackageVersion() != null) {
293 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
297 //ToDo add arch check .
298 if (moduleSa
.getSupArchList() != null) {
299 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
304 if (archsInKey
.length() == 0) {
313 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
314 ModuleSADocument
.ModuleSA moduleSa
= null;
315 if (fpdRoot
.getFrameworkModules() == null) {
318 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
319 if (cursor
.toFirstChild()) {
320 for (int j
= 0; j
< i
; ++j
) {
321 cursor
.toNextSibling();
323 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
329 public void removeModuleSA(int i
) {
330 XmlObject o
= fpdRoot
.getFrameworkModules();
335 XmlCursor cursor
= o
.newCursor();
336 if (cursor
.toFirstChild()) {
337 for (int j
= 0; j
< i
; ++j
) {
338 cursor
.toNextSibling();
341 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
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
);
356 while (cursor
.hasPrevToken()) {
357 cursor
.toPrevToken();
358 if (!cursor
.isText()) {
361 if (cursor
.getObject() == null) {
364 String s
= cursor
.getTextValue();
365 if (s
.matches(regExpNewLineAndSpaces
)) {
370 if (cursor
.isComment()) {
376 if (getFrameworkModulesCount() == 0) {
378 removeElement(getfpdFrameworkModules());
379 fpdFrameworkModules
= null;
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());
398 // delete pcd in ModuleSA but not in MSA files any longer.
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
>();
407 // create vector for module & library instance MIs.
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
);
416 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
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
)) {
424 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
428 // add new Pcd from MSA file to ModuleSA.
430 for (int i
= 0; i
< vMi
.size(); ++i
) {
431 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
432 .getModuleXmlObject(vMi
434 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
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());
442 for (int j
= 0; j
< al
.size(); ++j
) {
443 if (al
.get(j
).startsWith(moduleKey
)) {
449 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
450 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
451 if (spdPcd
== null) {
455 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
459 // AddItem to ModuleSA PcdBuildDefinitions
461 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
462 : msaPcd
.getDefaultValue();
464 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
465 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
474 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
476 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
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])) {
493 if (al
.size() == 0) {
494 defaultPcdValue
.remove(pcdKey
);
495 dynPcdMap
.remove(pcdKey
);
496 String
[] s1
= pcdKey
.split(" ");
497 removeDynamicPcdBuildData(s1
[0], s1
[1]);
502 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
504 public int getPcdDataCount (int i
){
505 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
507 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
510 return msa
.getPcdBuildDefinition().getPcdDataList().size();
514 public void getPcdData (int i
, String
[][] saa
) {
515 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
517 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
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();
534 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
535 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
536 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
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
;
547 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
548 if (cursor
.toFirstChild()){
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) {
561 while(cursor
.toNextSibling());
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){
573 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
574 if (cursor
.toFirstChild()){
576 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
577 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
579 // change item type while not updating dynPcdData????
581 if (itemType
!= null) {
582 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
585 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
586 pcdData
.setMaxDatumSize(new Integer(maxSize
));
589 // if value input is null, keep old value untouched.
592 pcdData
.setValue(value
);
593 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
599 while(cursor
.toNextSibling());
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.
610 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
612 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
613 .getModuleXmlObject(mi
);
614 if (msa
.getPcdCoded() == null) {
618 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
620 // First look through MSA pcd entries.
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
)) {
629 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
632 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
633 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
637 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
640 // Get Pcd help text and original item type.
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
);
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
>();
663 // create vector for module & library instance MIs.
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
);
672 int pcdSourceCount
= 0;
673 for (int i
= 0; i
< vMi
.size(); ++i
) {
674 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
679 if (pcdSourceCount
< 2) {
688 /**Remove PCDBuildDefinition entries from ModuleSA
689 * @param moduleKey identifier of ModuleSA.
690 * @param consumer where these entries come from.
692 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
694 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
695 if (msa
.getPcdCoded() == null) {
699 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
700 ListIterator li
= l
.listIterator();
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();
708 if (cursor
.toFirstChild()) {
710 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
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
)) {
717 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
722 } while (cursor
.toNextSibling());
726 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
735 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
737 public int getLibraryInstancesCount(String key
) {
738 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
739 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
742 return msa
.getLibraries().getInstanceList().size();
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){
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();
761 public void removeLibraryInstance(String key
, int i
) {
762 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
763 if (msa
== null || msa
.getLibraries() == null){
767 XmlCursor cursor
= msa
.getLibraries().newCursor();
768 if (cursor
.toFirstChild()) {
769 for (int j
= 0; j
< i
; ++j
) {
770 cursor
.toNextSibling();
773 while (cursor
.hasPrevToken()) {
774 cursor
.toPrevToken();
775 if (!cursor
.isText()) {
778 String s
= cursor
.getTextValue();
779 if (s
.matches(regExpNewLineAndSpaces
)) {
784 if (cursor
.isComment()) {
789 if (getLibraryInstancesCount(key
) == 0) {
798 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
799 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
801 msa
= getfpdFrameworkModules().addNewModuleSA();
803 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
805 libs
= msa
.addNewLibraries();
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();
817 String comment
= "Pkg: " + pn
+ " Mod: " + mn
818 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
819 cursor
.insertComment(comment
);
828 instance
.setModuleGuid(mg
);
829 instance
.setModuleVersion(mv
);
830 instance
.setPackageGuid(pg
);
831 instance
.setPackageVersion(pv
);
835 public String
getFvBinding(String moduleKey
){
836 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
837 return getFvBinding (moduleSa
);
840 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
841 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
844 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
847 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
848 if (moduleSa
== null ) {
851 if (fvBinding
== null || fvBinding
.length() == 0) {
852 if(moduleSa
.getModuleSaBuildOptions() != null){
853 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
857 if(moduleSa
.getModuleSaBuildOptions() == null){
858 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
861 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
865 public void setFvBinding(String moduleKey
, String fvBinding
){
866 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
867 setFvBinding (moduleSa
, fvBinding
);
870 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
871 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
875 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
876 String
[] fvNamesArray
= fvNameList
.split(" ");
878 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
879 if (fvNamesArray
[i
].equals(fvName
)) {
887 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
888 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
892 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
893 String
[] fvNamesArray
= fvNameList
.split(" ");
895 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
896 if (fvNamesArray
[i
].equals(fvName
)) {
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
) {
908 newFvNameList
+= fvNamesArray
[i
];
910 setFvBinding (moduleSa
, newFvNameList
.trim());
916 * @param fvName The FV name that to be removed from FvBinding List.
918 public void removeFvBindingAll (String fvName
) {
919 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
920 removeElement(getfpdFrameworkModules());
921 fpdFrameworkModules
= null;
925 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
926 while (li
.hasNext()) {
927 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
928 removeFvBinding (moduleSa
, fvName
);
932 public void appendFvBindingAll (String fvName
) {
933 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
934 removeElement(getfpdFrameworkModules());
935 fpdFrameworkModules
= null;
939 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
940 while (li
.hasNext()) {
941 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
942 appendFvBinding (moduleSa
, fvName
);
946 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
947 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
948 removeElement(getfpdFrameworkModules());
949 fpdFrameworkModules
= null;
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
);
963 public void appendFvBinding (String moduleKey
, String fvName
) {
964 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
965 appendFvBinding (moduleSa
, fvName
);
968 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
969 if (moduleSa
== null) {
973 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
974 setFvBinding(moduleSa
, fvName
);
978 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
979 String newFvNameList
= fvNameList
+ " " + fvName
;
980 setFvBinding (moduleSa
, newFvNameList
.trim());
983 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
985 appendFvBinding (moduleKey
, fvName
);
988 public String
getFfsFileNameGuid(String moduleKey
){
989 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
990 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
993 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
996 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
997 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1001 if(msa
.getModuleSaBuildOptions() == null){
1002 msa
.addNewModuleSaBuildOptions();
1005 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1006 if (fileGuid
!= null) {
1007 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1010 XmlCursor cursor
= msaBuildOpts
.newCursor();
1011 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1019 public String
getFfsFormatKey(String moduleKey
){
1020 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1021 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1024 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1027 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1028 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1032 if(msa
.getModuleSaBuildOptions() == null){
1033 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1036 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1039 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1040 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1041 moduleSa
.setForceDebug(dbgEnable
);
1044 public boolean getModuleSAForceDebug (int i
) {
1045 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1046 if (moduleSa
.getForceDebug() == true) {
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) {
1059 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1060 ListIterator li
= lOpt
.listIterator();
1062 while(li
.hasNext()) {
1063 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1064 if (opt
.getBuildTargets() != null) {
1065 saa
[i
][0] = listToString(opt
.getBuildTargets());
1067 saa
[i
][1] = opt
.getToolChainFamily();
1068 saa
[i
][2] = opt
.getTagName();
1069 saa
[i
][3] = opt
.getToolCode();
1071 if (opt
.getSupArchList() != null){
1072 saa
[i
][4] = listToString(opt
.getSupArchList());
1078 saa
[i
][5] = opt
.getStringValue();
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) {
1090 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
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();
1098 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1099 msa
.getModuleSaBuildOptions().addNewOptions();
1101 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1102 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1105 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1106 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1107 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
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();
1117 if (getModuleSAOptionsCount(moduleKey
) == 0) {
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) {
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();
1136 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1137 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1142 /**add pcd information of module mi to a ModuleSA.
1144 * @param moduleSa if null, generate a new ModuleSA.
1146 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1147 //ToDo add Arch filter
1149 if (moduleSa
== null) {
1150 moduleSa
= genModuleSA(mi
, arch
);
1153 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1154 .getModuleXmlObject(mi
);
1155 if (msa
.getPcdCoded() == null) {
1159 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1161 // Implementing InitializePlatformPcdBuildDefinitions
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) {
1172 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
1176 // AddItem to ModuleSA PcdBuildDefinitions
1178 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1180 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1182 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1187 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1189 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1190 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1192 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
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())) {
1204 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
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();
1220 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1221 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1222 cursor
.insertComment(comment
);
1225 e
.printStackTrace();
1230 msa
.setModuleGuid(mi
.getGuid());
1231 msa
.setModuleVersion(mi
.getVersion());
1232 msa
.setPackageGuid(pi
.getGuid());
1233 msa
.setPackageVersion(pi
.getVersion());
1235 Vector
<String
> v
= new Vector
<String
>();
1237 msa
.setSupArchList(v
);
1243 private String
chooseDefaultPcdType (List validPcdTypes
) {
1244 String choosedType
= "";
1245 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1246 choosedType
= "FIXED_AT_BUILD";
1248 else if (validPcdTypes
.contains("DYNAMIC")) {
1249 choosedType
= "DYNAMIC";
1251 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1252 choosedType
= "PATCHABLE_IN_MODULE";
1254 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1255 choosedType
= "DYNAMIC_EX";
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();
1267 // constructe pcd to modulesa mapping first.
1268 // Attention : for any error condition, remove from map this pcd.
1270 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1271 if (pcdConsumer
== null) {
1272 pcdConsumer
= new ArrayList
<String
>();
1275 // Check whether this PCD has already added to ModuleSA, if so, just return.
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(" ")))){
1285 // if pcd type from MSA file is Dynamic
1286 // we must choose one default type from SPD file for it.
1288 List validPcdTypes
= spdPcd
.getValidUsage();
1290 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1292 if (pcdConsumer
.size() > 0) {
1294 // platform should only contain one type for each pcd.
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
));
1303 if (itemType
.equals("DYNAMIC")) {
1304 if (!validPcdTypes
.contains(existingItemType
)) {
1305 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1307 itemType
= existingItemType
;
1310 if (!itemType
.equals(existingItemType
)) {
1311 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1316 // if this is the first occurence of this pcd.
1319 if (itemType
.equals("DYNAMIC")) {
1320 itemType
= chooseDefaultPcdType (validPcdTypes
);
1323 String listValue
= moduleInfo
+ " " + itemType
;
1324 pcdConsumer
.add(listValue
);
1325 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
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
));
1334 if (defaultVal
!= null){
1335 fpdPcd
.setValue(defaultVal
);
1338 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1339 fpdPcd
.setValue("0");
1341 if (dataType
.equals("BOOLEAN")){
1342 fpdPcd
.setValue("FALSE");
1344 if (dataType
.equals("VOID*")) {
1345 fpdPcd
.setValue("");
1349 // Using existing pcd value, if this pcd already exists in other moduleSa.
1351 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1352 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1355 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1358 if (dataType
.equals("UINT8")){
1359 fpdPcd
.setMaxDatumSize(1);
1361 if (dataType
.equals("UINT16")) {
1362 fpdPcd
.setMaxDatumSize(2);
1364 if (dataType
.equals("UINT32")) {
1365 fpdPcd
.setMaxDatumSize(4);
1367 if (dataType
.equals("UINT64")){
1368 fpdPcd
.setMaxDatumSize(8);
1370 if (dataType
.equals("BOOLEAN")){
1371 fpdPcd
.setMaxDatumSize(1);
1373 if (dataType
.equals("VOID*")) {
1374 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1375 fpdPcd
.setMaxDatumSize(maxSize
);
1379 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1380 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
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.
1385 if (al
.size() == 1) {
1386 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1392 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1393 if (datum
== null) {
1396 char ch
= datum
.charAt(0);
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 "{"
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
);
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
);
1425 strValue
= datum
.substring(start
+ 1, end
);
1426 return strValue
.length();
1427 } else if (ch
=='{') {
1428 String
[] strValueArray
;
1430 start
= datum
.indexOf('{');
1431 end
= datum
.lastIndexOf('}');
1432 strValue
= datum
.substring(start
+ 1, end
);
1433 strValue
= strValue
.trim();
1434 if (strValue
.length() == 0) {
1437 strValueArray
= strValue
.split(",");
1438 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1439 Integer value
= Integer
.decode(strValueArray
[index
].trim());
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
);
1447 return strValueArray
.length
;
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
);
1461 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1462 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1467 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1469 return dynPcdMap
.get(pcdKey
);
1472 public int getDynamicPcdBuildDataCount() {
1473 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1474 removeElement(getfpdDynPcdBuildDefs());
1475 fpdDynPcdBuildDefs
= null;
1478 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1481 public void getDynamicPcdBuildData(String
[][] saa
) {
1482 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1483 removeElement(getfpdDynPcdBuildDefs());
1484 fpdDynPcdBuildDefs
= null;
1487 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1488 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
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();
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
));
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
);
1518 if (dataType
.equals("UINT8")){
1519 skuInfo
.setValue("0");
1521 if (dataType
.equals("UINT16")) {
1522 skuInfo
.setValue("0");
1524 if (dataType
.equals("UINT32")) {
1525 skuInfo
.setValue("0");
1527 if (dataType
.equals("UINT64")){
1528 skuInfo
.setValue("0");
1530 if (dataType
.equals("BOOLEAN")){
1531 skuInfo
.setValue("false");
1533 if (dataType
.equals("VOID*")) {
1534 skuInfo
.setValue("");
1537 if (dataType
.equals("UINT8")){
1538 dynPcdData
.setMaxDatumSize(1);
1540 if (dataType
.equals("UINT16")) {
1541 dynPcdData
.setMaxDatumSize(2);
1543 if (dataType
.equals("UINT32")) {
1544 dynPcdData
.setMaxDatumSize(4);
1546 if (dataType
.equals("UINT64")){
1547 dynPcdData
.setMaxDatumSize(8);
1549 if (dataType
.equals("BOOLEAN")){
1550 dynPcdData
.setMaxDatumSize(1);
1552 if (dataType
.equals("VOID*")) {
1553 int maxSize
= setMaxSizeForPointer(defaultVal
);
1554 dynPcdData
.setMaxDatumSize(maxSize
);
1558 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1559 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1564 XmlCursor cursor
= o
.newCursor();
1565 if (cursor
.toFirstChild()) {
1567 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1568 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1569 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1571 if (getDynamicPcdBuildDataCount() == 1) {
1574 fpdDynPcdBuildDefs
= null;
1582 while (cursor
.toNextSibling());
1587 // Get the Sku Info count of ith dyn pcd element.
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;
1597 int skuInfoCount
= 0;
1598 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1599 if (cursor
.toFirstChild()) {
1600 for (int j
= 0; j
< i
; ++j
) {
1601 cursor
.toNextSibling();
1603 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1604 if (pcdData
.getSkuInfoList() == null) {
1608 skuInfoCount
= pcdData
.getSkuInfoList().size();
1612 return skuInfoCount
;
1615 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1616 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1617 removeElement(getfpdDynPcdBuildDefs());
1618 fpdDynPcdBuildDefs
= null;
1622 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1623 if (cursor
.toFirstChild()) {
1624 for (int j
= 0; j
< i
; ++j
) {
1625 cursor
.toNextSibling();
1627 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1628 if (pcdData
.getSkuInfoList() == null) {
1633 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
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();
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;
1661 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1662 if (cursor
.toFirstChild()) {
1663 for (int j
= 0; j
< i
; ++j
) {
1664 cursor
.toNextSibling();
1666 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1667 if (pcdData
.getSkuInfoList() == null) {
1671 value
= pcdData
.getSkuInfoArray(0).getValue();
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;
1686 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1687 if (cursor
.toFirstChild()) {
1688 for (int j
= 0; j
< i
; ++j
) {
1689 cursor
.toNextSibling();
1691 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1692 if (pcdData
.getSkuInfoList() == null) {
1696 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1703 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1704 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1705 removeElement(getfpdDynPcdBuildDefs());
1706 fpdDynPcdBuildDefs
= null;
1710 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1711 if (cursor
.toFirstChild()) {
1712 for (int j
= 0; j
< i
; ++j
) {
1713 cursor
.toNextSibling();
1715 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1716 if (pcdData
.getSkuInfoList() == null) {
1721 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1722 cursor
.toChild(qSkuInfo
);
1729 // generate sku info for ith dyn pcd build data.
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) {
1737 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1738 if (cursor
.toFirstChild()) {
1739 for (int j
= 0; j
< i
; ++j
) {
1740 cursor
.toNextSibling();
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
);
1751 else if (vpdOffset
!= null){
1752 skuInfo
.setVpdOffset(vpdOffset
);
1755 skuInfo
.setValue(value
);
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;
1768 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1769 if (cursor
.toFirstChild()) {
1770 for (int j
= 0; j
< i
; ++j
) {
1771 cursor
.toNextSibling();
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
);
1784 else if (vpdOffset
!= null){
1785 skuInfo
.setVpdOffset(vpdOffset
);
1788 skuInfo
.setValue(value
);
1796 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1797 if (fpdBuildOpts
== null) {
1798 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1800 return fpdBuildOpts
;
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");
1809 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1810 userExts
.setUserID("IMAGES");
1811 userExts
.setIdentifier(new BigInteger("1"));
1812 XmlCursor cursor
= userExts
.newCursor();
1813 cursor
.toEndToken();
1815 cursor
.beginElement(elementFvName
);
1816 cursor
.insertChars(fvName
);
1817 cursor
.toNextToken();
1819 cursor
.beginElement(elementInfFileName
);
1820 cursor
.insertChars(fvName
+ ".inf");
1821 cursor
.toNextToken();
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]);
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]);
1835 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1836 cursor
.toEndToken();
1837 cursor
.toNextToken();
1842 public int getUserExtsIncModCount (String fvName
) {
1843 if (getfpdBuildOpts().getUserExtensionsList() == null) {
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")) {
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()) {
1860 for (i
= 1; cursor
.toNextSibling(); ++i
);
1872 public void getUserExtsIncMods(String fvName
, String
[][] saa
) {
1873 if (getfpdBuildOpts().getUserExtensionsList() == null) {
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");
1888 if (cursor
.toChild(elementUserExts
)) {
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()) {
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
);
1905 }while (cursor
.toNextSibling());
1911 }while (cursor
.toNextSibling(elementUserExts
));
1917 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1918 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1921 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1922 while (li
.hasNext()) {
1923 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1924 if (!ues
.getUserID().equals("IMAGES")) {
1927 XmlCursor cursor
= ues
.newCursor();
1928 cursor
.toFirstChild();
1929 String elementName
= cursor
.getTextValue();
1930 if (elementName
.equals(oldFvName
)) {
1931 cursor
.setTextValue(newFvName
);
1938 public void removeBuildOptionsUserExtensions (String fvName
) {
1939 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1943 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1944 while (li
.hasNext()) {
1945 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1946 if (!ues
.getUserID().equals("IMAGES")) {
1949 XmlCursor cursor
= ues
.newCursor();
1950 cursor
.toFirstChild();
1951 String elementName
= cursor
.getTextValue();
1952 if (elementName
.equals(fvName
)) {
1963 private boolean versionEqual (String v1
, String v2
) {
1965 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1966 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1970 if (v1
!= null && v1
.equals(v2
)) {
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) {
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");
1992 if (cursor
.toChild(elementUserExts
)) {
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()) {
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
)) {
2011 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2014 if (!arch
.equalsIgnoreCase(ar
)) {
2017 if (!versionEqual(moduleVersion
, mv
)) {
2020 if (!versionEqual(packageVersion
, pv
)) {
2025 }while (cursor
.toNextSibling());
2031 }while (cursor
.toNextSibling(elementUserExts
));
2038 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2040 // if there is only one module before remove operation, the whole user extension should be removed.
2042 int moduleAmount
= getUserExtsIncModCount(fvName
);
2043 if (moduleAmount
== 1) {
2044 removeBuildOptionsUserExtensions(fvName
);
2048 if (moduleAmount
> 1) {
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");
2061 if (cursor
.toChild(elementUserExts
)) {
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()) {
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
)) {
2080 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2083 if (!arch
.equalsIgnoreCase(ar
)) {
2086 if (!versionEqual(moduleVersion
, mv
)) {
2089 if (!versionEqual(packageVersion
, pv
)) {
2093 }while (cursor
.toNextSibling());
2099 }while (cursor
.toNextSibling(elementUserExts
));
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
)) {
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")) {
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
);
2130 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2131 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2132 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2135 cursor
.insertAttributeWithValue("Arch", arch
);
2144 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2145 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2146 if (udats
== null) {
2147 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2150 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2151 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
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
);
2160 else if (cursor
.toChild(xmlNs
, "Filename")) {
2163 if (execOrder
!= null) {
2164 at
.setAntCmdOptions(execOrder
);
2166 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2172 public void removeBuildOptionsUserDefAntTask(int i
) {
2173 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2177 XmlCursor cursor
= o
.newCursor();
2178 if (cursor
.toFirstChild()) {
2179 for (int j
= 0; j
< i
; ++j
) {
2180 cursor
.toNextSibling();
2183 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2191 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2192 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2196 XmlCursor cursor
= o
.newCursor();
2197 if (cursor
.toFirstChild()) {
2198 for (int j
= 0; j
< i
; ++j
) {
2199 cursor
.toNextSibling();
2201 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2202 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2207 public int getBuildOptionsUserDefAntTaskCount() {
2208 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2209 if (udats
== null || udats
.getAntTaskList() == null) {
2213 return udats
.getAntTaskList().size();
2216 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2217 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2218 if (udats
== null || udats
.getAntTaskList() == null) {
2222 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2223 ListIterator li
= l
.listIterator();
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();
2232 if (at
.getAntCmdOptions() != null) {
2233 saa
[i
][2] = at
.getAntCmdOptions();
2238 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2239 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2241 opts
= getfpdBuildOpts().addNewOptions();
2243 OptionDocument
.Option opt
= opts
.addNewOption();
2244 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
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
);
2253 if (opt
.isSetBuildTargets()) {
2254 opt
.unsetBuildTargets();
2258 if (toolChain
!= null && toolChain
.length() > 0) {
2259 opt
.setToolChainFamily(toolChain
);
2262 if (opt
.isSetToolChainFamily()) {
2263 opt
.unsetToolChainFamily();
2267 if (tagName
!= null && tagName
.length() > 0) {
2268 opt
.setTagName(tagName
);
2271 if (opt
.isSetTagName()) {
2276 if (toolCmd
!= null && toolCmd
.length() > 0) {
2277 opt
.setToolCode(toolCmd
);
2280 if (opt
.isSetToolCode()) {
2281 opt
.unsetToolCode();
2286 if (archList
!= null) {
2287 opt
.setSupArchList(archList
);
2290 if (opt
.isSetSupArchList()) {
2291 opt
.unsetSupArchList();
2296 public void removeBuildOptionsOpt(int i
){
2298 XmlObject o
= getfpdBuildOpts().getOptions();
2303 XmlCursor cursor
= o
.newCursor();
2304 if (cursor
.toFirstChild()) {
2305 for (int j
= 0; j
< i
; ++j
) {
2306 cursor
.toNextSibling();
2309 if (getBuildOptionsOptCount() == 0) {
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();
2323 XmlCursor cursor
= o
.newCursor();
2324 if (cursor
.toFirstChild()) {
2325 for (int j
= 0; j
< i
; ++j
) {
2326 cursor
.toNextSibling();
2328 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2329 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2334 public int getBuildOptionsOptCount(){
2335 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2338 return getfpdBuildOpts().getOptions().getOptionList().size();
2341 public void getBuildOptionsOpts(String
[][] saa
) {
2342 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2346 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2347 ListIterator li
= lOpt
.listIterator();
2349 while(li
.hasNext()) {
2350 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2351 if (opt
.getBuildTargets() != null) {
2352 saa
[i
][0] = listToString(opt
.getBuildTargets());
2354 saa
[i
][1] = opt
.getToolChainFamily();
2355 if (opt
.getSupArchList() != null){
2356 saa
[i
][2] = listToString(opt
.getSupArchList());