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=fc49cd4151faf641964d3a1e920b9e3a3cdc344f;hb=ceea362ed6c5e41ce78fbf8b9da8428c7f794136;hpb=50d4c727a8fa751d8e687b9cf3756067420a4dc5 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 fc49cd4151..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. @@ -383,15 +384,15 @@ public class FpdFileContents { 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()); // @@ -402,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. @@ -410,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; } } @@ -440,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); @@ -452,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 @@ -462,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; } @@ -607,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; } @@ -676,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++; } } @@ -820,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){ @@ -1151,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); } } @@ -1229,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){ @@ -1251,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(); @@ -1275,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); @@ -1293,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 { @@ -1304,7 +1369,7 @@ public class FpdFileContents { fpdPcd.setValue("FALSE"); } if (dataType.equals("VOID*")) { - fpdPcd.setValue(""); + fpdPcd.setValue("L\"\""); } } // @@ -1455,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; } @@ -1531,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(); @@ -1548,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; } @@ -1675,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(); @@ -1716,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()) { @@ -1755,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(); @@ -1772,7 +1845,7 @@ public class FpdFileContents { cursor.toNextToken(); cursor.beginElement(elementInfFileName); - cursor.insertChars(fvName + ".inf"); + cursor.insertChars(outputFileName); cursor.toNextToken(); cursor.beginElement(elementIncludeModules); @@ -1794,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(); @@ -1824,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"); @@ -1843,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)) { @@ -1890,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(); @@ -1929,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"); @@ -1947,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)) { @@ -1990,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"); @@ -2007,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)) { @@ -2048,16 +2138,20 @@ public class FpdFileContents { } } - public void addModuleIntoBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { - if (moduleInBuildOptionsUserExtensions (fvName, moduleGuid, moduleVersion, packageGuid, packageVersion, arch)) { + 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("IMAGES")) { + if (!ues.getUserID().equals(userId)) { + continue; + } + if (ues.getIdentifier() == null || ues.getIdentifier() != new Integer(id).toString()) { continue; } XmlCursor cursor = ues.newCursor(); @@ -2319,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) { @@ -3269,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); } } @@ -3350,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; @@ -3362,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(); @@ -3374,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(); @@ -3621,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() {