]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Refresh applicable library instances after one illegal library instance is removed.
authorjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Feb 2007 10:11:03 +0000 (10:11 +0000)
committerjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Feb 2007 10:11:03 +0000 (10:11 +0000)
2.Remove library instances that is only consumed by one library instance when deleting this library instance from a module in platform.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2350 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java

index adc6d265a107017917e05d62cca8548487e5386c..4bca7fe22d047d22937b183565d3129d466028f9 100644 (file)
@@ -58,6 +58,7 @@ import org.tianocore.PlatformHeaderDocument;
 import org.tianocore.SkuInfoDocument;\r
 import org.tianocore.UserDefinedAntTasksDocument;\r
 import org.tianocore.UserExtensionsDocument;\r
+import org.tianocore.LibrariesDocument.Libraries.Instance;\r
 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;\r
 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
@@ -384,7 +385,7 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
-    public boolean adjustPcd (int seqModuleSa, Vector<String> vExceptions) throws Exception {\r
+    public boolean adjustPcd (String seqModuleSa, Vector<String> vExceptions) throws Exception {\r
         boolean dataModified = false;\r
         ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
         int pcdCount = getPcdDataCount(seqModuleSa);\r
@@ -523,8 +524,8 @@ public class FpdFileContents {
     //\r
     // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
     //\r
-    public int getPcdDataCount (int i){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
+    public int getPcdDataCount (String key){\r
+        ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
         \r
         if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
             return 0;\r
@@ -533,8 +534,8 @@ public class FpdFileContents {
         \r
     }\r
     \r
-    public void getPcdData (int i, String[][] saa) {\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
+    public void getPcdData (String key, String[][] saa) {\r
+        ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
         \r
         if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
             return;\r
@@ -553,8 +554,8 @@ public class FpdFileContents {
         }\r
     }\r
     \r
-    public void removePcdData (int seqModuleSa, String cName, String tsGuid) {\r
-        ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
+    public void removePcdData (String key, String cName, String tsGuid) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);\r
         if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){\r
             return;\r
         }\r
@@ -573,7 +574,7 @@ public class FpdFileContents {
                 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
                 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
                     maintainDynPcdMap(cName + " " + tsGuid, moduleKey);\r
-                    if (getPcdDataCount(seqModuleSa) == 1) {\r
+                    if (getPcdDataCount(key) == 1) {\r
                         cursor.toParent();\r
                     }\r
                     cursor.removeXml();\r
@@ -809,17 +810,21 @@ public class FpdFileContents {
         return false;\r
     }\r
     \r
-    public void removeLibraryInstance(String key, int i) {\r
+    public void removeLibraryInstance(String key, String instanceKey) {\r
         ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
         if (msa == null || msa.getLibraries() == null){\r
             return ;\r
         }\r
         \r
+        String[] instanceInfo = instanceKey.split(" ");\r
         XmlCursor cursor = msa.getLibraries().newCursor();\r
         if (cursor.toFirstChild()) {\r
-            for (int j = 0; j < i; ++j) {\r
-                cursor.toNextSibling();\r
+            do {\r
+                Instance libIns = (Instance)cursor.getObject();\r
+                if (libIns.getModuleGuid().equalsIgnoreCase(instanceInfo[0]) && libIns.getPackageGuid().equalsIgnoreCase(instanceInfo[2])) {\r
+                    break;\r
             }\r
+            }while (cursor.toNextSibling());\r
             cursor.push();\r
             while (cursor.hasPrevToken()) {\r
                 cursor.toPrevToken();\r
index 7e3faa969b62fce46390816b5c7d12f3c8fde2c9..e219ee32911c20f97d320e68f85ffa76e4c0e63c 100644 (file)
@@ -928,9 +928,17 @@ public class FpdFrameworkModules extends IInternalFrame {
 \r
     private boolean pcdSync(Vector<String> v) {\r
         boolean synced = false;\r
+        String[] sa = new String[5];\r
         for (int i = 0; i < jTableFpdModules.getRowCount(); ++i) {\r
             try {\r
-                if (ffc.adjustPcd(i, v)) {\r
+                ffc.getFrameworkModuleInfo(i, sa);\r
+                String mg = sa[ffcModGuid];\r
+                String mv = sa[ffcModVer];\r
+                String pg = sa[ffcPkgGuid];\r
+                String pv = sa[ffcPkgVer];\r
+                String arch = sa[ffcModArch];\r
+                String key = mg + " " + mv + " " + pg + " " + pv + " " + arch;\r
+                if (ffc.adjustPcd(key, v)) {\r
                     synced = true;\r
                 }\r
             }\r
index 102dd3dc4669da5d056bf252d5da0f1f49767b89..b97e0d77e64ac4445d1d86a04fb924b5bd44e84c 100644 (file)
@@ -96,7 +96,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     private FpdFileContents ffc = null;\r
     private String moduleKey = null;\r
     private ModuleIdentification moduleId = null;\r
-    private int moduleSaNum = -1;\r
     private HashMap<LibraryClassDescriptor, ArrayList<String>> classInstanceMap = null;\r
     //\r
     // map of <{libName, supArch, supMod}, list of Module information>\r
@@ -154,13 +153,12 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     \r
     public void setKey(String k, int i, OpeningPlatformType dc){\r
         this.moduleKey = k;\r
-        moduleSaNum = i;\r
         this.docConsole = dc;\r
         classInstanceMap = null;\r
         classProduced = null;\r
         classConsumed = null;\r
         jTabbedPane.setSelectedIndex(0);\r
-        initPcdBuildDefinition(i);\r
+        initPcdBuildDefinition(moduleKey);\r
         moduleId = WorkspaceProfile.getModuleId(moduleKey);\r
         if (moduleId == null) {\r
             return;\r
@@ -178,7 +176,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
       init will be called each time FpdModuleSA object is to be shown.\r
       @param key Module information.\r
      **/\r
-    public void initPcdBuildDefinition(int i) {\r
+    public void initPcdBuildDefinition(String key) {\r
         //\r
         // display pcd for key.\r
         //\r
@@ -187,10 +185,10 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         jComboBoxItemType.setSelectedIndex(-1);\r
         jTextFieldMaxDatumSize.setText("");\r
         jTextFieldPcdDefault.setText("");\r
-        int pcdCount = ffc.getPcdDataCount(i);\r
+        int pcdCount = ffc.getPcdDataCount(key);\r
         if (pcdCount != 0) {\r
             String[][] saa = new String[pcdCount][7];\r
-            ffc.getPcdData(i, saa);\r
+            ffc.getPcdData(key, saa);\r
             for (int j = 0; j < saa.length; ++j) {\r
                 model.addRow(saa[j]);\r
             }\r
@@ -236,6 +234,9 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
         while (iter.hasNext()) {\r
             LibraryClassDescriptor lcd = iter.next();\r
+            if (this.classConsumed.get(lcd) == null || this.classConsumed.get(lcd).size() == 0) {\r
+                continue;\r
+            }\r
             if (isBoundedClass(lcd, errorMsg)) {\r
                 continue;\r
             }\r
@@ -575,12 +576,41 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         return null;\r
     }\r
     \r
+    private ArrayList<String> getProducedBy (String className) {\r
+        Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();\r
+        while (lcdi.hasNext()) {\r
+            LibraryClassDescriptor lcd = lcdi.next();\r
+            if ((lcd.className != null) && lcd.className.equals(className)) {\r
+                return this.classProduced.get(lcd);\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+    //\r
+    // Get class name list related with instanceKey from HashMap m<LibraryClass, ArrayList<instanceKey>>.\r
+    //\r
+    private ArrayList<String> getLibraryClassList (String instanceKey, HashMap<LibraryClassDescriptor, ArrayList<String>> m) {\r
+        ArrayList<String> libraryClass = new ArrayList<String>();\r
+        Iterator<LibraryClassDescriptor> lcdi = m.keySet().iterator();\r
+        while (lcdi.hasNext()) {\r
+            LibraryClassDescriptor lcd = lcdi.next();\r
+            if ((m.get(lcd) != null) && m.get(lcd).contains(instanceKey)) {\r
+                libraryClass.add(lcd.className);\r
+            }\r
+        }\r
+        return libraryClass;\r
+    }\r
+    \r
     private void removeInstance(String key) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(key); \r
         //\r
         // remove pcd information of instance from current ModuleSA\r
+        // Note that Pcd data SHOULD be removed prior to library instance\r
+        // because Multi-Sourced PCD could not be removed, if we remove library instance first,\r
+        // it will impact the judgement of whether a PCD entry is Multi-Sourced.\r
         //\r
         ffc.removePcdData(moduleKey, mi);\r
+        ffc.removeLibraryInstance(moduleKey, key);\r
         //\r
         // remove class produced by this instance and add back these produced class to be bound.\r
         //\r
@@ -600,7 +630,25 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 continue;\r
             }\r
             al.remove(key);\r
-            \r
+            if (al.size() == 0) {\r
+                ArrayList<String> from = getProducedBy (clsConsumed[i]);\r
+                if (from == null) {\r
+                    continue;\r
+                }\r
+                boolean noUse = true;\r
+                for (int j = 0; j < from.size(); ++j) {\r
+                    ArrayList<String> libClasses = getLibraryClassList(from.get(j), classProduced);\r
+                    for (int k = 0; k < libClasses.size(); ++k) {\r
+                        if (getConsumedBy (libClasses.get(k)) != null && getConsumedBy (libClasses.get(k)).size() > 0) {\r
+                            noUse = false;\r
+                        }\r
+                    }\r
+                    if (noUse) {\r
+                        removeInstance(from.get(j));\r
+                    }\r
+                    noUse = true;\r
+                }\r
+            }\r
         }\r
         \r
     }\r
@@ -738,7 +786,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             jPanelPcd.add(getJPanelPcdSouth(), java.awt.BorderLayout.SOUTH);\r
             jPanelPcd.addComponentListener(new java.awt.event.ComponentAdapter() {\r
                 public void componentShown(java.awt.event.ComponentEvent e) {\r
-                    initPcdBuildDefinition(moduleSaNum);\r
+                    initPcdBuildDefinition(moduleKey);\r
                 }\r
             });\r
             \r
@@ -1124,9 +1172,14 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         String cls = libClassTableModel.getValueAt(selectedRow2, 0).toString();\r
                         String arch = libClassTableModel.getValueAt(selectedRow2, 1).toString();\r
                         String modType = libClassTableModel.getValueAt(selectedRow2, 2).toString();\r
-                        ArrayList<String> al = classInstanceMap.get(new LibraryClassDescriptor(cls, arch, modType));\r
+                        LibraryClassDescriptor lcd = new LibraryClassDescriptor(cls, arch, modType);\r
+                        ArrayList<String> al = classInstanceMap.get(lcd);\r
                         if (al == null) {\r
-                            return;\r
+                            al = getInstancesForClass(lcd, null);\r
+                            if (al.size() != 0) {\r
+                                classInstanceMap.put(lcd, al);\r
+                            }\r
+                            \r
                         }\r
                         ListIterator<String> li = al.listIterator();\r
                         while(li.hasNext()) {\r
@@ -1335,12 +1388,31 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         return;\r
                     }\r
                     docConsole.setSaved(false);\r
-                    removeInstance(selectedInstancesTableModel.getValueAt(row, 1) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 2) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 3) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 4));\r
-                    ffc.removeLibraryInstance(moduleKey, row);\r
-                    selectedInstancesTableModel.removeRow(row);\r
+                    String instanceKey = selectedInstancesTableModel.getValueAt(row, 1) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 2) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 3) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 4);\r
+                    removeInstance(instanceKey);\r
+                    \r
+                    selectedInstancesTableModel.setRowCount(0);\r
+                    int instanceCount = ffc.getLibraryInstancesCount(moduleKey);\r
+                    if (instanceCount != 0) {\r
+                        String[][] saa = new String[instanceCount][5];\r
+                        ffc.getLibraryInstances(moduleKey, saa);\r
+                        for (int i = 0; i < saa.length; ++i) {\r
+                            String libInstanceKey = saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4];\r
+                            ModuleIdentification mi = WorkspaceProfile.getModuleId(libInstanceKey);\r
+                            if (mi != null) {\r
+                                //\r
+                                // ToDo: verify this instance first.\r
+                                //\r
+                                saa[i][0] = mi.getName();\r
+                                saa[i][2] = mi.getVersion();\r
+                                saa[i][4] = mi.getPackageId().getVersion();\r
+                                selectedInstancesTableModel.addRow(saa[i]);\r
+                            }\r
+                        }\r
+                    }\r
                     showClassToResolved();\r
                 }\r
             });\r