From 1dac04abec3ac6b44cedd601126602d44f838172 Mon Sep 17 00:00:00 2001 From: jlin16 Date: Tue, 8 Aug 2006 08:55:34 +0000 Subject: [PATCH] auto adjust pcd settings when display existing ModuleSA settings. if new PCD added/deleted in MSA file, in platform FrameworkModules, the change of PCD will reflect in the display after you click settings. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1214 6f19259b-4bc3-4df7-8a09-765794883524 --- .../platform/ui/FpdFileContents.java | 185 +++++++++++++++--- .../platform/ui/FpdFrameworkModules.java | 10 + .../platform/ui/FpdModuleSA.java | 9 +- .../platform/ui/global/GlobalData.java | 18 +- .../platform/ui/global/SurfaceAreaQuery.java | 65 +----- 5 files changed, 193 insertions(+), 94 deletions(-) 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 8296b21eb4..3d3e8f3098 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 @@ -102,13 +102,13 @@ public class FpdFileContents { } ListIterator li = l.listIterator(); while (li.hasNext()) { - ModuleSADocument.ModuleSA msa = li.next(); - if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) { + ModuleSADocument.ModuleSA moduleSa = li.next(); + if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) { continue; } - String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() + - " " + msa.getPackageGuid() + " " + msa.getPackageVersion() + " " + listToString(msa.getSupArchList()); - List lp = msa.getPcdBuildDefinition().getPcdDataList(); + String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()); + List lp = moduleSa.getPcdBuildDefinition().getPcdDataList(); ListIterator lpi = lp.listIterator(); while (lpi.hasNext()) { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next(); @@ -230,32 +230,32 @@ public class FpdFileContents { } ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); while(li.hasNext()) { - ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next(); - if (msa.getModuleGuid().equalsIgnoreCase(s[0]) && msa.getPackageGuid().equalsIgnoreCase(s[2])) { - if (msa.getModuleVersion() != null) { - if (!msa.getModuleVersion().equals(s[1])) { + ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); + if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) { + if (moduleSa.getModuleVersion() != null) { + if (!moduleSa.getModuleVersion().equals(s[1])) { continue; } } - if (msa.getPackageVersion() != null) { - if (!msa.getPackageVersion().equals(s[3])) { + if (moduleSa.getPackageVersion() != null) { + if (!moduleSa.getPackageVersion().equals(s[3])) { continue; } } //ToDo add arch check for s[4] - if (msa.getSupArchList() != null) { - if (!listToString(msa.getSupArchList()).equals(s[4])) { + if (moduleSa.getSupArchList() != null) { + if (!listToString(moduleSa.getSupArchList()).equals(s[4])) { continue; } } - return msa; + return moduleSa; } } return null; } private ModuleSADocument.ModuleSA getModuleSA(int i) { - ModuleSADocument.ModuleSA msa = null; + ModuleSADocument.ModuleSA moduleSa = null; if (fpdRoot.getFrameworkModules() == null) { return null; } @@ -264,10 +264,10 @@ public class FpdFileContents { for (int j = 0; j < i; ++j) { cursor.toNextSibling(); } - msa = (ModuleSADocument.ModuleSA)cursor.getObject(); + moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject(); } cursor.dispose(); - return msa; + return moduleSa; } public void removeModuleSA(int i) { @@ -311,6 +311,103 @@ public class FpdFileContents { cursor.dispose(); } + public boolean adjustPcd (int seqModuleSa) 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 mv = moduleSa.getModuleVersion(); + String pg = moduleSa.getPackageGuid(); + String pv = moduleSa.getPackageVersion(); + String arch = listToString(moduleSa.getSupArchList()); + // + // delete pcd in ModuleSA but not in MSA files any longer. + // + String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch; + int libCount = getLibraryInstancesCount(moduleKey); + String[][] saaLib = new String[libCount][5]; + getLibraryInstances(moduleKey, saaLib); + ModuleIdentification mi = GlobalData.getModuleId(moduleKey); + Vector vMi = new Vector(); + vMi.add(mi); + 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)) { + continue nextPcd; + } + } + removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]); + dataModified = true; + } + } + catch (Exception e) { + + } + // + // add new Pcd from MSA file to ModuleSA. + // + try { + + for (int i = 0; i < vMi.size(); ++i) { + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) GlobalData + .getModuleXmlObject(vMi + .get(i)); + if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) { + continue; + } + ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator(); + msaPcdIter:while (li.hasNext()) { + PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next(); + ArrayList al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName()); + if (al != null) { + for (int j = 0; j < al.size(); ++j) { + if (al.get(j).contains(moduleKey)) { + continue msaPcdIter; + } + } + } + + Map m = new HashMap(); + m.put("ModuleSurfaceArea", msa); + SurfaceAreaQuery.setDoc(m); + PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null); + 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()); + } + // + // 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); + dataModified = true; + } + + } + } + catch (Exception e){ + throw e; + } + + return dataModified; + } + private void maintainDynPcdMap(String pcdKey, String moduleInfo) { ArrayList al = dynPcdMap.get(pcdKey); @@ -340,7 +437,7 @@ public class FpdFileContents { // // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch" // - public int getPcdDataCount(int i){ + public int getPcdDataCount (int i){ ModuleSADocument.ModuleSA msa = getModuleSA(i); if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){ @@ -350,7 +447,7 @@ public class FpdFileContents { } - public void getPcdData(int i, String[][] saa) { + public void getPcdData (int i, String[][] saa) { ModuleSADocument.ModuleSA msa = getModuleSA(i); if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){ @@ -370,13 +467,46 @@ public class FpdFileContents { } } - public void updatePcdData(String key, String cName, String tsGuid, String itemType, String maxSize, String value){ - ModuleSADocument.ModuleSA msa = getModuleSA(key); - if (msa == null || msa.getPcdBuildDefinition() == null){ + public void removePcdData (int seqModuleSa, String cName, String tsGuid) { + ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa); + if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){ return; } - XmlCursor cursor = msa.getPcdBuildDefinition().newCursor(); + String mg = moduleSa.getModuleGuid(); + String mv = moduleSa.getModuleVersion(); + String pg = moduleSa.getPackageGuid(); + String pv = moduleSa.getPackageVersion(); + String arch = listToString(moduleSa.getSupArchList()); + String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch; + + XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor(); + if (cursor.toFirstChild()){ + + do { + 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) { + cursor.toParent(); + } + cursor.removeXml(); + break; + } + } + while(cursor.toNextSibling()); + + } + cursor.dispose(); + } + + public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){ + ModuleSADocument.ModuleSA moduleSa = getModuleSA(key); + if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){ + return; + } + + XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor(); if (cursor.toFirstChild()){ do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject(); @@ -400,7 +530,7 @@ public class FpdFileContents { * @param sa Results: HelpText, Original item type. * @return */ - public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String[] sa) throws Exception{ + public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{ try { ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi); @@ -422,6 +552,9 @@ public class FpdFileContents { if (!msaPcd.getCName().equals(cName)) { continue; } + if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) { + continue; + } PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs); if (spdPcd == null) { // @@ -571,7 +704,7 @@ public class FpdFileContents { XmlCursor cursor = instance.newCursor(); try{ String comment = "Pkg: " + pn + " Mod: " + mn - + " Path: " + GlobalData.getMsaFile(libMi).getPath(); + + " Path: " + GlobalData.getMsaFile(libMi).getPath().substring(System.getenv("WORKSPACE").length() + 1); cursor.insertComment(comment); } catch (Exception e){ @@ -830,7 +963,7 @@ public class FpdFileContents { XmlCursor cursor = msa.newCursor(); try{ String comment = "Mod: " + mi.getName() + " Type: " + mi.getModuleType() + " Path: " - + GlobalData.getMsaFile(mi).getPath(); + + GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1); cursor.insertComment(comment); } catch(Exception e){ diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java index d260bf5a7a..56375e1b38 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java @@ -336,6 +336,15 @@ public class FpdFrameworkModules extends IInternalFrame { TableSorter sorter = (TableSorter)jTableFpdModules.getModel(); selectedRow = sorter.modelIndex(selectedRow); + try { + if (ffc.adjustPcd(selectedRow)) { + docConsole.setSaved(false); + } + } + catch (Exception exp) { + JOptionPane.showMessageDialog(frame, exp.getMessage()); + return; + } if (settingDlg == null) { settingDlg = new FpdModuleSA(ffc); @@ -355,6 +364,7 @@ public class FpdFrameworkModules extends IInternalFrame { } return jButtonSettings; } + /** * This method initializes jButton2 diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java index d2ef9997b2..5ebcb20d39 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java @@ -551,8 +551,9 @@ public class FpdModuleSA extends JDialog implements ActionListener { else{ int selectedRow = lsm.getMinSelectionIndex(); String cName = jTablePcd.getValueAt(selectedRow, 0)+""; + String tsGuid = jTablePcd.getValueAt(selectedRow, 1)+""; String[] pcdInfo = {"", ""}; - getPcdInfo(cName, pcdInfo); + getPcdInfo(cName, tsGuid, pcdInfo); jTextAreaPcdHelp.setText(pcdInfo[0]); initComboBox(pcdInfo[1]); jComboBoxItemType.setSelectedItem(pcdInfo[1]); @@ -632,17 +633,17 @@ public class FpdModuleSA extends JDialog implements ActionListener { } } - private void getPcdInfo(String cName, String[] sa) { + private void getPcdInfo(String cName, String tsGuid, String[] sa) { String[][] saa = new String[ffc.getLibraryInstancesCount(moduleKey)][5]; ffc.getLibraryInstances(moduleKey, saa); try{ - if (ffc.getPcdBuildDataInfo(GlobalData.getModuleId(moduleKey), cName, sa)) { + if (ffc.getPcdBuildDataInfo(GlobalData.getModuleId(moduleKey), cName, tsGuid, sa)) { return; } for (int j = 0; j < saa.length; ++j) { if (ffc.getPcdBuildDataInfo(GlobalData.getModuleId(saa[j][1] + " " + saa[j][2] + " " + saa[j][3] + " " + saa[j][4]), - cName, sa)) { + cName, tsGuid, sa)) { return; } } diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/GlobalData.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/GlobalData.java index 44f6f36b34..457208b4e3 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/GlobalData.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/GlobalData.java @@ -20,6 +20,7 @@ import org.apache.xmlbeans.XmlObject; import org.tianocore.DbPathAndFilename; import org.tianocore.FrameworkDatabaseDocument; import org.tianocore.ModuleSurfaceAreaDocument; +import org.tianocore.PcdCodedDocument; import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea; import org.tianocore.frameworkwizard.platform.ui.id.FpdModuleIdentification; import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification; @@ -464,7 +465,7 @@ public class GlobalData { return null; } - public static Vector getModuleSupArchs(ModuleIdentification mi) throws Exception{ + public static Vector getModuleSupArchs(ModuleIdentification mi) throws Exception { Vector vArchs = null; ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)getModuleXmlObject(mi); if (msa.getModuleDefinitions() == null || msa.getModuleDefinitions().getSupportedArchitectures() == null) { @@ -481,6 +482,21 @@ public class GlobalData { return vArchs; } + public static boolean pcdInMsa (String cName, String tsGuid, ModuleIdentification mi) throws Exception { + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)getModuleXmlObject(mi); + if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) { + return false; + } + ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator(); + while (li.hasNext()) { + PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next(); + if (msaPcd.getCName().equals(cName) && msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) { + return true; + } + } + return false; + } + } final class KeyComparator implements Comparator { diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java index 1f6ea98f51..a3b08065b3 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java @@ -893,71 +893,10 @@ public class SurfaceAreaQuery { return null; } - /** - * Get the PcdToken array from module's surface area document. The array - * should contains following data: - *

- * ------------------------------------------------------------------- - *

- *

- * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText - *

- *

- * ------------------------------------------------------------------- - *

- *

- * Note: Until new schema applying, now we can only get CName, ItemType, - *

- * - * @return 2-array table contains all information of PCD token retrieved - * from MSA. - */ - public static Object[][] etModulePCDTokenArray() { - return null; - // int index; - // Object[][] result; - // PCDs.PcdData[] pcds; - // String[] xPath = new String[] { "/PcdData" }; - // XmlObject[] returns = get("PCDs", xPath); - // - // if ((returns == null) || (returns.length == 0)) { - // return null; - // } - // - // pcds = (PCDs.PcdData[]) returns; - // result = new Object[pcds.length][6]; - // for (index = 0; index < pcds.length; index++) { - // // - // // Get CName - // // - // result[index][0] = pcds[index].getCName(); - // // - // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE, - // // DYNAMIC, DYNAMIC_EX - // // - // if (pcds[index].getItemType() != null) { - // result[index][1] = pcds[index].getItemType().toString(); - // } else { - // result[index][1] = null; - // } - // - // // - // // BUGBUG: following field can *not* be got from current MSA until - // // schema changed. - // // - // // result [index][2] = pcds[index].getTokenSpaceName(); - // result[index][2] = null; - // result[index][3] = pcds[index].getDefaultValue(); - // // result [index][4] = pcds[index].getUsage (); - // result[index][4] = null; - // // result [index][5] = pcds[index].getHelpText (); - // result[index][5] = null; - // } - // return result; - } + /** - * Retrieve MAS header + * Retrieve MSA header * * @return * @return -- 2.39.2