X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fplatform%2Fui%2FFpdFileContents.java;h=b54715b877b59818e794350476983db9db1bc764;hb=73d9b1c494ac88a0e875a047fb3f11aa91e87c4d;hp=2b1cffe8909f5299e4999bf2040d3208940666f2;hpb=daa4663bdd6c65b7e4423bd7b9f8b2cc72ee9bab;p=mirror_edk2.git diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java index 2b1cffe890..b54715b877 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java @@ -57,10 +57,11 @@ import org.tianocore.LicenseDocument; import org.tianocore.PlatformHeaderDocument; import org.tianocore.SkuInfoDocument; import org.tianocore.UserDefinedAntTasksDocument; -import org.tianocore.frameworkwizard.platform.ui.global.GlobalData; +import org.tianocore.UserExtensionsDocument; +import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile; import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery; -import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification; -import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification; +import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification; +import org.tianocore.frameworkwizard.packaging.PackageIdentification; /** This class processes fpd file contents such as add remove xml elements. @@ -88,6 +89,13 @@ public class FpdFileContents { private HashMap> dynPcdMap = null; + private HashMap defaultPcdValue = new HashMap(); + + private String itemType (String pcdInfo) { + + return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1); + } + /** * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings. */ @@ -181,6 +189,32 @@ public class FpdFileContents { return fpdFrameworkModules; } + public void getFrameworkModuleGuid (String fvName, Vector vGuid) { + if (getFrameworkModulesCount() == 0){ + return; + } + + ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); + while(li.hasNext()) { + ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); + if (moduleSa.getModuleSaBuildOptions() == null) { + continue; + } + String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding(); + if (fvBinding == null) { + continue; + } + + String[] fvNames = fvBinding.split(" "); + for (int i = 0; i < fvNames.length; ++i) { + if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) { + vGuid.add(moduleSa.getModuleGuid()); + break; + } + } + } + } + public int getFrameworkModulesCount() { if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){ removeElement(getfpdFrameworkModules()); @@ -198,13 +232,13 @@ public class FpdFileContents { ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); int i = 0; while(li.hasNext()) { - ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next(); - saa[i][0] = msa.getModuleGuid(); - saa[i][1] = msa.getModuleVersion(); + ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); + saa[i][0] = moduleSa.getModuleGuid(); + saa[i][1] = moduleSa.getModuleVersion(); - saa[i][2] = msa.getPackageGuid(); - saa[i][3] = msa.getPackageVersion(); - saa[i][4] = listToString(msa.getSupArchList()); + saa[i][2] = moduleSa.getPackageGuid(); + saa[i][3] = moduleSa.getPackageVersion(); + saa[i][4] = listToString(moduleSa.getSupArchList()); ++i; } } @@ -222,12 +256,22 @@ public class FpdFileContents { } public ModuleSADocument.ModuleSA getModuleSA(String key) { - String[] s = key.split(" "); + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) { removeElement(getfpdFrameworkModules()); fpdFrameworkModules = null; return null; } + String[] s = key.split(" "); + String archsInKey = ""; + if (s.length > 4) { + for (int i = 4; i < s.length; ++i) { + archsInKey += s[i]; + archsInKey += " "; + } + archsInKey = archsInKey.trim(); + } + ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); while(li.hasNext()) { ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); @@ -242,13 +286,17 @@ public class FpdFileContents { continue; } } - //ToDo add arch check for s[4] + //ToDo add arch check . if (moduleSa.getSupArchList() != null) { - if (!listToString(moduleSa.getSupArchList()).equals(s[4])) { - continue; + if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) { + return moduleSa; + } + } + else { + if (archsInKey.length() == 0) { + return moduleSa; } } - return moduleSa; } } return null; @@ -329,19 +377,24 @@ public class FpdFileContents { int libCount = getLibraryInstancesCount(moduleKey); String[][] saaLib = new String[libCount][5]; getLibraryInstances(moduleKey, saaLib); - ModuleIdentification mi = GlobalData.getModuleId(moduleKey); + ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey); Vector vMi = new Vector(); + // + // create vector for module & library instance MIs. + // vMi.add(mi); + 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); + } + try { nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) { - if (GlobalData.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], mi)){ - continue; - } - for (int j = 0; j < saaLib.length; ++j) { - String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4]; - ModuleIdentification libMi = GlobalData.getModuleId(libKey); - vMi.add(libMi); - if (GlobalData.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], libMi)) { + + for (int j = 0; j < vMi.size(); ++j) { + ModuleIdentification nextMi = vMi.get(j); + if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) { continue nextPcd; } } @@ -350,7 +403,7 @@ public class FpdFileContents { } } catch (Exception e) { - + throw e; } // // add new Pcd from MSA file to ModuleSA. @@ -358,7 +411,7 @@ public class FpdFileContents { try { for (int i = 0; i < vMi.size(); ++i) { - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) GlobalData + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile .getModuleXmlObject(vMi .get(i)); if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) { @@ -376,9 +429,6 @@ public class FpdFileContents { } } - Map m = new HashMap(); - m.put("ModuleSurfaceArea", msa); - SurfaceAreaQuery.setDoc(m); PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i)); PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); if (spdPcd == null) { @@ -428,6 +478,7 @@ public class FpdFileContents { } if (al.size() == 0) { + defaultPcdValue.remove(pcdKey); dynPcdMap.remove(pcdKey); String[] s1 = pcdKey.split(" "); removeDynamicPcdBuildData(s1[0], s1[1]); @@ -511,11 +562,15 @@ public class FpdFileContents { do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject(); if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) { + // + // change item type while not updating dynPcdData???? + // pcdData.setItemType(PcdItemTypes.Enum.forString(itemType)); if(pcdData.getDatumType().equals("VOID*")) { pcdData.setMaxDatumSize(new Integer(maxSize)); } pcdData.setValue(value); + defaultPcdValue.put(cName + " " + tsGuid, value); break; } } @@ -533,7 +588,7 @@ public class FpdFileContents { public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{ try { - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi); + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi); if (msa.getPcdCoded() == null) { return false; } @@ -586,7 +641,7 @@ public class FpdFileContents { */ public void removePcdData(String moduleKey, ModuleIdentification consumer) { try { - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(consumer); + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer); if (msa.getPcdCoded() == null) { return; } @@ -600,25 +655,18 @@ public class FpdFileContents { if (moduleSA.getPcdBuildDefinition() != null) { XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor(); if (cursor.toFirstChild()) { - PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor - .getObject(); - if (msaPcd.getCName().equals(pcdData.getCName()) - && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) { - - maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey); - cursor.removeXml(); - break; - } - while (cursor.toNextSibling()) { - pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor.getObject(); + do { + PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor + .getObject(); if (msaPcd.getCName().equals(pcdData.getCName()) && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) { + maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey); cursor.removeXml(); break; } - } + } while (cursor.toNextSibling()); } cursor.dispose(); } @@ -697,14 +745,14 @@ public class FpdFileContents { String mn = libMi.getName(); String mg = libMi.getGuid(); String mv = libMi.getVersion(); - String pn = libMi.getPackage().getName(); - String pg = libMi.getPackage().getGuid(); - String pv = libMi.getPackage().getVersion(); + String pn = libMi.getPackageId().getName(); + String pg = libMi.getPackageId().getGuid(); + String pv = libMi.getPackageId().getVersion(); LibrariesDocument.Libraries.Instance instance = libs.addNewInstance(); XmlCursor cursor = instance.newCursor(); try{ String comment = "Pkg: " + pn + " Mod: " + mn - + " Path: " + GlobalData.getMsaFile(libMi).getPath().substring(System.getenv("WORKSPACE").length() + 1); + + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1); cursor.insertComment(comment); } catch (Exception e){ @@ -722,31 +770,169 @@ public class FpdFileContents { } public String getFvBinding(String moduleKey){ - ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey); - if (msa == null || msa.getModuleSaBuildOptions() == null) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey); + return getFvBinding (moduleSa); + } + + public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) { + if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) { return null; } - return msa.getModuleSaBuildOptions().getFvBinding(); + return moduleSa.getModuleSaBuildOptions().getFvBinding(); + } + + public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) { + if (moduleSa == null ) { + return; + } + if (fvBinding == null || fvBinding.length() == 0) { + if(moduleSa.getModuleSaBuildOptions() != null){ + moduleSa.getModuleSaBuildOptions().unsetFvBinding(); + } + } + else { + if(moduleSa.getModuleSaBuildOptions() == null){ + moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding); + return; + } + moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding); + } } public void setFvBinding(String moduleKey, String fvBinding){ - ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey); - if (msa == null ) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey); + setFvBinding (moduleSa, fvBinding); + } + + private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) { + if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) { + return -1; + } + + String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding(); + String[] fvNamesArray = fvNameList.split(" "); + int occursAt = -1; + for (int i = 0; i < fvNamesArray.length; ++i) { + if (fvNamesArray[i].equals(fvName)) { + occursAt = i; + break; + } + } + return occursAt; + } + + public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) { + if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) { return; } - if(msa.getModuleSaBuildOptions() == null){ - msa.addNewModuleSaBuildOptions().setFvBinding(fvBinding); + + String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding(); + String[] fvNamesArray = fvNameList.split(" "); + int occursAt = -1; + for (int i = 0; i < fvNamesArray.length; ++i) { + if (fvNamesArray[i].equals(fvName)) { + occursAt = i; + break; + } + } + // jump over where the input fvName occurs in the original Fv list. + if (occursAt != -1) { + String newFvNameList = " "; + for (int i = 0; i < fvNamesArray.length; ++i) { + if (i == occursAt) { + continue; + } + newFvNameList += fvNamesArray[i]; + } + setFvBinding (moduleSa, newFvNameList.trim()); + } + + } + + /** + * @param fvName The FV name that to be removed from FvBinding List. + */ + public void removeFvBindingAll (String fvName) { + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){ + removeElement(getfpdFrameworkModules()); + fpdFrameworkModules = null; + return; + } + + Iterator li = getfpdFrameworkModules().getModuleSAList().iterator(); + while (li.hasNext()) { + ModuleSADocument.ModuleSA moduleSa = li.next(); + removeFvBinding (moduleSa, fvName); + } + } + + public void appendFvBindingAll (String fvName) { + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){ + removeElement(getfpdFrameworkModules()); + fpdFrameworkModules = null; return; } - msa.getModuleSaBuildOptions().setFvBinding(fvBinding); + + Iterator li = getfpdFrameworkModules().getModuleSAList().iterator(); + while (li.hasNext()) { + ModuleSADocument.ModuleSA moduleSa = li.next(); + appendFvBinding (moduleSa, fvName); + } + } + + public void appendFvBindingFor (String oldFvName, String newFvName) { + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){ + removeElement(getfpdFrameworkModules()); + fpdFrameworkModules = null; + return; + } + + Iterator li = getfpdFrameworkModules().getModuleSAList().iterator(); + while (li.hasNext()) { + ModuleSADocument.ModuleSA moduleSa = li.next(); + String fvBinding = getFvBinding (moduleSa); + if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) { + appendFvBinding (moduleSa, newFvName); + } + } + } + + public void appendFvBinding (String moduleKey, String fvName) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey); + appendFvBinding (moduleSa, fvName); + } + + public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) { + if (moduleSa == null) { + return; + } + + if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) { + setFvBinding(moduleSa, fvName); + return; + } + + String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding(); + String newFvNameList = fvNameList + " " + fvName; + setFvBinding (moduleSa, newFvNameList.trim()); + } + + public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) { + Vector vSupArchs = new Vector(); + getPlatformDefsSupportedArchs(vSupArchs); + String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion(); + for (int i = 0; i < vSupArchs.size(); ++i) { + String moduleKey = moduleInfo + " " + vSupArchs.get(i); + appendFvBinding (moduleKey, fvName); + } } public String getFfsFileNameGuid(String moduleKey){ - ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey); - if (msa == null || msa.getModuleSaBuildOptions() == null) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey); + if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) { return null; } - return msa.getModuleSaBuildOptions().getFfsFileNameGuid(); + return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid(); } public void setFfsFileNameGuid(String moduleKey, String fileGuid){ @@ -792,6 +978,19 @@ public class FpdFileContents { msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey); } + public void setModuleSAForceDebug(int i, boolean dbgEnable) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(i); + moduleSa.setForceDebug(dbgEnable); + } + + public boolean getModuleSAForceDebug (int i) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(i); + if (moduleSa.getForceDebug() == true) { + return true; + } + return false; + } + public void getModuleSAOptions(String moduleKey, String[][] saa) { ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey); if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null @@ -813,7 +1012,9 @@ public class FpdFileContents { if (opt.getSupArchList() != null){ saa[i][4] = listToString(opt.getSupArchList()); - + } + else { + saa[i][4] = ""; } saa[i][5] = opt.getStringValue(); @@ -888,7 +1089,7 @@ public class FpdFileContents { moduleSa = genModuleSA(mi, arch); } - ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi); + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi); if (msa.getPcdCoded() == null) { return; } @@ -929,12 +1130,10 @@ public class FpdFileContents { private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) { - Map m = new HashMap(); PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null; for (int i = 0; i < depPkgs.length; ++i) { - m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i])); - SurfaceAreaQuery.setDoc(m); - XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(); + + XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]); if (xo == null) { continue; } @@ -958,12 +1157,12 @@ public class FpdFileContents { } private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) { - PackageIdentification pi = GlobalData.getPackageForModule(mi); + PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi); ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA(); XmlCursor cursor = msa.newCursor(); try{ - String comment = "Mod: " + mi.getName() + " Type: " + mi.getModuleType() + " Path: " - + GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1); + String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: " + + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1); cursor.insertComment(comment); } catch(Exception e){ @@ -998,41 +1197,19 @@ public class FpdFileContents { if (pcdConsumer == null) { pcdConsumer = new ArrayList(); } + // + // Using existing Pcd type, if this pcd already exists in other ModuleSA + // + if (pcdConsumer.size() > 0) { + + itemType = itemType (pcdConsumer.get(0)); + } String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()) + " " + itemType; pcdConsumer.add(listValue); dynPcdMap.put(cName + " " + tsGuid, pcdConsumer); - // - // Special dynamic type, if this pcd already exists in other ModuleSA - // - /* Comment out Item type checking temporarily. - if (itemType.equals("DYNAMIC")) { - - ListIterator li = pcdConsumer.listIterator(); - while(li.hasNext()) { - String value = li.next().toString(); - String[] valuePart= value.split(" "); - if (!valuePart[5].equals("DYNAMIC")) { - //ToDo error for same pcd, other type than dynamic - pcdConsumer.remove(listValue); - throw new PcdItemTypeConflictException(cName, value); - } - } - } - else { - ListIterator li = pcdConsumer.listIterator(); - while(li.hasNext()) { - String value = li.next().toString(); - String[] valuePart= value.split(" "); - if (valuePart[5].equals("DYNAMIC")) { - //ToDo error for same pcd, other type than non-dynamic - pcdConsumer.remove(listValue); - throw new PcdItemTypeConflictException(cName, value); - } - } - } - */ + PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData(); fpdPcd.setCName(cName); fpdPcd.setToken(token); @@ -1048,12 +1225,22 @@ public class FpdFileContents { fpdPcd.setValue("0"); } if (dataType.equals("BOOLEAN")){ - fpdPcd.setValue("false"); + fpdPcd.setValue("FALSE"); } if (dataType.equals("VOID*")) { fpdPcd.setValue(""); } } + // + // Using existing pcd value, if this pcd already exists in other moduleSa. + // + if (defaultPcdValue.get(cName + " " + tsGuid) == null) { + defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue()); + } + else { + fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid)); + } + if (dataType.equals("UINT8")){ fpdPcd.setMaxDatumSize(1); } @@ -1085,44 +1272,7 @@ public class FpdFileContents { addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal); } } - else { - /* - if (defaultVal != null){ - fpdPcd.setValue(defaultVal); - } - else { - if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) { - fpdPcd.setValue("0"); - } - if (dataType.equals("BOOLEAN")){ - fpdPcd.setValue("false"); - } - if (dataType.equals("VOID*")) { - fpdPcd.setValue(""); - } - } - - if (dataType.equals("UINT8")){ - fpdPcd.setMaxDatumSize(1); - } - if (dataType.equals("UINT16")) { - fpdPcd.setMaxDatumSize(2); - } - if (dataType.equals("UINT32")) { - fpdPcd.setMaxDatumSize(4); - } - if (dataType.equals("UINT64")){ - fpdPcd.setMaxDatumSize(8); - } - if (dataType.equals("BOOLEAN")){ - fpdPcd.setMaxDatumSize(1); - } - if (dataType.equals("VOID*")) { - int maxSize = setMaxSizeForPointer(fpdPcd.getValue()); - fpdPcd.setMaxDatumSize(maxSize); - } - */ - } + } public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{ @@ -1176,7 +1326,7 @@ public class FpdFileContents { if (value > 0xFF) { // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+ -// "it is byte array in fact. But the element of %s exceed the byte range", +// "it must be a byte array. But the element of %s exceed the byte range", throw new PcdValueMalFormed (datum); } } @@ -1529,6 +1679,153 @@ public class FpdFileContents { return fpdBuildOpts; } + public void genBuildOptionsUserExtensions(String fvName, 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")); + XmlCursor cursor = userExts.newCursor(); + cursor.toEndToken(); + + cursor.beginElement(elementFvName); + cursor.insertChars(fvName); + cursor.toNextToken(); + + cursor.beginElement(elementInfFileName); + cursor.insertChars(fvName + ".inf"); + cursor.toNextToken(); + + cursor.beginElement(elementIncludeModules); + for (int i = 0; i < includeModules.size(); ++i) { + cursor.beginElement(elementModule); + cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]); + cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]); + cursor.toEndToken(); + cursor.toNextToken(); + } + cursor.dispose(); + } + + public int getUserExtsIncModCount (String fvName) { + 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")) { + continue; + } + XmlCursor cursor = ues.newCursor(); + cursor.toFirstChild(); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toNextSibling(elementIncludeModules); + if (cursor.toFirstChild()) { + int i = 1; + for (i = 1; cursor.toNextSibling(); ++i); + cursor.dispose(); + return i; + } + cursor.dispose(); + return 0; + } + cursor.dispose(); + } + return -1; + } + + public void getUserExtsIncMods(String fvName, String[][] saa) { + if (getfpdBuildOpts().getUserExtensionsList() == null) { + return; + } + + XmlCursor cursor = getfpdBuildOpts().newCursor(); + QName elementUserExts = new QName (xmlNs, "UserExtensions"); + QName attribUserId = new QName ("UserID"); + QName elementFvName = new QName (xmlNs, "FvName"); + QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); + QName attribModuleGuid = new QName("ModuleGuid"); + QName attribBaseName = new QName("BaseName"); + + if (cursor.toChild(elementUserExts)) { + do { + cursor.push(); + if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + cursor.toChild(elementFvName); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toNextSibling(elementIncludeModules); + if (cursor.toFirstChild()) { + int i = 0; + do { + saa[i][0] = cursor.getAttributeText(attribModuleGuid); + saa[i][1] = cursor.getAttributeText(attribBaseName); + ++i; + }while (cursor.toNextSibling()); + } + break; + } + } + cursor.pop(); + }while (cursor.toNextSibling(elementUserExts)); + } + cursor.dispose(); + + } + + public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) { + if (getfpdBuildOpts().getUserExtensionsList() == null) { + return; + } + ListIterator li = getfpdBuildOpts().getUserExtensionsList().listIterator(); + while (li.hasNext()) { + UserExtensionsDocument.UserExtensions ues = li.next(); + if (!ues.getUserID().equals("IMAGES")) { + continue; + } + XmlCursor cursor = ues.newCursor(); + cursor.toFirstChild(); + String elementName = cursor.getTextValue(); + if (elementName.equals(oldFvName)) { + cursor.setTextValue(newFvName); + } + cursor.dispose(); + } + + } + + public void removeBuildOptionsUserExtensions (String fvName) { + if (getfpdBuildOpts().getUserExtensionsList() == null) { + return; + } + + ListIterator li = getfpdBuildOpts().getUserExtensionsList().listIterator(); + while (li.hasNext()) { + UserExtensionsDocument.UserExtensions ues = li.next(); + if (!ues.getUserID().equals("IMAGES")) { + continue; + } + XmlCursor cursor = ues.newCursor(); + cursor.toFirstChild(); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toParent(); + cursor.removeXml(); + cursor.dispose(); + return; + } + cursor.dispose(); + } + + } + + public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) { UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks(); if (udats == null) { @@ -2317,6 +2614,64 @@ public class FpdFileContents { } } + public void getFvImagesFvImageFvImageNames (Vector vImageNames) { + FvImagesDocument.FvImages fis = getfpdFlash().getFvImages(); + if (fis == null || fis.getFvImageList() == null) { + return; + } + + ListIterator li = fis.getFvImageList().listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage fi = li.next(); + if (fi.getType().toString().equals("ImageName")) { + vImageNames.addAll(fi.getFvImageNamesList()); + return; + } + } + } + + public void addFvImageFvImageNames (String[] fvNames) { + FvImagesDocument.FvImages fis = getfpdFlash().getFvImages(); + if (fis == null || fis.getFvImageList() == null) { + genFvImagesFvImage (fvNames, "ImageName", null); + return; + } + + ListIterator li = fis.getFvImageList().listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage fi = li.next(); + if (fi.getType().toString().equals("ImageName")) { + addFvImageNamesInFvImage (fi, fvNames); + return; + } + } + genFvImagesFvImage (fvNames, "ImageName", null); + } + + public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) { + + for (int i = 0; i < fvNames.length; ++i) { + fi.addFvImageNames(fvNames[i]); + } + } + + public void addFvImageNamesInFvImage (int i, String[] fvNames) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + addFvImageNamesInFvImage(fi, fvNames); + } + cursor.dispose(); + } + public void genFvImagesFvImage(String[] names, String types, Map options) { FvImagesDocument.FvImages fis = null; @@ -2376,6 +2731,87 @@ public class FpdFileContents { cursor.dispose(); } + /** + * @param oldFvName + * @param newFvName The New FV Name. If null, remove the old FvImageNames entry. + */ + public void updateFvImageNameAll (String oldFvName, String newFvName) { + if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) { + return; + } + ListIterator li = getfpdFlash().getFvImages().getFvImageList().listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage fi = li.next(); + updateFvImageNamesInFvImage (fi, oldFvName, newFvName); + if (fi.getFvImageNamesList().size() == 0) { + li.remove(); + } + } + } + + public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + updateFvImageNamesInFvImage (fi, oldFvName, newFvName); + } + cursor.dispose(); + } + /** + * @param fi + * @param oldFvName The FV Name to be replaced. + * @param newFvName The New FV Name. If null, remove the old FvImageNames entry. + */ + public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) { + QName qFvImageNames = new QName(xmlNs, "FvImageNames"); + XmlCursor cursor = fi.newCursor(); + + if (cursor.toChild(qFvImageNames)) { + do { + String xmlValue = cursor.getTextValue(); + if (xmlValue.equals(oldFvName)){ + if (newFvName != null) { + cursor.setTextValue(newFvName); + } + else { + cursor.removeXml(); + } + } + }while (cursor.toNextSibling(qFvImageNames)); + } + + cursor.dispose(); + } + + /**update the Type attribute of ith FvImage with new type. + * @param i + * @param type + */ + public void updateFvImagesFvImageType (int i, String type) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + fi.setType(FvImageTypes.Enum.forString(type)); + } + cursor.dispose(); + } + public void updateFvImagesFvImage(int i, String[] names, String types, Map options){ XmlObject o = getfpdFlash().getFvImages(); @@ -2416,18 +2852,50 @@ public class FpdFileContents { cursor.dispose(); } - public int getFvImagesFvImageCount() { + public int getFvImagesFvImageCount(String type) { if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) { return 0; } - return getfpdFlash().getFvImages().getFvImageList().size(); + List l = getfpdFlash().getFvImages().getFvImageList(); + ListIterator li = l.listIterator(); + int i = 0; + while(li.hasNext()) { + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next(); + if (!fi.getType().toString().equals(type) && !type.equals("ALL")) { + continue; + } + + ++i; + } + + return i; } - /**Only Get Fv image setting - name and type. + public Vector getFvImagesFvImageWithName (String fvName, String type) { + Vector vFvImage = new Vector(); + if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) { + return vFvImage; + } + List l = getfpdFlash().getFvImages().getFvImageList(); + 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)) { + vFvImage.add(fi); + } + } + + return vFvImage; + } + /** * @param saa + * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components. */ - public void getFvImagesFvImages(String[][] saa) { + public void getFvImagesFvImages(String[][] saa, String type) { if (getfpdFlash().getFvImages() == null) { return; @@ -2440,6 +2908,9 @@ public class FpdFileContents { int i = 0; while(li.hasNext()) { FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next(); + if (!fi.getType().toString().equals(type) && !type.equals("ALL")) { + continue; + } // // get FvImageNames array, space separated // @@ -2458,6 +2929,224 @@ public class FpdFileContents { } } + public void removeFvImageNameValue (int i, String attributeName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + removeFvImageNameValue (fi, attributeName); + } + cursor.dispose(); + } + /**Remove from fi the attribute pair with attributeName in FvImageOptions. + * @param fi + * @param attributeName + */ + public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) { + if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) { + ListIterator li = fi.getFvImageOptions().getNameValueList().listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next(); + if (nv.getName().equals(attributeName)) { + li.remove(); + } + } + } + } + + public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) { + Vector vFvImage = getFvImagesFvImageWithName(fvName, type); + for (int i = 0; i < vFvImage.size(); ++i) { + FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i); + removeFvImageNameValue (fi, optName); + } + } + + /**Add name-value pair to FvImage element with type. + * @param fvName FV name to add name-value pair. + * @param type FvImage attribute. + * @param name + * @param value + */ + public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) { + 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; + } + fvImageExists = true; + setFvImagesFvImageNameValue (fi, name, value, null); + } + + if (!fvImageExists) { + HashMap map = new HashMap(); + map.put(name, value); + genFvImagesFvImage(new String[]{fvName}, type, map); + } + } + + /**Add to all FvImage elements with type, the name-value pair. + * @param type + * @param name + * @param value + */ + public void setTypedFvImageNameValue (String type, String name, String value) { + 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; + } + setFvImagesFvImageNameValue (fi, name, value, null); + } + + } + + public void setFvImagesFvImageNameValue (int i, String name, String value) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + setFvImagesFvImageNameValue (fi, name, value, null); + } + cursor.dispose(); + } + + /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before. + * @param fi + * @param name + * @param value + * @param newName + */ + public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) { + if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue(); + nv.setName(name); + nv.setValue(value); + if (newName != null) { + nv.setName(newName); + } + return; + } + + XmlCursor cursor = fi.getFvImageOptions().newCursor(); + if (cursor.toFirstChild()) { + do { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject(); + if (nv.getName().equals(name)) { + nv.setValue(value); + if (newName != null) { + nv.setName(newName); + } + cursor.dispose(); + return; + } + }while (cursor.toNextSibling()); + } + + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue(); + nv.setName(name); + nv.setValue(value); + if (newName != null) { + nv.setName(newName); + } + cursor.dispose(); + } + + public void getFvImagesFvImageOptions (String fvName, Map m) { + Vector vFvImage = getFvImagesFvImageWithName (fvName, "Options"); + for (int i = 0; i < vFvImage.size(); ++i) { + FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i); + if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) { + continue; + } + + ListIterator li = fi.getFvImageOptions() + .getNameValueList() + .listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next(); + m.put(nv.getName(), nv.getValue()); + } + } + } + + public int getFvImagePosInFvImages (String fvNameList, String type) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return -1; + } + + int pos = -1; + String[] fvNameArray = fvNameList.trim().split(" "); + Vector vFvNames = new Vector(); + + + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + do { + pos++; + vFvNames.removeAllElements(); + for (int i = 0; i < fvNameArray.length; ++i) { + vFvNames.add(fvNameArray[i]); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + if (!fi.getType().toString().equals(type)) { + continue; + } + if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) { + continue; + } + ListIterator li = fi.getFvImageNamesList().listIterator(); + while (li.hasNext()) { + String name = li.next(); + vFvNames.remove(name); + } + if (vFvNames.size() == 0) { + cursor.dispose(); + return pos; + } + + }while (cursor.toNextSibling(qFvImage)); + + } + cursor.dispose(); + return -1; + } /**Get FvImage Options for FvImage i * @param i the ith FvImage */ @@ -2474,6 +3163,7 @@ public class FpdFileContents { } FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){ + cursor.dispose(); return; } ListIterator li = fi.getFvImageOptions().getNameValueList().listIterator(); @@ -2482,6 +3172,7 @@ public class FpdFileContents { m.put(nv.getName(), nv.getValue()); } } + cursor.dispose(); } /** @@ -2637,8 +3328,8 @@ class PcdItemTypeConflictException extends Exception { private String details = null; PcdItemTypeConflictException(String pcdName, String info){ - ModuleIdentification mi = GlobalData.getModuleId(info); - details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackage().getName(); + ModuleIdentification mi = WorkspaceProfile.getModuleId(info); + details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName(); } public String getMessage() {