import org.tianocore.SkuInfoDocument;\r
import org.tianocore.UserDefinedAntTasksDocument;\r
import org.tianocore.UserExtensionsDocument;\r
+import org.tianocore.LibrariesDocument.Libraries.Instance;\r
import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;\r
import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
cursor.dispose();\r
}\r
\r
- public boolean adjustPcd (int seqModuleSa, Vector<String> vExceptions) throws Exception {\r
+ public boolean adjustPcd (String seqModuleSa, Vector<String> vExceptions) throws Exception {\r
boolean dataModified = false;\r
ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
int pcdCount = getPcdDataCount(seqModuleSa);\r
//\r
// key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
//\r
- public int getPcdDataCount (int i){\r
- ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
+ public int getPcdDataCount (String key){\r
+ ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
\r
if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
return 0;\r
\r
}\r
\r
- public void getPcdData (int i, String[][] saa) {\r
- ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
+ public void getPcdData (String key, String[][] saa) {\r
+ ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
\r
if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
return;\r
}\r
}\r
\r
- public void removePcdData (int seqModuleSa, String cName, String tsGuid) {\r
- ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
+ public void removePcdData (String key, String cName, String tsGuid) {\r
+ ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);\r
if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){\r
return;\r
}\r
PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
maintainDynPcdMap(cName + " " + tsGuid, moduleKey);\r
- if (getPcdDataCount(seqModuleSa) == 1) {\r
+ if (getPcdDataCount(key) == 1) {\r
cursor.toParent();\r
}\r
cursor.removeXml();\r
return false;\r
}\r
\r
- public void removeLibraryInstance(String key, int i) {\r
+ public void removeLibraryInstance(String key, String instanceKey) {\r
ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
if (msa == null || msa.getLibraries() == null){\r
return ;\r
}\r
\r
+ String[] instanceInfo = instanceKey.split(" ");\r
XmlCursor cursor = msa.getLibraries().newCursor();\r
if (cursor.toFirstChild()) {\r
- for (int j = 0; j < i; ++j) {\r
- cursor.toNextSibling();\r
+ do {\r
+ Instance libIns = (Instance)cursor.getObject();\r
+ if (libIns.getModuleGuid().equalsIgnoreCase(instanceInfo[0]) && libIns.getPackageGuid().equalsIgnoreCase(instanceInfo[2])) {\r
+ break;\r
}\r
+ }while (cursor.toNextSibling());\r
cursor.push();\r
while (cursor.hasPrevToken()) {\r
cursor.toPrevToken();\r
private FpdFileContents ffc = null;\r
private String moduleKey = null;\r
private ModuleIdentification moduleId = null;\r
- private int moduleSaNum = -1;\r
private HashMap<LibraryClassDescriptor, ArrayList<String>> classInstanceMap = null;\r
//\r
// map of <{libName, supArch, supMod}, list of Module information>\r
\r
public void setKey(String k, int i, OpeningPlatformType dc){\r
this.moduleKey = k;\r
- moduleSaNum = i;\r
this.docConsole = dc;\r
classInstanceMap = null;\r
classProduced = null;\r
classConsumed = null;\r
jTabbedPane.setSelectedIndex(0);\r
- initPcdBuildDefinition(i);\r
+ initPcdBuildDefinition(moduleKey);\r
moduleId = WorkspaceProfile.getModuleId(moduleKey);\r
if (moduleId == null) {\r
return;\r
init will be called each time FpdModuleSA object is to be shown.\r
@param key Module information.\r
**/\r
- public void initPcdBuildDefinition(int i) {\r
+ public void initPcdBuildDefinition(String key) {\r
//\r
// display pcd for key.\r
//\r
jComboBoxItemType.setSelectedIndex(-1);\r
jTextFieldMaxDatumSize.setText("");\r
jTextFieldPcdDefault.setText("");\r
- int pcdCount = ffc.getPcdDataCount(i);\r
+ int pcdCount = ffc.getPcdDataCount(key);\r
if (pcdCount != 0) {\r
String[][] saa = new String[pcdCount][7];\r
- ffc.getPcdData(i, saa);\r
+ ffc.getPcdData(key, saa);\r
for (int j = 0; j < saa.length; ++j) {\r
model.addRow(saa[j]);\r
}\r
Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
while (iter.hasNext()) {\r
LibraryClassDescriptor lcd = iter.next();\r
+ if (this.classConsumed.get(lcd) == null || this.classConsumed.get(lcd).size() == 0) {\r
+ continue;\r
+ }\r
if (isBoundedClass(lcd, errorMsg)) {\r
continue;\r
}\r
return null;\r
}\r
\r
+ private ArrayList<String> getProducedBy (String className) {\r
+ Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();\r
+ while (lcdi.hasNext()) {\r
+ LibraryClassDescriptor lcd = lcdi.next();\r
+ if ((lcd.className != null) && lcd.className.equals(className)) {\r
+ return this.classProduced.get(lcd);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ //\r
+ // Get class name list related with instanceKey from HashMap m<LibraryClass, ArrayList<instanceKey>>.\r
+ //\r
+ private ArrayList<String> getLibraryClassList (String instanceKey, HashMap<LibraryClassDescriptor, ArrayList<String>> m) {\r
+ ArrayList<String> libraryClass = new ArrayList<String>();\r
+ Iterator<LibraryClassDescriptor> lcdi = m.keySet().iterator();\r
+ while (lcdi.hasNext()) {\r
+ LibraryClassDescriptor lcd = lcdi.next();\r
+ if ((m.get(lcd) != null) && m.get(lcd).contains(instanceKey)) {\r
+ libraryClass.add(lcd.className);\r
+ }\r
+ }\r
+ return libraryClass;\r
+ }\r
+ \r
private void removeInstance(String key) {\r
ModuleIdentification mi = WorkspaceProfile.getModuleId(key); \r
//\r
// remove pcd information of instance from current ModuleSA\r
+ // Note that Pcd data SHOULD be removed prior to library instance\r
+ // because Multi-Sourced PCD could not be removed, if we remove library instance first,\r
+ // it will impact the judgement of whether a PCD entry is Multi-Sourced.\r
//\r
ffc.removePcdData(moduleKey, mi);\r
+ ffc.removeLibraryInstance(moduleKey, key);\r
//\r
// remove class produced by this instance and add back these produced class to be bound.\r
//\r
continue;\r
}\r
al.remove(key);\r
- \r
+ if (al.size() == 0) {\r
+ ArrayList<String> from = getProducedBy (clsConsumed[i]);\r
+ if (from == null) {\r
+ continue;\r
+ }\r
+ boolean noUse = true;\r
+ for (int j = 0; j < from.size(); ++j) {\r
+ ArrayList<String> libClasses = getLibraryClassList(from.get(j), classProduced);\r
+ for (int k = 0; k < libClasses.size(); ++k) {\r
+ if (getConsumedBy (libClasses.get(k)) != null && getConsumedBy (libClasses.get(k)).size() > 0) {\r
+ noUse = false;\r
+ }\r
+ }\r
+ if (noUse) {\r
+ removeInstance(from.get(j));\r
+ }\r
+ noUse = true;\r
+ }\r
+ }\r
}\r
\r
}\r
jPanelPcd.add(getJPanelPcdSouth(), java.awt.BorderLayout.SOUTH);\r
jPanelPcd.addComponentListener(new java.awt.event.ComponentAdapter() {\r
public void componentShown(java.awt.event.ComponentEvent e) {\r
- initPcdBuildDefinition(moduleSaNum);\r
+ initPcdBuildDefinition(moduleKey);\r
}\r
});\r
\r
String cls = libClassTableModel.getValueAt(selectedRow2, 0).toString();\r
String arch = libClassTableModel.getValueAt(selectedRow2, 1).toString();\r
String modType = libClassTableModel.getValueAt(selectedRow2, 2).toString();\r
- ArrayList<String> al = classInstanceMap.get(new LibraryClassDescriptor(cls, arch, modType));\r
+ LibraryClassDescriptor lcd = new LibraryClassDescriptor(cls, arch, modType);\r
+ ArrayList<String> al = classInstanceMap.get(lcd);\r
if (al == null) {\r
- return;\r
+ al = getInstancesForClass(lcd, null);\r
+ if (al.size() != 0) {\r
+ classInstanceMap.put(lcd, al);\r
+ }\r
+ \r
}\r
ListIterator<String> li = al.listIterator();\r
while(li.hasNext()) {\r
return;\r
}\r
docConsole.setSaved(false);\r
- removeInstance(selectedInstancesTableModel.getValueAt(row, 1) + " " +\r
- selectedInstancesTableModel.getValueAt(row, 2) + " " +\r
- selectedInstancesTableModel.getValueAt(row, 3) + " " +\r
- selectedInstancesTableModel.getValueAt(row, 4));\r
- ffc.removeLibraryInstance(moduleKey, row);\r
- selectedInstancesTableModel.removeRow(row);\r
+ String instanceKey = selectedInstancesTableModel.getValueAt(row, 1) + " "\r
+ + selectedInstancesTableModel.getValueAt(row, 2) + " "\r
+ + selectedInstancesTableModel.getValueAt(row, 3) + " "\r
+ + selectedInstancesTableModel.getValueAt(row, 4);\r
+ removeInstance(instanceKey);\r
+ \r
+ selectedInstancesTableModel.setRowCount(0);\r
+ int instanceCount = ffc.getLibraryInstancesCount(moduleKey);\r
+ if (instanceCount != 0) {\r
+ String[][] saa = new String[instanceCount][5];\r
+ ffc.getLibraryInstances(moduleKey, saa);\r
+ for (int i = 0; i < saa.length; ++i) {\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
+ //\r
+ saa[i][0] = mi.getName();\r
+ saa[i][2] = mi.getVersion();\r
+ saa[i][4] = mi.getPackageId().getVersion();\r
+ selectedInstancesTableModel.addRow(saa[i]);\r
+ }\r
+ }\r
+ }\r
showClassToResolved();\r
}\r
});\r