Optimize library instance selection algorithm.
authorjlin16 <jlin16@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 31 Jan 2007 11:43:58 +0000 (11:43 +0000)
committerjlin16 <jlin16@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 31 Jan 2007 11:43:58 +0000 (11:43 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@2342 de2fecce-e211-0410-80a6-f3fac2684e05

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

index 594390c..adc6d26 100644 (file)
@@ -786,9 +786,24 @@ public class FpdFileContents {
             String[][] saa = new String[count][5];\r
             getLibraryInstances (key, saa);\r
             for (int i = 0; i < count; ++i) {\r
-                if (mg.equalsIgnoreCase(saa[i][1]) && mv.equalsIgnoreCase(saa[i][2]) && pg.equalsIgnoreCase(saa[i][3]) && pv.equalsIgnoreCase(saa[i][4])) {\r
+                if (mg.equalsIgnoreCase(saa[i][1]) && pg.equalsIgnoreCase(saa[i][3])) {\r
+                    boolean modVerMatch = false;\r
+                    boolean pkgVerMatch = false;\r
+                    if ((mv.equals("null") || saa[i][2] == null)) {\r
+                        modVerMatch = true;\r
+                    }\r
+                    if (pv.equals("null") || saa[i][4] == null) {\r
+                        pkgVerMatch = true;\r
+                    }\r
+                    if (modVerMatch && pkgVerMatch) {\r
                     return true;\r
                 }\r
+                    else {\r
+                        if (mv.equals(saa[i][2]) && pv.equals(saa[i][4])) {\r
+                            return true;\r
+                        }\r
+                    }\r
+                }\r
             }\r
         }\r
         return false;\r
index d6b1323..102dd3d 100644 (file)
@@ -41,6 +41,7 @@ import java.util.ArrayList;
 import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.ListIterator;\r
+import java.util.Set;\r
 import java.util.Stack;\r
 import java.util.Vector;\r
 \r
@@ -201,27 +202,18 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         libInstanceTableModel.setRowCount(0);\r
         selectedInstancesTableModel.setRowCount(0);\r
         Vector<String> errorMsg = new Vector<String>();\r
-        try {\r
-            //\r
-            // display library classes that need to be resolved. also potential instances for them.\r
-            //\r
-            resolveLibraryInstances(moduleKey, true, errorMsg);\r
-        } catch (Exception e) {\r
-            String exceptionMsg = e.getCause() + " " + e.getMessage();\r
-            errorMsg.add(exceptionMsg);\r
-            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), exceptionMsg);\r
-        }\r
-        //\r
-        // display lib instances already selected for key\r
-        //\r
+        Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();\r
+        \r
+        addConsumedClassFromModule (key);\r
+        addProducedClassFromModule (key);\r
         \r
         int instanceCount = ffc.getLibraryInstancesCount(key);\r
         if (instanceCount != 0) {\r
             String[][] saa = new String[instanceCount][5];\r
             ffc.getLibraryInstances(key, saa);\r
             for (int i = 0; i < saa.length; ++i) {\r
-                ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3]\r
-                                                                       + " " + saa[i][4]);\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
@@ -232,19 +224,48 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     //\r
                     // re-evaluate lib instance usage when adding a already-selected lib instance.\r
                     //\r
-                    try {\r
-                        resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], true, errorMsg);\r
-                    } catch (Exception e) {\r
-                        String exceptionMsg = e.getCause() + " " + e.getMessage();\r
-                        if (!errorMsg.contains(exceptionMsg)) {\r
-                            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());\r
-                        }\r
-                    }\r
+                    addConsumedClassFromModule (libInstanceKey);\r
+                    addProducedClassFromModule (libInstanceKey);\r
                     selectedInstancesTableModel.addRow(saa[i]);\r
                 }\r
             }\r
         }\r
