Fix EDKT174, auto-select library instance if only one candidate available for a libra...
authorjlin16 <jlin16@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 26 Jan 2007 16:40:37 +0000 (16:40 +0000)
committerjlin16 <jlin16@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 26 Jan 2007 16:40:37 +0000 (16:40 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@2329 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 366e2e3..594390c 100644 (file)
@@ -780,6 +780,20 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public boolean instanceExistsInModuleSA (String key, String mg, String mv, String pg, String pv) {\r
+        int count = 0;\r
+        if ((count = getLibraryInstancesCount(key)) > 0) {\r
+            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
+                    return true;\r
+                }\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+    \r
     public void removeLibraryInstance(String key, int i) {\r
         ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
         if (msa == null || msa.getLibraries() == null){\r
index 92519f6..d6b1323 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.Stack;\r
 import java.util.Vector;\r
 \r
 import javax.swing.JTextField;\r
@@ -204,7 +205,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             //\r
             // display library classes that need to be resolved. also potential instances for them.\r
             //\r
-            resolveLibraryInstances(moduleKey, errorMsg);\r
+            resolveLibraryInstances(moduleKey, true, errorMsg);\r
         } catch (Exception e) {\r
             String exceptionMsg = e.getCause() + " " + e.getMessage();\r
             errorMsg.add(exceptionMsg);\r
@@ -232,7 +233,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     // 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], errorMsg);\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
@@ -251,7 +252,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             }\r
             JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);\r
         }\r
-        showClassToResolved();\r
     }\r
     \r
     public void initFvInfo (String key) {\r
@@ -342,35 +342,8 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         }\r
     }\r
     \r
-    private void resolveLibraryInstances(String key, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{\r
+    private void addProducedClassFromModule (String key) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(key);\r
-        PackageIdentification[] depPkgList = null;\r
-        \r
-        //\r
-        // Get dependency pkg list into which we will search lib instances.\r
-        //\r
-        //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);\r
-        //\r
-        // Get the lib class consumed, produced by this module itself.\r
-        //\r
-        Vector<LibraryClassDescriptor> vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);\r
-        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
-            vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId);\r
-        }\r
-        filterClassConsumedByArch(vClassConsumed);\r
-        if (this.classConsumed == null) {\r
-            this.classConsumed = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
-        }\r
-\r
-        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
-            ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));\r
-            if (consumedBy == null) {\r
-                consumedBy = new ArrayList<String>();\r
-            }\r
-            consumedBy.add(key);\r
-            this.classConsumed.put(vClassConsumed.get(i), consumedBy);\r
-        }\r
-\r
         Vector<LibraryClassDescriptor> vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);\r
         if (this.classProduced == null) {\r
             this.classProduced = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
@@ -405,20 +378,60 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             this.classProduced.put(vClassProduced.get(i), producedBy);\r
             \r
         }\r
+    }\r
+    \r
+    private Vector<LibraryClassDescriptor> addConsumedClassFromModule (String key) {\r
+        ModuleIdentification mi = WorkspaceProfile.getModuleId(key);\r
+//        PackageIdentification[] depPkgList = null;\r
 \r
         //\r
-        // find potential instances in all pkgs for classes still in classConsumed.\r
+        // Get dependency pkg list into which we will search lib instances.\r
+        //\r
+        //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);\r
+        //\r
+        // Get the lib class consumed, produced by this module itself.\r
         //\r
+        Vector<LibraryClassDescriptor> vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);\r
+        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
+            vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId);\r
+        }\r
+        filterClassConsumedByArch(vClassConsumed);\r
+        if (this.classConsumed == null) {\r
+            this.classConsumed = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
+        }\r
+\r
+        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
+            ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));\r
+            if (consumedBy == null) {\r
+                consumedBy = new ArrayList<String>();\r
+            }\r
+            consumedBy.add(key);\r
+            this.classConsumed.put(vClassConsumed.get(i), consumedBy);\r
+        }\r
+\r
+        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
+        \r
         if (classInstanceMap == null) {\r
             classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
         }\r
-        Iterator<LibraryClassDescriptor> lic = this.classConsumed.keySet().iterator();\r
-        while (lic.hasNext()) {\r
-            LibraryClassDescriptor cls = lic.next();\r
+        while (!lcdStack.empty()) {\r
+            LibraryClassDescriptor cls = lcdStack.pop();\r
             if (isBoundedClass(cls, errorMsg)) {\r
                 continue;\r
             }\r
-            ArrayList<String> instances = getInstancesForClass(cls, depPkgList);\r
+            ArrayList<String> instances = getInstancesForClass(cls, null);\r
             if (instances.size() == 0) {\r
 //                throw new NoInstanceException (cls.className);\r
                 String exceptionMsg = new NoInstanceException (cls.className).getMessage();\r
@@ -428,10 +441,35 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 \r
             }\r
             classInstanceMap.put(cls, instances);\r
+            if (instances.size() == 1 && autoSelectSingleInstance) {\r
+                String instanceInfo = instances.get(0);\r
+                ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceInfo);\r
+                try {\r
+                    Object[] row = {libMi.getName(), libMi.getGuid(), libMi.getVersion(), \r
+                                    libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()};\r
+                    if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) {\r
+                        addLibInstance(libMi);\r
+                        docConsole.setSaved(false);\r
+                        selectedInstancesTableModel.addRow(row);\r
+                        addProducedClassFromModule (instanceInfo);\r
+                        vLcd = addConsumedClassFromModule(instanceInfo);\r
+                        for (int i = 0; i < vLcd.size(); ++i) {\r
+                            LibraryClassDescriptor lcd = vLcd.get(i);\r
+                            lcdStack.push(lcd);\r
+                        }\r
+                    }\r
+                }\r
+                catch (Exception e) {\r
+                    if (!errorMsg.contains(e.getMessage())) {\r
+                        errorMsg.add(e.getMessage());\r
+                    }\r
+                }\r
+            }\r
+        }\r
 \r
+        showClassToResolved();\r
         }\r
-//            showClassToResolved();\r
-    }\r
+//            \r
 \r
     /**Search classProduced map to see if this class has been produced by some instance (module).\r
      * @param cls\r
@@ -585,15 +623,17 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         if (classConsumed == null || classConsumed.size() == 0) {\r
             return;\r
         }\r
+\r
         Iterator<LibraryClassDescriptor> li = classConsumed.keySet().iterator();\r
         while(li.hasNext()){\r
             LibraryClassDescriptor lcd = li.next();\r
-            String[] s = {lcd.className, lcd.supArchs, lcd.supModTypes};\r
             if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) {\r
                 continue;\r
             }\r
             \r
             if (!isBoundedClass(lcd, errorMsg)){\r
+     \r
+                String[] s = { lcd.className, lcd.supArchs, lcd.supModTypes };\r
                 libClassTableModel.addRow(s);\r
             }\r
         }\r
@@ -1235,7 +1275,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     \r
                     Vector<String> errorMsg = new Vector<String>();\r
                     try {\r
-                        resolveLibraryInstances(instanceValue, errorMsg);\r
+                        resolveLibraryInstances(instanceValue, true, errorMsg);\r
                     }\r
                     catch (Exception exp) {\r
                         JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());\r
@@ -1248,7 +1288,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         }\r
                         JOptionPane.showMessageDialog(FpdModuleSA.this, errors);\r
                     }\r
-                    showClassToResolved();\r
                 }\r
             });\r
         }\r