X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FJava%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fplatform%2Fui%2FFpdFileContents.java;h=d8dfb279ba59f2228a4fce57ceb13b79fb57ad91;hp=b15e5d28d8ddebdba0920722c9d3cc5670fa5459;hb=ceea362ed6c5e41ce78fbf8b9da8428c7f794136;hpb=feccee87a78e68d575dbdf44b34ca0cb5a21ea8d diff --git a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java index b15e5d28d8..d8dfb279ba 100644 --- a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java +++ b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java @@ -62,6 +62,7 @@ import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile; import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery; import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification; import org.tianocore.frameworkwizard.packaging.PackageIdentification; +import org.tianocore.frameworkwizard.workspace.Workspace; /** This class processes fpd file contents such as add remove xml elements. @@ -115,8 +116,8 @@ public class FpdFileContents { if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) { continue; } - String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + - " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()); + String ModuleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() + + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()); List lp = moduleSa.getPcdBuildDefinition().getPcdDataList(); ListIterator lpi = lp.listIterator(); while (lpi.hasNext()) { @@ -358,6 +359,9 @@ public class FpdFileContents { if (!cursor.isText()) { break; } + if (cursor.getObject() == null) { + break; + } String s = cursor.getTextValue(); if (s.matches(regExpNewLineAndSpaces)) { continue; @@ -371,22 +375,24 @@ public class FpdFileContents { cursor.pop(); cursor.removeXml(); if (getFrameworkModulesCount() == 0) { - cursor.toParent(); - cursor.removeXml(); + cursor.dispose(); + removeElement(getfpdFrameworkModules()); + fpdFrameworkModules = null; + return; } } cursor.dispose(); } - public boolean adjustPcd (int seqModuleSa) throws Exception { + public boolean adjustPcd (int seqModuleSa, Vector vExceptions) throws Exception { boolean dataModified = false; ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa); int pcdCount = getPcdDataCount(seqModuleSa); String[][] saaModuleSaPcd = new String[pcdCount][7]; getPcdData(seqModuleSa, saaModuleSaPcd); - String mg = moduleSa.getModuleGuid(); + String mg = moduleSa.getModuleGuid().toLowerCase(); String mv = moduleSa.getModuleVersion(); - String pg = moduleSa.getPackageGuid(); + String pg = moduleSa.getPackageGuid().toLowerCase(); String pv = moduleSa.getPackageVersion(); String arch = listToString(moduleSa.getSupArchList()); // @@ -397,6 +403,10 @@ public class FpdFileContents { String[][] saaLib = new String[libCount][5]; getLibraryInstances(moduleKey, saaLib); ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey); + if (mi == null) { + vExceptions.add("Module " + mg + " does NOT exist in workspace."); + throw new Exception ("Module does NOT exist in workspace."); + } Vector vMi = new Vector(); // // create vector for module & library instance MIs. @@ -405,14 +415,19 @@ public class FpdFileContents { for (int j = 0; j < saaLib.length; ++j) { String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4]; ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey); - vMi.add(libMi); + if (libMi != null) { + vMi.add(libMi); + } } nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) { for (int j = 0; j < vMi.size(); ++j) { ModuleIdentification nextMi = vMi.get(j); - if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) { + if (nextMi == null) { + continue; + } + if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], arch, nextMi)) { continue nextPcd; } } @@ -435,11 +450,18 @@ public class FpdFileContents { ArrayList al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName()); if (al != null) { for (int j = 0; j < al.size(); ++j) { - if (al.get(j).contains(moduleKey)) { + if (al.get(j).startsWith(moduleKey)) { continue msaPcdIter; } } } + // Check sup arch conformance for the new PCD + if (msaPcd.getSupArchList() != null) { + String newPcdArch = msaPcd.getSupArchList().toString(); + if (!newPcdArch.toLowerCase().contains(arch.toLowerCase())) { + continue; + } + } PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i)); PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); @@ -447,8 +469,13 @@ public class FpdFileContents { // // ToDo Error // - throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " - + mi.getName()); + String errorMessage = "No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + + mi.getName(); + if (i != 0) { + errorMessage += " Library Instance " + vMi.get(i).getName(); + } + vExceptions.add(errorMessage); + throw new PcdDeclNotFound(errorMessage); } // // AddItem to ModuleSA PcdBuildDefinitions @@ -457,7 +484,7 @@ public class FpdFileContents { : msaPcd.getDefaultValue(); genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), - msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa); + msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd); dataModified = true; } @@ -475,7 +502,7 @@ public class FpdFileContents { String[] s = moduleInfo.split(" "); for(int i = 0; i < al.size(); ++i){ String consumer = al.get(i); - if (consumer.contains(s[0]) && consumer.contains(s[2])){ + if (consumer.contains(s[0].toLowerCase()) && consumer.contains(s[2].toLowerCase())){ String[] consumerPart = consumer.split(" "); if (!consumerPart[4].equals(s[4])) { continue; @@ -573,12 +600,21 @@ public class FpdFileContents { // // change item type while not updating dynPcdData???? // - pcdData.setItemType(PcdItemTypes.Enum.forString(itemType)); - if(pcdData.getDatumType().equals("VOID*")) { + if (itemType != null) { + pcdData.setItemType(PcdItemTypes.Enum.forString(itemType)); + } + + if(pcdData.getDatumType().equals("VOID*") && maxSize != null) { pcdData.setMaxDatumSize(new Integer(maxSize)); } - pcdData.setValue(value); - defaultPcdValue.put(cName + " " + tsGuid, value); + // + // if value input is null, keep old value untouched. + // + if (value != null) { + pcdData.setValue(value); + defaultPcdValue.put(cName + " " + tsGuid, value); + } + break; } } @@ -593,54 +629,49 @@ public class FpdFileContents { * @param sa Results: HelpText, Original item type. * @return */ - public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{ - try { - - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi); - if (msa.getPcdCoded() == null) { - return false; + public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa, Vector validPcdTypes) throws Exception{ + + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile + .getModuleXmlObject(mi); + if (msa.getPcdCoded() == null) { + return false; + } + + PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi); + // + // First look through MSA pcd entries. + // + List l = msa.getPcdCoded().getPcdEntryList(); + ListIterator li = l.listIterator(); + while (li.hasNext()) { + PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next(); + if (!msaPcd.getCName().equals(cName)) { + continue; } - - Map m = new HashMap(); - m.put("ModuleSurfaceArea", msa); - SurfaceAreaQuery.setDoc(m); - PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi); - // - // First look through MSA pcd entries. - // - List l = msa.getPcdCoded().getPcdEntryList(); - ListIterator li = l.listIterator(); - while(li.hasNext()) { - PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next(); - if (!msaPcd.getCName().equals(cName)) { - continue; - } - if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) { - continue; - } - PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); - if (spdPcd == null) { - // - // ToDo Error - // - throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName()); - } + if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) { + continue; + } + PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); + if (spdPcd == null || spdPcd.getValidUsage() == null) { // - // Get Pcd help text and original item type. + // ToDo Error // - sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText(); - sa[1] = msaPcd.getPcdItemType()+""; - sa[2] = msa.getModuleDefinitions().getBinaryModule()+""; - return true; + throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName()); } - - - } - catch (Exception e){ - e.printStackTrace(); - throw e; + // + // Get Pcd help text and original item type. + // + sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText(); + sa[1] = msaPcd.getPcdItemType() + ""; + sa[2] = msa.getModuleDefinitions().getBinaryModule() + ""; + ListIterator iter = spdPcd.getValidUsage().listIterator(); + while (iter.hasNext()) { + String usage = iter.next().toString(); + validPcdTypes.add(usage); + } + return true; } - + return false; } @@ -662,7 +693,7 @@ public class FpdFileContents { int pcdSourceCount = 0; for (int i = 0; i < vMi.size(); ++i) { - if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) { + if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, null, vMi.get(i))) { pcdSourceCount++; } } @@ -806,7 +837,7 @@ public class FpdFileContents { XmlCursor cursor = instance.newCursor(); try{ String comment = "Pkg: " + pn + " Mod: " + mn - + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1); + + " Path: " + libMi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1); cursor.insertComment(comment); } catch (Exception e){ @@ -1137,46 +1168,45 @@ public class FpdFileContents { public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception { //ToDo add Arch filter - try { - if (moduleSa == null) { - moduleSa = genModuleSA(mi, arch); - } - - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi); - if (msa.getPcdCoded() == null) { - return; - } - - Map m = new HashMap(); - m.put("ModuleSurfaceArea", msa); - SurfaceAreaQuery.setDoc(m); - PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi); - // - // Implementing InitializePlatformPcdBuildDefinitions - // - List l = msa.getPcdCoded().getPcdEntryList(); - ListIterator li = l.listIterator(); - while(li.hasNext()) { - PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next(); - PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); - if (spdPcd == null) { - // - // ToDo Error - // - throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName()); - } + if (moduleSa == null) { + moduleSa = genModuleSA(mi, arch); + } + + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile + .getModuleXmlObject(mi); + if (msa.getPcdCoded() == null) { + return; + } + + PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi); + // + // Implementing InitializePlatformPcdBuildDefinitions + // + List l = msa.getPcdCoded().getPcdEntryList(); + ListIterator li = l.listIterator(); + while (li.hasNext()) { + PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next(); + if (msaPcd.getSupArchList() != null) { + if (!msaPcd.getSupArchList().toString().toLowerCase().contains(arch.toLowerCase())) { + continue; + } + } + PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); + if (spdPcd == null) { // - // AddItem to ModuleSA PcdBuildDefinitions + // ToDo Error // - String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue(); - - genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa); + throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + "\n used by Module " + + mi.getName() + " or its Library Instances."); } - - } - catch (Exception e){ - - throw e; + // + // AddItem to ModuleSA PcdBuildDefinitions + // + String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue(); + + genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType() + .toString(), + spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd); } } @@ -1215,7 +1245,7 @@ public class FpdFileContents { XmlCursor cursor = msa.newCursor(); try{ String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: " - + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1); + + mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1); cursor.insertComment(comment); } catch(Exception e){ @@ -1237,7 +1267,25 @@ public class FpdFileContents { return msa; } - private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) + private String chooseDefaultPcdType (List validPcdTypes) { + String choosedType = ""; + if (validPcdTypes.contains("FIXED_AT_BUILD")) { + choosedType = "FIXED_AT_BUILD"; + } + else if (validPcdTypes.contains("DYNAMIC")) { + choosedType = "DYNAMIC"; + } + else if (validPcdTypes.contains("PATCHABLE_IN_MODULE")) { + choosedType = "PATCHABLE_IN_MODULE"; + } + else if (validPcdTypes.contains("DYNAMIC_EX")) { + choosedType = "DYNAMIC_EX"; + } + return choosedType; + } + + private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, + ModuleSADocument.ModuleSA moduleSa, PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd) throws PcdItemTypeConflictException, PcdValueMalFormed{ if (moduleSa.getPcdBuildDefinition() == null){ moduleSa.addNewPcdBuildDefinition(); @@ -1261,12 +1309,43 @@ public class FpdFileContents { return; } } + // if pcd type from MSA file is Dynamic + // we must choose one default type from SPD file for it. + // + List validPcdTypes = spdPcd.getValidUsage(); // // Using existing Pcd type, if this pcd already exists in other ModuleSA // if (pcdConsumer.size() > 0) { + // + // platform should only contain one type for each pcd. + // + String existingItemType = itemType (pcdConsumer.get(0)); + for (int i = 1; i < pcdConsumer.size(); ++i) { + if (!existingItemType.equals(itemType(pcdConsumer.get(i)))) { + throw new PcdItemTypeConflictException (cName, pcdConsumer.get(0), pcdConsumer.get(i)); + } + } - itemType = itemType (pcdConsumer.get(0)); + if (itemType.equals("DYNAMIC")) { + if (!validPcdTypes.contains(existingItemType)) { + throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0)); + } + itemType = existingItemType; + } + else { + if (!itemType.equals(existingItemType)) { + throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0)); + } + } + } + // + // if this is the first occurence of this pcd. + // + else { + if (itemType.equals("DYNAMIC")) { + itemType = chooseDefaultPcdType (validPcdTypes); + } } String listValue = moduleInfo + " " + itemType; pcdConsumer.add(listValue); @@ -1279,7 +1358,7 @@ public class FpdFileContents { fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType)); fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType)); - if (defaultVal != null){ + if (defaultVal != null && defaultVal.length() > 0){ fpdPcd.setValue(defaultVal); } else { @@ -1290,7 +1369,7 @@ public class FpdFileContents { fpdPcd.setValue("FALSE"); } if (dataType.equals("VOID*")) { - fpdPcd.setValue(""); + fpdPcd.setValue("L\"\""); } } // @@ -1441,7 +1520,7 @@ public class FpdFileContents { saa[i][1] = dynPcd.getToken().toString(); saa[i][2] = dynPcd.getTokenSpaceGuidCName(); saa[i][3] = dynPcd.getMaxDatumSize()+""; - saa[i][4] = dynPcd.getDatumType().toString(); + saa[i][4] = dynPcd.getDatumType()+""; ++i; } @@ -1517,7 +1596,10 @@ public class FpdFileContents { if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) { if (getDynamicPcdBuildDataCount() == 1) { - cursor.toParent(); + cursor.dispose(); + removeElement(o); + fpdDynPcdBuildDefs = null; + return; } cursor.removeXml(); cursor.dispose(); @@ -1534,6 +1616,8 @@ public class FpdFileContents { public int getDynamicPcdSkuInfoCount(int i){ if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) { + removeElement(getfpdDynPcdBuildDefs()); + fpdDynPcdBuildDefs = null; return 0; } @@ -1661,9 +1745,10 @@ public class FpdFileContents { return; } else { - QName qSkuInfo = new QName(xmlNs, "SkuInfo"); - cursor.toChild(qSkuInfo); - cursor.removeXml(); + pcdData.getSkuInfoList().clear(); +// QName qSkuInfo = new QName(xmlNs, "SkuInfo"); +// cursor.toChild(qSkuInfo); +// cursor.removeXml(); } } cursor.dispose(); @@ -1702,9 +1787,11 @@ public class FpdFileContents { public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, String hiiDefault, String vpdOffset, String value, int i){ -// if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) { -// return; -// } + if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) { + removeElement(getfpdDynPcdBuildDefs()); + fpdDynPcdBuildDefs = null; + return; + } XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor(); if (cursor.toFirstChild()) { @@ -1741,15 +1828,15 @@ public class FpdFileContents { return fpdBuildOpts; } - public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector includeModules) { + public void genBuildOptionsUserExtensions(String fvName, String userId, String id, String outputFileName, Vector includeModules) { QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName elementInfFileName = new QName(xmlNs, "InfFileName"); QName elementModule = new QName(xmlNs, "Module"); UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions(); - userExts.setUserID("IMAGES"); - userExts.setIdentifier(new BigInteger("1")); + userExts.setUserID(userId); + userExts.setIdentifier(id); XmlCursor cursor = userExts.newCursor(); cursor.toEndToken(); @@ -1758,7 +1845,7 @@ public class FpdFileContents { cursor.toNextToken(); cursor.beginElement(elementInfFileName); - cursor.insertChars(fvName + ".inf"); + cursor.insertChars(outputFileName); cursor.toNextToken(); cursor.beginElement(elementIncludeModules); @@ -1780,15 +1867,19 @@ public class FpdFileContents { cursor.dispose(); } - public int getUserExtsIncModCount (String fvName) { + public int getUserExtsIncModCount (String fvName, String userId, int id) { if (getfpdBuildOpts().getUserExtensionsList() == null) { return -1; } + ListIterator li = getfpdBuildOpts().getUserExtensionsList().listIterator(); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); while (li.hasNext()) { UserExtensionsDocument.UserExtensions ues = li.next(); - if (!ues.getUserID().equals("IMAGES")) { + if (!ues.getUserID().equals(userId)) { + continue; + } + if (ues.getIdentifier() == null || ues.getIdentifier() != new Integer(id).toString()) { continue; } XmlCursor cursor = ues.newCursor(); @@ -1810,14 +1901,15 @@ public class FpdFileContents { return -1; } - public void getUserExtsIncMods(String fvName, String[][] saa) { + public void getUserExtsIncMods(String fvName, String userId, int id, String[][] saa) { if (getfpdBuildOpts().getUserExtensionsList() == null) { return; } - + XmlCursor cursor = getfpdBuildOpts().newCursor(); QName elementUserExts = new QName (xmlNs, "UserExtensions"); QName attribUserId = new QName ("UserID"); + QName attribId = new QName ("Identifier"); QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName attribModuleGuid = new QName("ModuleGuid"); @@ -1829,7 +1921,7 @@ public class FpdFileContents { if (cursor.toChild(elementUserExts)) { do { cursor.push(); - if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) { cursor.toChild(elementFvName); String elementName = cursor.getTextValue(); if (elementName.equals(fvName)) { @@ -1876,15 +1968,18 @@ public class FpdFileContents { } - public void removeBuildOptionsUserExtensions (String fvName) { + public void removeBuildOptionsUserExtensions (String fvName, String userId, int id) { if (getfpdBuildOpts().getUserExtensionsList() == null) { return; } - + ListIterator li = getfpdBuildOpts().getUserExtensionsList().listIterator(); while (li.hasNext()) { UserExtensionsDocument.UserExtensions ues = li.next(); - if (!ues.getUserID().equals("IMAGES")) { + if (!ues.getUserID().equals(userId)) { + continue; + } + if (ues.getIdentifier()== null || ues.getIdentifier() != new Integer(id).toString()) { continue; } XmlCursor cursor = ues.newCursor(); @@ -1915,13 +2010,13 @@ public class FpdFileContents { return false; } - public boolean moduleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { + public boolean moduleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { boolean inList = false; - if (getUserExtsIncModCount(fvName) > 0) { - + if (getUserExtsIncModCount(fvName, userId, id) > 0) { XmlCursor cursor = getfpdBuildOpts().newCursor(); QName elementUserExts = new QName (xmlNs, "UserExtensions"); QName attribUserId = new QName ("UserID"); + QName attribId = new QName ("Identifier"); QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName attribModuleGuid = new QName("ModuleGuid"); @@ -1933,7 +2028,7 @@ public class FpdFileContents { if (cursor.toChild(elementUserExts)) { do { cursor.push(); - if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) { cursor.toChild(elementFvName); String elementName = cursor.getTextValue(); if (elementName.equals(fvName)) { @@ -1976,12 +2071,21 @@ public class FpdFileContents { return inList; } - public void removeModuleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { - if (getUserExtsIncModCount(fvName) > 0) { - + public void removeModuleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { + // + // if there is only one module before remove operation, the whole user extension should be removed. + // + int moduleAmount = getUserExtsIncModCount(fvName, userId, id); + if (moduleAmount == 1) { + removeBuildOptionsUserExtensions(fvName, userId, id); + return; + } + + if (moduleAmount > 1) { XmlCursor cursor = getfpdBuildOpts().newCursor(); QName elementUserExts = new QName (xmlNs, "UserExtensions"); QName attribUserId = new QName ("UserID"); + QName attribId = new QName ("Identifier"); QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName attribModuleGuid = new QName("ModuleGuid"); @@ -1993,7 +2097,7 @@ public class FpdFileContents { if (cursor.toChild(elementUserExts)) { do { cursor.push(); - if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) { cursor.toChild(elementFvName); String elementName = cursor.getTextValue(); if (elementName.equals(fvName)) { @@ -2034,6 +2138,49 @@ public class FpdFileContents { } } + public void addModuleIntoBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { + if (moduleInBuildOptionsUserExtensions (fvName, userId, id, moduleGuid, moduleVersion, packageGuid, packageVersion, arch)) { + return; + } + + ListIterator li = getfpdBuildOpts().getUserExtensionsList().listIterator(); + QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); + QName elementModule = new QName(xmlNs, "Module"); + while (li.hasNext()) { + UserExtensionsDocument.UserExtensions ues = li.next(); + if (!ues.getUserID().equals(userId)) { + continue; + } + if (ues.getIdentifier() == null || ues.getIdentifier() != new Integer(id).toString()) { + continue; + } + XmlCursor cursor = ues.newCursor(); + cursor.toFirstChild(); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toNextSibling(elementIncludeModules); + cursor.toLastChild(); + cursor.toEndToken(); + cursor.toNextToken(); + cursor.beginElement(elementModule); + cursor.insertAttributeWithValue("ModuleGuid", moduleGuid); + if (!moduleVersion.equals("null") && moduleVersion.length() != 0) { + cursor.insertAttributeWithValue("ModuleVersion", moduleVersion); + } + cursor.insertAttributeWithValue("PackageGuid", packageGuid); + if (!packageVersion.equals("null") && packageVersion.length() != 0) { + cursor.insertAttributeWithValue("PackageVersion", packageVersion); + } + + cursor.insertAttributeWithValue("Arch", arch); + cursor.dispose(); + return; + } + cursor.dispose(); + } + + } + public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) { UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks(); if (udats == null) { @@ -2266,10 +2413,8 @@ public class FpdFileContents { } public void updateBuildOptionsFfsSectionsType(int i, String type) { - BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs(); - if (type != null) { - ffs.addNewSections().setEncapsulationType(type); - } + BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i); + ffs.getSections().setEncapsulationType(type); } public void genBuildOptionsFfsAttribute(int i, String name, String value) { @@ -2369,7 +2514,9 @@ public class FpdFileContents { if (sections == null){ sections = ffs.addNewSections(); } - sections.addNewSections().setEncapsulationType(encapType); + BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections(); + sections2.setEncapsulationType(encapType); + sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32")); } public void removeBuildOptionsFfsSectionsSections(int i, int j) { @@ -2495,9 +2642,9 @@ public class FpdFileContents { ListIterator li = sections2.getSectionList().listIterator(); while(li.hasNext()) { BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next(); - if (section.isSetSectionType()) { - al.add(section.getSectionType().toString()); - } +// if (section.isSetSectionType()) { + al.add(section.getSectionType()+""); +// } } } @@ -2546,7 +2693,7 @@ public class FpdFileContents { if (ffs.getSections().getSectionList() != null){ ListIterator li = ffs.getSections().getSectionList().listIterator(); while (li.hasNext()) { - firstLevelSection.add(li.next().getSectionType().toString()); + firstLevelSection.add(li.next().getSectionType()+""); } } if (ffs.getSections().getSectionsList() != null) { @@ -3214,32 +3361,31 @@ public class FpdFileContents { * @param name * @param value */ - public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) { + public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value, String newName) { boolean fvImageExists = false; - if (getfpdFlash().getFvImages() == null) { - return; - } - List l = getfpdFlash().getFvImages().getFvImageList(); - if (l == null) { - return; - } - ListIterator li = l.listIterator(); - while(li.hasNext()) { - FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next(); - if (!fi.getType().toString().equals(type) && !type.equals("ALL")) { - continue; - } - if (!fi.getFvImageNamesList().contains(fvName)) { - continue; + if (getfpdFlash().getFvImages() != null) { + + List l = getfpdFlash().getFvImages().getFvImageList(); + if (l != null) { + ListIterator li = l.listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage) li.next(); + if (!fi.getType().toString().equals(type) && !type.equals("ALL")) { + continue; + } + if (!fi.getFvImageNamesList().contains(fvName)) { + continue; + } + fvImageExists = true; + setFvImagesFvImageNameValue(fi, name, value, newName); + } } - fvImageExists = true; - setFvImagesFvImageNameValue (fi, name, value, null); } - + if (!fvImageExists) { HashMap map = new HashMap(); map.put(name, value); - genFvImagesFvImage(new String[]{fvName}, type, map); + genFvImagesFvImage(new String[] { fvName }, type, map); } } @@ -3295,7 +3441,7 @@ public class FpdFileContents { FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue(); nv.setName(name); nv.setValue(value); - if (newName != null) { + if (newName != null && !newName.equals(name)) { nv.setName(newName); } return; @@ -3307,7 +3453,7 @@ public class FpdFileContents { FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject(); if (nv.getName().equals(name)) { nv.setValue(value); - if (newName != null) { + if (newName != null && !newName.equals(name)) { nv.setName(newName); } cursor.dispose(); @@ -3319,7 +3465,7 @@ public class FpdFileContents { FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue(); nv.setName(name); nv.setValue(value); - if (newName != null) { + if (newName != null && !newName.equals(name)) { nv.setName(newName); } cursor.dispose(); @@ -3566,9 +3712,36 @@ class PcdItemTypeConflictException extends Exception { private static final long serialVersionUID = 1L; private String details = null; - PcdItemTypeConflictException(String pcdName, String info){ + PcdItemTypeConflictException (String pcdName, String info) { ModuleIdentification mi = WorkspaceProfile.getModuleId(info); - details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName(); + if (mi != null) { + details = pcdName + " ItemType Conflicts with " + mi.getName() + "\n in Pkg " + mi.getPackageId().getName(); + } + else { + details = pcdName + " ItemType Conflicts with \n" + info; + } + } + + PcdItemTypeConflictException (String pcdName, String info1, String info2) { + ModuleIdentification mi1 = WorkspaceProfile.getModuleId(info1); + ModuleIdentification mi2 = WorkspaceProfile.getModuleId(info2); + String moduleInfo1 = ""; + String moduleInfo2 = ""; + if (mi1 != null) { + moduleInfo1 = mi1.getName() + " in Pkg " + mi1.getPackageId().getName(); + } + else { + moduleInfo1 = info1; + } + + if (mi2 != null) { + moduleInfo2 = mi2.getName() + " in Pkg " + mi2.getPackageId().getName(); + } + else { + moduleInfo2 = info2; + } + + details = pcdName + " ItemType Conflicts in \n" + moduleInfo1 + "\n and " + moduleInfo2; } public String getMessage() {