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
This commit is contained in:
jlin16 2007-01-26 16:40:37 +00:00
parent c7916981cc
commit b8f186eb78
2 changed files with 95 additions and 42 deletions

View File

@ -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) { public void removeLibraryInstance(String key, int i) {
ModuleSADocument.ModuleSA msa = getModuleSA(key); ModuleSADocument.ModuleSA msa = getModuleSA(key);
if (msa == null || msa.getLibraries() == null){ if (msa == null || msa.getLibraries() == null){

View File

@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Stack;
import java.util.Vector; import java.util.Vector;
import javax.swing.JTextField; 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. // display library classes that need to be resolved. also potential instances for them.
// //
resolveLibraryInstances(moduleKey, errorMsg); resolveLibraryInstances(moduleKey, true, errorMsg);
} catch (Exception e) { } catch (Exception e) {
String exceptionMsg = e.getCause() + " " + e.getMessage(); String exceptionMsg = e.getCause() + " " + e.getMessage();
errorMsg.add(exceptionMsg); 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. // re-evaluate lib instance usage when adding a already-selected lib instance.
// //
try { 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) { } catch (Exception e) {
String exceptionMsg = e.getCause() + " " + e.getMessage(); String exceptionMsg = e.getCause() + " " + e.getMessage();
if (!errorMsg.contains(exceptionMsg)) { if (!errorMsg.contains(exceptionMsg)) {
@ -251,7 +252,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors); JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);
} }
showClassToResolved();
} }
public void initFvInfo (String key) { public void initFvInfo (String key) {
@ -342,35 +342,8 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
} }
private void resolveLibraryInstances(String key, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{ private void addProducedClassFromModule (String key) {
ModuleIdentification mi = WorkspaceProfile.getModuleId(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<LibraryClassDescriptor> 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<LibraryClassDescriptor, ArrayList<String>>();
}
for (int i = 0; i < vClassConsumed.size(); ++i) {
ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));
if (consumedBy == null) {
consumedBy = new ArrayList<String>();
}
consumedBy.add(key);
this.classConsumed.put(vClassConsumed.get(i), consumedBy);
}
Vector<LibraryClassDescriptor> vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi); Vector<LibraryClassDescriptor> vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);
if (this.classProduced == null) { if (this.classProduced == null) {
this.classProduced = new HashMap<LibraryClassDescriptor, ArrayList<String>>(); this.classProduced = new HashMap<LibraryClassDescriptor, ArrayList<String>>();
@ -405,20 +378,60 @@ public class FpdModuleSA extends JDialog implements ActionListener {
this.classProduced.put(vClassProduced.get(i), producedBy); this.classProduced.put(vClassProduced.get(i), producedBy);
} }
}
private Vector<LibraryClassDescriptor> 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<LibraryClassDescriptor> 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<LibraryClassDescriptor, ArrayList<String>>();
}
for (int i = 0; i < vClassConsumed.size(); ++i) {
ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));
if (consumedBy == null) {
consumedBy = new ArrayList<String>();
}
consumedBy.add(key);
this.classConsumed.put(vClassConsumed.get(i), consumedBy);
}
return vClassConsumed;
}
private void resolveLibraryInstances(String key, boolean autoSelectSingleInstance, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{
Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (key);
addProducedClassFromModule (key);
Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();
for (int i = 0; i < vLcd.size(); ++i) {
LibraryClassDescriptor cls = vLcd.get(i);
lcdStack.push(cls);
}
if (classInstanceMap == null) { if (classInstanceMap == null) {
classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>(); classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>();
} }
Iterator<LibraryClassDescriptor> lic = this.classConsumed.keySet().iterator(); while (!lcdStack.empty()) {
while (lic.hasNext()) { LibraryClassDescriptor cls = lcdStack.pop();
LibraryClassDescriptor cls = lic.next();
if (isBoundedClass(cls, errorMsg)) { if (isBoundedClass(cls, errorMsg)) {
continue; continue;
} }
ArrayList<String> instances = getInstancesForClass(cls, depPkgList); ArrayList<String> instances = getInstancesForClass(cls, null);
if (instances.size() == 0) { if (instances.size() == 0) {
// throw new NoInstanceException (cls.className); // throw new NoInstanceException (cls.className);
String exceptionMsg = new NoInstanceException (cls.className).getMessage(); String exceptionMsg = new NoInstanceException (cls.className).getMessage();
@ -428,10 +441,35 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
classInstanceMap.put(cls, instances); 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). /**Search classProduced map to see if this class has been produced by some instance (module).
* @param cls * @param cls
@ -585,15 +623,17 @@ public class FpdModuleSA extends JDialog implements ActionListener {
if (classConsumed == null || classConsumed.size() == 0) { if (classConsumed == null || classConsumed.size() == 0) {
return; return;
} }
Iterator<LibraryClassDescriptor> li = classConsumed.keySet().iterator(); Iterator<LibraryClassDescriptor> li = classConsumed.keySet().iterator();
while(li.hasNext()){ while(li.hasNext()){
LibraryClassDescriptor lcd = li.next(); LibraryClassDescriptor lcd = li.next();
String[] s = {lcd.className, lcd.supArchs, lcd.supModTypes};
if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) { if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) {
continue; continue;
} }
if (!isBoundedClass(lcd, errorMsg)){ if (!isBoundedClass(lcd, errorMsg)){
String[] s = { lcd.className, lcd.supArchs, lcd.supModTypes };
libClassTableModel.addRow(s); libClassTableModel.addRow(s);
} }
} }
@ -1235,7 +1275,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
Vector<String> errorMsg = new Vector<String>(); Vector<String> errorMsg = new Vector<String>();
try { try {
resolveLibraryInstances(instanceValue, errorMsg); resolveLibraryInstances(instanceValue, true, errorMsg);
} }
catch (Exception exp) { catch (Exception exp) {
JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage()); JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());
@ -1248,7 +1288,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
JOptionPane.showMessageDialog(FpdModuleSA.this, errors); JOptionPane.showMessageDialog(FpdModuleSA.this, errors);
} }
showClassToResolved();
} }
}); });
} }