From: jlin16 Date: Fri, 26 Jan 2007 16:40:37 +0000 (+0000) Subject: Fix EDKT174, auto-select library instance if only one candidate available for a libra... X-Git-Tag: edk2-stable201903~23548 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=b8f186eb785e207dadd1affba8c55232eb3eefd0 Fix EDKT174, auto-select library instance if only one candidate available for a library class. Note that if you remove one single instance, it will NOT be auto-selected back at once. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2329 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java index 366e2e3022..594390c328 100644 --- a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java +++ b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java @@ -780,6 +780,20 @@ public class FpdFileContents { } } + public boolean instanceExistsInModuleSA (String key, String mg, String mv, String pg, String pv) { + int count = 0; + if ((count = getLibraryInstancesCount(key)) > 0) { + String[][] saa = new String[count][5]; + getLibraryInstances (key, saa); + for (int i = 0; i < count; ++i) { + if (mg.equalsIgnoreCase(saa[i][1]) && mv.equalsIgnoreCase(saa[i][2]) && pg.equalsIgnoreCase(saa[i][3]) && pv.equalsIgnoreCase(saa[i][4])) { + return true; + } + } + } + return false; + } + public void removeLibraryInstance(String key, int i) { ModuleSADocument.ModuleSA msa = getModuleSA(key); if (msa == null || msa.getLibraries() == null){ diff --git a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java index 92519f656d..d6b13238af 100644 --- a/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java +++ b/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.ListIterator; +import java.util.Stack; import java.util.Vector; import javax.swing.JTextField; @@ -204,7 +205,7 @@ public class FpdModuleSA extends JDialog implements ActionListener { // // display library classes that need to be resolved. also potential instances for them. // - resolveLibraryInstances(moduleKey, errorMsg); + resolveLibraryInstances(moduleKey, true, errorMsg); } catch (Exception e) { String exceptionMsg = e.getCause() + " " + e.getMessage(); errorMsg.add(exceptionMsg); @@ -232,7 +233,7 @@ public class FpdModuleSA extends JDialog implements ActionListener { // re-evaluate lib instance usage when adding a already-selected lib instance. // try { - resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], errorMsg); + resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], true, errorMsg); } catch (Exception e) { String exceptionMsg = e.getCause() + " " + e.getMessage(); if (!errorMsg.contains(exceptionMsg)) { @@ -251,7 +252,6 @@ public class FpdModuleSA extends JDialog implements ActionListener { } JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors); } - showClassToResolved(); } public void initFvInfo (String key) { @@ -342,35 +342,8 @@ public class FpdModuleSA extends JDialog implements ActionListener { } } - private void resolveLibraryInstances(String key, Vector errorMsg) throws MultipleInstanceException, NoInstanceException{ + private void addProducedClassFromModule (String key) { ModuleIdentification mi = WorkspaceProfile.getModuleId(key); - PackageIdentification[] depPkgList = null; - - // - // Get dependency pkg list into which we will search lib instances. - // - //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi); - // - // Get the lib class consumed, produced by this module itself. - // - Vector vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi); - for (int i = 0; i < vClassConsumed.size(); ++i) { - vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId); - } - filterClassConsumedByArch(vClassConsumed); - if (this.classConsumed == null) { - this.classConsumed = new HashMap>(); - } - - for (int i = 0; i < vClassConsumed.size(); ++i) { - ArrayList consumedBy = this.classConsumed.get(vClassConsumed.get(i)); - if (consumedBy == null) { - consumedBy = new ArrayList(); - } - consumedBy.add(key); - this.classConsumed.put(vClassConsumed.get(i), consumedBy); - } - Vector vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi); if (this.classProduced == null) { this.classProduced = new HashMap>(); @@ -405,20 +378,60 @@ public class FpdModuleSA extends JDialog implements ActionListener { this.classProduced.put(vClassProduced.get(i), producedBy); } + } + + private Vector addConsumedClassFromModule (String key) { + ModuleIdentification mi = WorkspaceProfile.getModuleId(key); +// PackageIdentification[] depPkgList = null; // - // find potential instances in all pkgs for classes still in classConsumed. + // Get dependency pkg list into which we will search lib instances. + // + //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi); + // + // Get the lib class consumed, produced by this module itself. // + Vector vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi); + for (int i = 0; i < vClassConsumed.size(); ++i) { + vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId); + } + filterClassConsumedByArch(vClassConsumed); + if (this.classConsumed == null) { + this.classConsumed = new HashMap>(); + } + + for (int i = 0; i < vClassConsumed.size(); ++i) { + ArrayList consumedBy = this.classConsumed.get(vClassConsumed.get(i)); + if (consumedBy == null) { + consumedBy = new ArrayList(); + } + consumedBy.add(key); + this.classConsumed.put(vClassConsumed.get(i), consumedBy); + } + + return vClassConsumed; + } + + private void resolveLibraryInstances(String key, boolean autoSelectSingleInstance, Vector errorMsg) throws MultipleInstanceException, NoInstanceException{ + + Vector vLcd = addConsumedClassFromModule (key); + addProducedClassFromModule (key); + + Stack lcdStack = new Stack(); + for (int i = 0; i < vLcd.size(); ++i) { + LibraryClassDescriptor cls = vLcd.get(i); + lcdStack.push(cls); + } + if (classInstanceMap == null) { classInstanceMap = new HashMap>(); } - Iterator lic = this.classConsumed.keySet().iterator(); - while (lic.hasNext()) { - LibraryClassDescriptor cls = lic.next(); + while (!lcdStack.empty()) { + LibraryClassDescriptor cls = lcdStack.pop(); if (isBoundedClass(cls, errorMsg)) { continue; } - ArrayList instances = getInstancesForClass(cls, depPkgList); + ArrayList instances = getInstancesForClass(cls, null); if (instances.size() == 0) { // throw new NoInstanceException (cls.className); String exceptionMsg = new NoInstanceException (cls.className).getMessage(); @@ -428,10 +441,35 @@ public class FpdModuleSA extends JDialog implements ActionListener { } classInstanceMap.put(cls, instances); + if (instances.size() == 1 && autoSelectSingleInstance) { + String instanceInfo = instances.get(0); + ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceInfo); + try { + Object[] row = {libMi.getName(), libMi.getGuid(), libMi.getVersion(), + libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()}; + if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) { + addLibInstance(libMi); + docConsole.setSaved(false); + selectedInstancesTableModel.addRow(row); + addProducedClassFromModule (instanceInfo); + vLcd = addConsumedClassFromModule(instanceInfo); + for (int i = 0; i < vLcd.size(); ++i) { + LibraryClassDescriptor lcd = vLcd.get(i); + lcdStack.push(lcd); + } + } + } + catch (Exception e) { + if (!errorMsg.contains(e.getMessage())) { + errorMsg.add(e.getMessage()); + } + } + } + } + showClassToResolved(); } -// showClassToResolved(); - } +// /**Search classProduced map to see if this class has been produced by some instance (module). * @param cls @@ -585,15 +623,17 @@ public class FpdModuleSA extends JDialog implements ActionListener { if (classConsumed == null || classConsumed.size() == 0) { return; } + Iterator li = classConsumed.keySet().iterator(); while(li.hasNext()){ LibraryClassDescriptor lcd = li.next(); - String[] s = {lcd.className, lcd.supArchs, lcd.supModTypes}; if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) { continue; } if (!isBoundedClass(lcd, errorMsg)){ + + String[] s = { lcd.className, lcd.supArchs, lcd.supModTypes }; libClassTableModel.addRow(s); } } @@ -1235,7 +1275,7 @@ public class FpdModuleSA extends JDialog implements ActionListener { Vector errorMsg = new Vector(); try { - resolveLibraryInstances(instanceValue, errorMsg); + resolveLibraryInstances(instanceValue, true, errorMsg); } catch (Exception exp) { JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage()); @@ -1248,7 +1288,6 @@ public class FpdModuleSA extends JDialog implements ActionListener { } JOptionPane.showMessageDialog(FpdModuleSA.this, errors); } - showClassToResolved(); } }); }