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=4bca7fe22d047d22937b183565d3129d466028f9;hp=5f4e0b522eeb17e69ae43a7175400f97f80abcd4;hb=e64872fa8b577189395edb6624b9e178989fd3e5;hpb=5f480cb5e8d562cd44d5d87472d0100b8842ba5e 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 5f4e0b522e..4bca7fe22d 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 @@ -58,10 +58,12 @@ import org.tianocore.PlatformHeaderDocument; import org.tianocore.SkuInfoDocument; import org.tianocore.UserDefinedAntTasksDocument; import org.tianocore.UserExtensionsDocument; +import org.tianocore.LibrariesDocument.Libraries.Instance; 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 +385,15 @@ public class FpdFileContents { cursor.dispose(); } - public boolean adjustPcd (int seqModuleSa) throws Exception { + public boolean adjustPcd (String 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 +404,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 +416,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 +451,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 +470,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 +485,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; } @@ -501,8 +524,8 @@ public class FpdFileContents { // // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch" // - public int getPcdDataCount (int i){ - ModuleSADocument.ModuleSA msa = getModuleSA(i); + public int getPcdDataCount (String key){ + ModuleSADocument.ModuleSA msa = getModuleSA(key); if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){ return 0; @@ -511,8 +534,8 @@ public class FpdFileContents { } - public void getPcdData (int i, String[][] saa) { - ModuleSADocument.ModuleSA msa = getModuleSA(i); + public void getPcdData (String key, String[][] saa) { + ModuleSADocument.ModuleSA msa = getModuleSA(key); if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){ return; @@ -531,8 +554,8 @@ public class FpdFileContents { } } - public void removePcdData (int seqModuleSa, String cName, String tsGuid) { - ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa); + public void removePcdData (String key, String cName, String tsGuid) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(key); if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){ return; } @@ -551,7 +574,7 @@ public class FpdFileContents { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject(); if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) { maintainDynPcdMap(cName + " " + tsGuid, moduleKey); - if (getPcdDataCount(seqModuleSa) == 1) { + if (getPcdDataCount(key) == 1) { cursor.toParent(); } cursor.removeXml(); @@ -578,12 +601,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; } } @@ -598,54 +630,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; } @@ -667,7 +694,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++; } } @@ -754,17 +781,50 @@ public class FpdFileContents { } } - public void removeLibraryInstance(String key, int i) { + public boolean instanceExistsInModuleSA (String key, String mg, String mv, String pg, String pv) { + int count = 0; + if ((count = getLibraryInstancesCount(key)) > 0) { + String[][] saa = new String[count][5]; + getLibraryInstances (key, saa); + for (int i = 0; i < count; ++i) { + if (mg.equalsIgnoreCase(saa[i][1]) && pg.equalsIgnoreCase(saa[i][3])) { + boolean modVerMatch = false; + boolean pkgVerMatch = false; + if ((mv.equals("null") || saa[i][2] == null)) { + modVerMatch = true; + } + if (pv.equals("null") || saa[i][4] == null) { + pkgVerMatch = true; + } + if (modVerMatch && pkgVerMatch) { + return true; + } + else { + if (mv.equals(saa[i][2]) && pv.equals(saa[i][4])) { + return true; + } + } + } + } + } + return false; + } + + public void removeLibraryInstance(String key, String instanceKey) { ModuleSADocument.ModuleSA msa = getModuleSA(key); if (msa == null || msa.getLibraries() == null){ return ; } + String[] instanceInfo = instanceKey.split(" "); XmlCursor cursor = msa.getLibraries().newCursor(); if (cursor.toFirstChild()) { - for (int j = 0; j < i; ++j) { - cursor.toNextSibling(); + do { + Instance libIns = (Instance)cursor.getObject(); + if (libIns.getModuleGuid().equalsIgnoreCase(instanceInfo[0]) && libIns.getPackageGuid().equalsIgnoreCase(instanceInfo[2])) { + break; } + }while (cursor.toNextSibling()); cursor.push(); while (cursor.hasPrevToken()) { cursor.toPrevToken(); @@ -811,7 +871,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){ @@ -1142,46 +1202,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); } } @@ -1220,7 +1279,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){ @@ -1242,7 +1301,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(); @@ -1266,12 +1343,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); @@ -1284,7 +1392,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 { @@ -1295,7 +1403,7 @@ public class FpdFileContents { fpdPcd.setValue("FALSE"); } if (dataType.equals("VOID*")) { - fpdPcd.setValue(""); + fpdPcd.setValue("L\"\""); } } // @@ -1446,7 +1554,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; } @@ -1522,7 +1630,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(); @@ -1539,6 +1650,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; } @@ -1666,9 +1779,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(); @@ -1707,9 +1821,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()) { @@ -1746,15 +1862,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(); @@ -1763,7 +1879,7 @@ public class FpdFileContents { cursor.toNextToken(); cursor.beginElement(elementInfFileName); - cursor.insertChars(fvName + ".inf"); + cursor.insertChars(outputFileName); cursor.toNextToken(); cursor.beginElement(elementIncludeModules); @@ -1785,15 +1901,19 @@ public class FpdFileContents { cursor.dispose(); } - public int getUserExtsIncModCount (String fvName) { + public int getUserExtsIncModCount (String fvName, String userId, String 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().equals(id)) { continue; } XmlCursor cursor = ues.newCursor(); @@ -1815,14 +1935,15 @@ public class FpdFileContents { return -1; } - public void getUserExtsIncMods(String fvName, String[][] saa) { + public void getUserExtsIncMods(String fvName, String userId, String 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"); @@ -1834,7 +1955,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)) { @@ -1881,15 +2002,18 @@ public class FpdFileContents { } - public void removeBuildOptionsUserExtensions (String fvName) { + public void removeBuildOptionsUserExtensions (String fvName, String userId, String 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().equals(id)) { continue; } XmlCursor cursor = ues.newCursor(); @@ -1920,13 +2044,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, String 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"); @@ -1938,7 +2062,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)) { @@ -1981,12 +2105,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, String 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"); @@ -1998,7 +2131,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)) { @@ -2039,6 +2172,49 @@ public class FpdFileContents { } } + public void addModuleIntoBuildOptionsUserExtensions (String fvName, String userId, String 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().equals(id)) { + 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) { @@ -2271,10 +2447,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) { @@ -3221,32 +3395,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); } } @@ -3302,7 +3475,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; @@ -3314,7 +3487,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(); @@ -3326,7 +3499,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(); @@ -3573,9 +3746,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() {