Optimize library instance selection algorithm.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2342 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jlin16 2007-01-31 11:43:58 +00:00
parent 9e011eacdb
commit fd0f684ffa
2 changed files with 88 additions and 49 deletions

View File

@ -786,9 +786,24 @@ public class FpdFileContents {
String[][] saa = new String[count][5]; String[][] saa = new String[count][5];
getLibraryInstances (key, saa); getLibraryInstances (key, saa);
for (int i = 0; i < count; ++i) { 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])) { if (mg.equalsIgnoreCase(saa[i][1]) && pg.equalsIgnoreCase(saa[i][3])) {
boolean modVerMatch = false;
boolean pkgVerMatch = false;
if ((mv.equals("null") || saa[i][2] == null)) {
modVerMatch = true;
}
if (pv.equals("null") || saa[i][4] == null) {
pkgVerMatch = true;
}
if (modVerMatch && pkgVerMatch) {
return true; return true;
} }
else {
if (mv.equals(saa[i][2]) && pv.equals(saa[i][4])) {
return true;
}
}
}
} }
} }
return false; return false;

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.Set;
import java.util.Stack; import java.util.Stack;
import java.util.Vector; import java.util.Vector;
@ -201,27 +202,18 @@ public class FpdModuleSA extends JDialog implements ActionListener {
libInstanceTableModel.setRowCount(0); libInstanceTableModel.setRowCount(0);
selectedInstancesTableModel.setRowCount(0); selectedInstancesTableModel.setRowCount(0);
Vector<String> errorMsg = new Vector<String>(); Vector<String> errorMsg = new Vector<String>();
try { Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();
//
// display library classes that need to be resolved. also potential instances for them. addConsumedClassFromModule (key);
// addProducedClassFromModule (key);
resolveLibraryInstances(moduleKey, true, errorMsg);
} catch (Exception e) {
String exceptionMsg = e.getCause() + " " + e.getMessage();
errorMsg.add(exceptionMsg);
JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), exceptionMsg);
}
//
// display lib instances already selected for key
//
int instanceCount = ffc.getLibraryInstancesCount(key); int instanceCount = ffc.getLibraryInstancesCount(key);
if (instanceCount != 0) { if (instanceCount != 0) {
String[][] saa = new String[instanceCount][5]; String[][] saa = new String[instanceCount][5];
ffc.getLibraryInstances(key, saa); ffc.getLibraryInstances(key, saa);
for (int i = 0; i < saa.length; ++i) { for (int i = 0; i < saa.length; ++i) {
ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] String libInstanceKey = saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4];
+ " " + saa[i][4]); ModuleIdentification mi = WorkspaceProfile.getModuleId(libInstanceKey);
if (mi != null) { if (mi != null) {
// //
// ToDo: verify this instance first. // ToDo: verify this instance first.
@ -232,19 +224,48 @@ 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 { addConsumedClassFromModule (libInstanceKey);
resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], true, errorMsg); addProducedClassFromModule (libInstanceKey);
} catch (Exception e) {
String exceptionMsg = e.getCause() + " " + e.getMessage();
if (!errorMsg.contains(exceptionMsg)) {
JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());
}
}
selectedInstancesTableModel.addRow(saa[i]); selectedInstancesTableModel.addRow(saa[i]);
} }
} }
} }
Set<LibraryClassDescriptor> sLcd = this.classConsumed.keySet();
Iterator<LibraryClassDescriptor> iter = sLcd.iterator();
Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();
while (iter.hasNext()) {
LibraryClassDescriptor lcd = iter.next();
if (isBoundedClass(lcd, errorMsg)) {
continue;
}
if (!lcdStack.contains(lcd)) {
lcdStack.push(lcd);
}
}
try {
resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);
} catch (Exception e) {
String exceptionMsg = e.getCause() + " " + e.getMessage();
if (!errorMsg.contains(exceptionMsg)) {
JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());
}
}
String newInstancesAddedMsg = "Library instance automatically added to this module :\n";
for (int i = 0; i < newInstances.size(); ++i) {
ModuleIdentification libMi = newInstances.get(i);
newInstancesAddedMsg += libMi.getName();
newInstancesAddedMsg += " ";
}
if (newInstances.size() > 0) {
JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), newInstancesAddedMsg);
}
showClassToResolved();
if (errorMsg.size() > 0) { if (errorMsg.size() > 0) {
String errors = ""; String errors = "";
for (int i = 0; i < errorMsg.size(); ++i) { for (int i = 0; i < errorMsg.size(); ++i) {
@ -412,16 +433,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
return vClassConsumed; return vClassConsumed;
} }
private void resolveLibraryInstances(String key, boolean autoSelectSingleInstance, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{ private void resolveLibraryInstances(Stack<LibraryClassDescriptor> lcdStack, boolean autoSelectSingleInstance, Vector<String> errorMsg, Vector<ModuleIdentification> newInstances) 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>>();
@ -449,13 +461,16 @@ public class FpdModuleSA extends JDialog implements ActionListener {
libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()}; libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()};
if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) { if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) {
addLibInstance(libMi); addLibInstance(libMi);
newInstances.add(libMi);
docConsole.setSaved(false); docConsole.setSaved(false);
selectedInstancesTableModel.addRow(row); selectedInstancesTableModel.addRow(row);
addProducedClassFromModule (instanceInfo); addProducedClassFromModule (instanceInfo);
vLcd = addConsumedClassFromModule(instanceInfo); Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule(instanceInfo);
for (int i = 0; i < vLcd.size(); ++i) { for (int i = 0; i < vLcd.size(); ++i) {
LibraryClassDescriptor lcd = vLcd.get(i); LibraryClassDescriptor lcd = vLcd.get(i);
lcdStack.push(lcd); if (!lcdStack.contains(lcd)) {
lcdStack.push(lcd);
}
} }
} }
} }
@ -466,9 +481,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
} }
} }
}
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).
@ -590,8 +603,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
} }
showClassToResolved();
} }
@ -1255,11 +1266,11 @@ public class FpdModuleSA extends JDialog implements ActionListener {
return; return;
} }
String instanceValue = libInstanceTableModel.getValueAt(row, 1) + " " + String libInstanceKey = libInstanceTableModel.getValueAt(row, 1) + " " +
libInstanceTableModel.getValueAt(row, 2) + " " + libInstanceTableModel.getValueAt(row, 2) + " " +
libInstanceTableModel.getValueAt(row, 3) + " " + libInstanceTableModel.getValueAt(row, 3) + " " +
libInstanceTableModel.getValueAt(row, 4); libInstanceTableModel.getValueAt(row, 4);
ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceValue); ModuleIdentification libMi = WorkspaceProfile.getModuleId(libInstanceKey);
try { try {
addLibInstance (libMi); addLibInstance (libMi);
} }
@ -1273,14 +1284,27 @@ public class FpdModuleSA extends JDialog implements ActionListener {
libInstanceTableModel.getValueAt(row, 4)}; libInstanceTableModel.getValueAt(row, 4)};
selectedInstancesTableModel.addRow(s); selectedInstancesTableModel.addRow(s);
Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (libInstanceKey);
addProducedClassFromModule (libInstanceKey);
Vector<String> errorMsg = new Vector<String>(); Vector<String> errorMsg = new Vector<String>();
Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();
Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();
for (int i = 0; i < vLcd.size(); ++i) {
LibraryClassDescriptor lcd = vLcd.get(i);
if (!lcdStack.contains(lcd)) {
lcdStack.push(lcd);
}
}
try { try {
resolveLibraryInstances(instanceValue, true, errorMsg); resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);
} }
catch (Exception exp) { catch (Exception exp) {
JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage()); JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());
} }
showClassToResolved();
if (errorMsg.size() > 0) { if (errorMsg.size() > 0) {
String errors = ""; String errors = "";
for (int i = 0; i < errorMsg.size(); ++i) { for (int i = 0; i < errorMsg.size(); ++i) {
@ -1317,7 +1341,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
selectedInstancesTableModel.getValueAt(row, 4)); selectedInstancesTableModel.getValueAt(row, 4));
ffc.removeLibraryInstance(moduleKey, row); ffc.removeLibraryInstance(moduleKey, row);
selectedInstancesTableModel.removeRow(row); selectedInstancesTableModel.removeRow(row);
showClassToResolved();
} }
}); });
} }