-\r
+        \r
+        Set<LibraryClassDescriptor> sLcd = this.classConsumed.keySet();\r
+        Iterator<LibraryClassDescriptor> iter = sLcd.iterator(); \r
+        Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
+        while (iter.hasNext()) {\r
+            LibraryClassDescriptor lcd = iter.next();\r
+            if (isBoundedClass(lcd, errorMsg)) {\r
+                continue;\r
+            }\r
+            \r
+            if (!lcdStack.contains(lcd)) {\r
+                lcdStack.push(lcd);\r
+            }\r
+        }\r
+        \r
+        try {\r
+            resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);\r
+        } catch (Exception e) {\r
+            String exceptionMsg = e.getCause() + " " + e.getMessage();\r
+            if (!errorMsg.contains(exceptionMsg)) {\r
+                JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());\r
+            }\r
+        }\r
+        \r
+        String newInstancesAddedMsg = "Library instance automatically added to this module :\n";\r
+        for (int i = 0; i < newInstances.size(); ++i) {\r
+            ModuleIdentification libMi = newInstances.get(i);\r
+            newInstancesAddedMsg += libMi.getName();\r
+            newInstancesAddedMsg += " ";\r
+        }\r
+        if (newInstances.size() > 0) {\r
+            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), newInstancesAddedMsg);\r
+        }\r
+        \r
+        showClassToResolved();\r
+        \r
         if (errorMsg.size() > 0) {\r
             String errors = "";\r
             for (int i = 0; i < errorMsg.size(); ++i) {\r
@@ -383,7 +404,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     private Vector<LibraryClassDescriptor> addConsumedClassFromModule (String key) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(key);\r
 //        PackageIdentification[] depPkgList = null;\r
-\r
+        \r
         //\r
         // Get dependency pkg list into which we will search lib instances.\r
         //\r
@@ -412,20 +433,11 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         return vClassConsumed;\r
     }\r
     \r
-    private void resolveLibraryInstances(String key, boolean autoSelectSingleInstance, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{\r
-                \r
-        Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (key);\r
-        addProducedClassFromModule (key);\r
-        \r
-        Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
-        for (int i = 0; i < vLcd.size(); ++i) {\r
-            LibraryClassDescriptor cls = vLcd.get(i);\r
-            lcdStack.push(cls);\r
-        }\r
+    private void resolveLibraryInstances(Stack<LibraryClassDescriptor> lcdStack, boolean autoSelectSingleInstance, Vector<String> errorMsg, Vector<ModuleIdentification> newInstances) throws MultipleInstanceException, NoInstanceException{\r
         \r
         if (classInstanceMap == null) {\r
             classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
-        }\r
+        }        \r
         while (!lcdStack.empty()) {\r
             LibraryClassDescriptor cls = lcdStack.pop();\r
             if (isBoundedClass(cls, errorMsg)) {\r
@@ -449,13 +461,16 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                                     libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()};\r
                     if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) {\r
                         addLibInstance(libMi);\r
+                        newInstances.add(libMi);\r
                         docConsole.setSaved(false);\r
                         selectedInstancesTableModel.addRow(row);\r
                         addProducedClassFromModule (instanceInfo);\r
-                        vLcd = addConsumedClassFromModule(instanceInfo);\r
+                        Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule(instanceInfo);\r
                         for (int i = 0; i < vLcd.size(); ++i) {\r
                             LibraryClassDescriptor lcd = vLcd.get(i);\r
-                            lcdStack.push(lcd);\r
+                            if (!lcdStack.contains(lcd)) {\r
+                                lcdStack.push(lcd);\r
+                            }\r
                         }\r
                     }\r
                 }\r
@@ -466,9 +481,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 }\r
             }\r
         }\r
-\r
-        showClassToResolved();\r
-        }\r
+    }\r
 //            \r
 \r
     /**Search classProduced map to see if this class has been produced by some instance (module).\r
@@ -590,8 +603,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             \r
         }\r
         \r
-        showClassToResolved();\r
-        \r
     }\r
     \r
     \r
@@ -637,7 +648,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 libClassTableModel.addRow(s);\r
             }\r
         }\r
-        \r
+\r
         if (errorMsg.size() > 0) {\r
             String errors = "";\r
             for (int i = 0; i < errorMsg.size(); ++i) {\r
@@ -1255,11 +1266,11 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         return;\r
                     }\r
                     \r
-                    String instanceValue = libInstanceTableModel.getValueAt(row, 1) + " " +\r
+                    String libInstanceKey = libInstanceTableModel.getValueAt(row, 1) + " " +\r
                     libInstanceTableModel.getValueAt(row, 2) + " " +\r
                     libInstanceTableModel.getValueAt(row, 3) + " " +\r
                     libInstanceTableModel.getValueAt(row, 4);\r
-                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceValue);\r
+                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(libInstanceKey);\r
                     try {\r
                         addLibInstance (libMi);\r
                     }\r
@@ -1273,14 +1284,27 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                                   libInstanceTableModel.getValueAt(row, 4)};\r
                     selectedInstancesTableModel.addRow(s);\r
                     \r
+                    Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (libInstanceKey);\r
+                    addProducedClassFromModule (libInstanceKey);\r
+                    \r
                     Vector<String> errorMsg = new Vector<String>();\r
+                    Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();\r
+                    Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
+                    for (int i = 0; i < vLcd.size(); ++i) {\r
+                        LibraryClassDescriptor lcd = vLcd.get(i);\r
+                        if (!lcdStack.contains(lcd)) {\r
+                            lcdStack.push(lcd);\r
+                        }\r
+                    }\r
                     try {\r
-                        resolveLibraryInstances(instanceValue, true, errorMsg);\r
+                        resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);\r
                     }\r
                     catch (Exception exp) {\r
                         JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());\r
                     }\r
                     \r
+                    showClassToResolved();\r
+                    \r
                     if (errorMsg.size() > 0) {\r
                         String errors = "";\r
                         for (int i = 0; i < errorMsg.size(); ++i) {\r
@@ -1317,7 +1341,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                                    selectedInstancesTableModel.getValueAt(row, 4));\r
                     ffc.removeLibraryInstance(moduleKey, row);\r
                     selectedInstancesTableModel.removeRow(row);\r
-                    \r
+                    showClassToResolved();\r
                 }\r
             });\r
         }\r