]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java
1. Fix EDKT339 Library Class Search need to get info for selected library class
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / workspace / WorkspaceTools.java
... / ...
CommitLineData
1/** @file\r
2\r
3 The file is used to init workspace and get basic information of workspace\r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.workspace;\r
16\r
17import java.io.File;\r
18import java.io.IOException;\r
19import java.util.List;\r
20import java.util.Vector;\r
21\r
22import org.apache.xmlbeans.XmlCursor;\r
23import org.apache.xmlbeans.XmlException;\r
24import org.tianocore.DbPathAndFilename;\r
25import org.tianocore.IndustryStdIncludesDocument.IndustryStdIncludes;\r
26import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r
27import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions;\r
28import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
29import org.tianocore.MsaFilesDocument.MsaFiles;\r
30import org.tianocore.PackageDependenciesDocument.PackageDependencies;\r
31import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
32import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
33import org.tianocore.SourceFilesDocument.SourceFiles;\r
34import org.tianocore.frameworkwizard.common.DataType;\r
35import org.tianocore.frameworkwizard.common.GlobalData;\r
36import org.tianocore.frameworkwizard.common.Log;\r
37import org.tianocore.frameworkwizard.common.OpenFile;\r
38import org.tianocore.frameworkwizard.common.SaveFile;\r
39import org.tianocore.frameworkwizard.common.Sort;\r
40import org.tianocore.frameworkwizard.common.Tools;\r
41import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
42import org.tianocore.frameworkwizard.far.FarHeader;\r
43import org.tianocore.frameworkwizard.far.FarIdentification;\r
44import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
45import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdIdentification;\r
46import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;\r
47import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
48import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
49\r
50public class WorkspaceTools {\r
51\r
52 public void addFarToDb(List<String> packageList, List<String> platformList, FarHeader far) {\r
53 //FrameworkDatabase fdb = openFrameworkDb();\r
54\r
55 for (int i = 0; i < packageList.size(); i++) {\r
56 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();\r
57 item.setFarGuid(far.getGuidValue());\r
58 item.setStringValue(packageList.get(i));\r
59 GlobalData.fdb.getPackageList().getFilenameList().add(item);\r
60 }\r
61\r
62 for (int i = 0; i < platformList.size(); i++) {\r
63 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();\r
64 item.setFarGuid(far.getGuidValue());\r
65 item.setStringValue(platformList.get(i));\r
66 GlobalData.fdb.getPlatformList().getFilenameList().add(item);\r
67 }\r
68\r
69 DbPathAndFilename farItem = DbPathAndFilename.Factory.newInstance();\r
70 farItem.setFarGuid(far.getGuidValue());\r
71 farItem.setStringValue(far.getFarName());\r
72 GlobalData.fdb.getFarList().getFilenameList().add(farItem);\r
73\r
74 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
75 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
76\r
77 try {\r
78 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
79 } catch (Exception e) {\r
80 Log.err("Save Database File", e.getMessage());\r
81 }\r
82 }\r
83\r
84 public void removeFarFromDb(FarIdentification far) {\r
85 //\r
86 // Remove Packages\r
87 //\r
88 XmlCursor cursor = GlobalData.fdb.getPackageList().newCursor();\r
89 cursor.toFirstChild();\r
90 do {\r
91 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();\r
92\r
93 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
94 cursor.removeXml();\r
95 }\r
96 } while (cursor.toNextSibling());\r
97 cursor.dispose();\r
98\r
99 //\r
100 // Remove Platforms\r
101 //\r
102 cursor = GlobalData.fdb.getPlatformList().newCursor();\r
103 cursor.toFirstChild();\r
104 do {\r
105 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();\r
106 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
107 cursor.removeXml();\r
108 }\r
109 } while (cursor.toNextSibling());\r
110\r
111 //\r
112 // Remove Far\r
113 //\r
114 cursor = GlobalData.fdb.getFarList().newCursor();\r
115 cursor.toFirstChild();\r
116 do {\r
117 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();\r
118 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
119 cursor.removeXml();\r
120 }\r
121 } while (cursor.toNextSibling());\r
122 cursor.dispose();\r
123\r
124 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
125 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
126 try {\r
127 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
128 } catch (Exception e) {\r
129 Log.err("Save Database File", e.getMessage());\r
130 }\r
131 }\r
132\r
133 public String getPackageFarGuid(Identification packageId) {\r
134 for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {\r
135 DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);\r
136 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
137 File tempFile = new File(path);\r
138 if (tempFile.getPath().equalsIgnoreCase(packageId.getPath())) {\r
139 return GlobalData.fdb.getPackageList().getFilenameArray(index).getFarGuid();\r
140 }\r
141 }\r
142\r
143 return null;\r
144 }\r
145\r
146 public String getPlatformFarGuid(Identification platformId) {\r
147 for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {\r
148 DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);\r
149 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
150 File tempFile = new File(path);\r
151 if (tempFile.getPath().equalsIgnoreCase(platformId.getPath())) {\r
152 return GlobalData.fdb.getPlatformList().getFilenameArray(index).getFarGuid();\r
153 }\r
154 }\r
155\r
156 return null;\r
157 }\r
158\r
159 public String getModuleFarGuid(Identification moduleId) {\r
160 PackageIdentification packageId = getPackageIdByModuleId(moduleId);\r
161 if (packageId != null) {\r
162 return getPackageFarGuid(packageId);\r
163 } else {\r
164 return null;\r
165 }\r
166 }\r
167\r
168 /**\r
169 Get all modules' paths from one package\r
170 \r
171 @return a Vector with all modules' path\r
172 \r
173 **/\r
174 public Vector<String> getAllModulesOfPackage(String path) {\r
175 Vector<String> modulePath = new Vector<String>();\r
176 PackageIdentification id = new PackageIdentification(null, null, null, path);\r
177 MsaFiles files = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(id).getMsaFiles();\r
178 if (files != null) {\r
179 for (int index = 0; index < files.getFilenameList().size(); index++) {\r
180 String msaPath = files.getFilenameList().get(index);\r
181 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;\r
182 msaPath = Tools.convertPathToCurrentOsType(msaPath);\r
183 modulePath.addElement(msaPath);\r
184 }\r
185 }\r
186\r
187 return modulePath;\r
188 }\r
189\r
190 /**\r
191 Get all Industry Std Includes' paths from one package\r
192 \r
193 @return a Vector with all paths\r
194 \r
195 **/\r
196 public Vector<String> getAllIndustryStdIncludesOfPackage(String path) {\r
197 Vector<String> includePath = new Vector<String>();\r
198 PackageIdentification id = new PackageIdentification(null, null, null, path);\r
199 IndustryStdIncludes files = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(id)\r
200 .getIndustryStdIncludes();\r
201 if (files != null) {\r
202 for (int index = 0; index < files.getIndustryStdHeaderList().size(); index++) {\r
203 String temp = files.getIndustryStdHeaderList().get(index).getIncludeHeader();\r
204 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;\r
205 temp = Tools.convertPathToCurrentOsType(temp);\r
206 includePath.addElement(temp);\r
207 }\r
208 }\r
209 return includePath;\r
210 }\r
211\r
212 /**\r
213 Get all package basic information form the FrameworkDatabase.db file\r
214 \r
215 @return vPackageList A vector includes all packages' basic information\r
216 \r
217 */\r
218 public Vector<PackageIdentification> getAllPackages() {\r
219 return GlobalData.vPackageList;\r
220 }\r
221\r
222 public Vector<FarIdentification> getAllFars() {\r
223\r
224 Vector<FarIdentification> v = new Vector<FarIdentification>();\r
225 for (int index = 0; index < GlobalData.fdb.getFarList().getFilenameList().size(); index++) {\r
226 DbPathAndFilename item = GlobalData.fdb.getFarList().getFilenameList().get(index);\r
227 FarIdentification far = new FarIdentification(item.getFarGuid(), item.getMd5Sum(), item.getStringValue());\r
228 v.addElement(far);\r
229 }\r
230 return v;\r
231 }\r
232\r
233 public Vector<PackageIdentification> getPackagesByFar(FarIdentification far) {\r
234 Identification id = null;\r
235\r
236 Vector<PackageIdentification> v = new Vector<PackageIdentification>();\r
237\r
238 for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {\r
239 DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);\r
240 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
241 path = Tools.convertPathToCurrentOsType(path);\r
242\r
243 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
244\r
245 try {\r
246 id = Tools.getId(path, OpenFile.openSpdFile(path));\r
247 v.addElement(new PackageIdentification(id));\r
248 } catch (IOException e) {\r
249 Log.err("Open Package Surface Area " + path, e.getMessage());\r
250 } catch (XmlException e) {\r
251 Log.err("Open Package Surface Area " + path, e.getMessage());\r
252 } catch (Exception e) {\r
253 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
254 }\r
255 }\r
256 }\r
257 return v;\r
258 }\r
259\r
260 public Vector<PlatformIdentification> getPlatformsByFar(FarIdentification far) {\r
261 Identification id = null;\r
262\r
263 Vector<PlatformIdentification> v = new Vector<PlatformIdentification>();\r
264\r
265 for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {\r
266 DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);\r
267 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
268 path = Tools.convertPathToCurrentOsType(path);\r
269\r
270 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
271 try {\r
272 id = Tools.getId(path, OpenFile.openFpdFile(path));\r
273 v.addElement(new PlatformIdentification(id));\r
274 } catch (IOException e) {\r
275 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
276 } catch (XmlException e) {\r
277 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
278 } catch (Exception e) {\r
279 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
280 }\r
281 }\r
282 }\r
283 return v;\r
284 }\r
285\r
286 /**\r
287 Get all module basic information from a package\r
288 \r
289 @param id Package id\r
290 @return A vector includes all modules' basic information\r
291 \r
292 **/\r
293 public Vector<ModuleIdentification> getAllModules(PackageIdentification pid) {\r
294 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();\r
295 Vector<String> modulePaths = this.getAllModulesOfPackage(pid.getPath());\r
296 String modulePath = null;\r
297\r
298 for (int index = 0; index < modulePaths.size(); index++) {\r
299 modulePath = modulePaths.get(index);\r
300 ModuleIdentification id = GlobalData.openingModuleList.getIdByPath(modulePath);\r
301 if (id != null) {\r
302 v.addElement(id);\r
303 }\r
304 }\r
305 Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);\r
306 return v;\r
307 }\r
308\r
309 /**\r
310 Get all module basic information from a platform\r
311 \r
312 @param id Package id\r
313 @return A vector includes all modules' basic information\r
314 \r
315 **/\r
316 public Vector<ModuleIdentification> getAllModules(PlatformIdentification fid) {\r
317 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();\r
318 PlatformSurfaceArea fpd = GlobalData.openingPlatformList.getOpeningPlatformById(fid).getXmlFpd();\r
319 if (fpd.getFrameworkModules() != null) {\r
320 for (int index = 0; index < fpd.getFrameworkModules().getModuleSAList().size(); index++) {\r
321 String guid = fpd.getFrameworkModules().getModuleSAList().get(index).getModuleGuid();\r
322 String version = fpd.getFrameworkModules().getModuleSAList().get(index).getModuleVersion();\r
323 ModuleIdentification id = GlobalData.openingModuleList.getIdByGuidVersion(guid, version);\r
324 if (id != null) {\r
325 boolean isFind = false;\r
326 for (int indexOfModules = 0; indexOfModules < v.size(); indexOfModules++) {\r
327 if (v.elementAt(indexOfModules).equals(id)) {\r
328 isFind = true;\r
329 break;\r
330 }\r
331 }\r
332 if (!isFind) {\r
333 v.addElement(id);\r
334 }\r
335 }\r
336 }\r
337 }\r
338 Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);\r
339 return v;\r
340 }\r
341\r
342 /**\r
343 Get all module basic information form the FrameworkDatabase.db file\r
344 \r
345 @return vModuleList A vector includes all modules' basic information\r
346 \r
347 */\r
348 public Vector<ModuleIdentification> getAllModules() {\r
349 return GlobalData.vModuleList;\r
350 }\r
351\r
352 /**\r
353 Get all platform basic information form the FrameworkDatabase.db file\r
354 \r
355 @return vplatformList A vector includes all platforms' basic information\r
356 \r
357 */\r
358 public Vector<PlatformIdentification> getAllPlatforms() {\r
359 return GlobalData.vPlatformList;\r
360 }\r
361\r
362 /**\r
363 Get all Library Class Definitions from a package\r
364 \r
365 @return Vector\r
366 **/\r
367 public Vector<String> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd) {\r
368 Vector<String> vector = new Vector<String>();\r
369 if (spd.getLibraryClassDeclarations() != null) {\r
370 if (spd.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {\r
371 for (int index = 0; index < spd.getLibraryClassDeclarations().getLibraryClassList().size(); index++) {\r
372 vector.addElement(spd.getLibraryClassDeclarations().getLibraryClassList().get(index).getName());\r
373 }\r
374 }\r
375 }\r
376 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
377 return vector;\r
378 }\r
379\r
380 /**\r
381 Get all Protocol Definitions from a package\r
382 \r
383 @return Vector\r
384 **/\r
385 public Vector<String> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd) {\r
386 Vector<String> vector = new Vector<String>();\r
387 if (spd.getProtocolDeclarations() != null) {\r
388 if (spd.getProtocolDeclarations().getEntryList().size() > 0) {\r
389 for (int index = 0; index < spd.getProtocolDeclarations().getEntryList().size(); index++) {\r
390 vector.addElement(spd.getProtocolDeclarations().getEntryList().get(index).getCName());\r
391 }\r
392 }\r
393 }\r
394 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
395 return vector;\r
396 }\r
397\r
398 /**\r
399 Get all Ppi Definitions from a package\r
400 \r
401 @return Vector\r
402 **/\r
403 public Vector<String> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd) {\r
404 Vector<String> vector = new Vector<String>();\r
405 if (spd.getPpiDeclarations() != null) {\r
406 if (spd.getPpiDeclarations().getEntryList().size() > 0) {\r
407 for (int index = 0; index < spd.getPpiDeclarations().getEntryList().size(); index++) {\r
408 vector.addElement(spd.getPpiDeclarations().getEntryList().get(index).getCName());\r
409 }\r
410 }\r
411 }\r
412 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
413 return vector;\r
414 }\r
415\r
416 /**\r
417 Get all Guid Definitions from a package\r
418 \r
419 @return Vector\r
420 **/\r
421 public Vector<String> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd, String type) {\r
422 Vector<String> vector = new Vector<String>();\r
423 boolean isFound = false;\r
424 if (spd.getGuidDeclarations() != null) {\r
425 if (spd.getGuidDeclarations().getEntryList().size() > 0) {\r
426 for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) {\r
427 Vector<String> vArch = Tools.convertListToVector(spd.getGuidDeclarations().getEntryList()\r
428 .get(index).getGuidTypeList());\r
429 for (int indexOfArch = 0; indexOfArch < vArch.size(); indexOfArch++) {\r
430 if (vArch.get(indexOfArch).equals(type)) {\r
431 isFound = true;\r
432 break;\r
433 }\r
434 }\r
435 if ((isFound) || (vArch == null) || (vArch.size() < 1)) {\r
436 vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName());\r
437 isFound = false;\r
438 }\r
439 }\r
440 }\r
441 }\r
442 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
443 return vector;\r
444 }\r
445\r
446 /**\r
447 Get all Pcd Definitions from a package\r
448 \r
449 @return Vector\r
450 **/\r
451 public PcdVector getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {\r
452 PcdVector vector = new PcdVector();\r
453 if (spd.getPcdDeclarations() != null) {\r
454 if (spd.getPcdDeclarations().getPcdEntryList().size() > 0) {\r
455 for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) {\r
456 String name = spd.getPcdDeclarations().getPcdEntryList().get(index).getCName();\r
457 String guidCName = spd.getPcdDeclarations().getPcdEntryList().get(index).getTokenSpaceGuidCName();\r
458 String help = spd.getPcdDeclarations().getPcdEntryList().get(index).getHelpText();\r
459 Vector<String> type = Tools.convertListToVector(spd.getPcdDeclarations().getPcdEntryList()\r
460 .get(index).getValidUsage());\r
461 //\r
462 // The algorithm for PCD of msa should be:\r
463 // 1. If the type of PCD from Spd is FEATURE_FLAG, \r
464 // the type of Msa only can be FEATURE_FLAG.\r
465 // 2. If the type of PCD from Spd is not FEATURE_FLAG, \r
466 // the type of Msa could be selected from the PCD's all types and "DYNAMIC" type.\r
467 //\r
468 boolean hasFEATURE_FLAG = false;\r
469 boolean hasDYNAMIC = false;\r
470 for (int indexOfType = 0; indexOfType < type.size(); indexOfType++) {\r
471 if (type.elementAt(indexOfType).equals(DataType.PCD_ITEM_TYPE_DYNAMIC)) {\r
472 hasDYNAMIC = true;\r
473 }\r
474 if (type.elementAt(indexOfType).equals(DataType.PCD_ITEM_TYPE_FEATURE_FLAG)) {\r
475 hasFEATURE_FLAG = true;\r
476 }\r
477 }\r
478 if (hasFEATURE_FLAG) {\r
479 type.removeAllElements();\r
480 type.addElement(DataType.PCD_ITEM_TYPE_FEATURE_FLAG);\r
481 } else {\r
482 if (!hasDYNAMIC) {\r
483 type.addElement(DataType.PCD_ITEM_TYPE_DYNAMIC);\r
484 }\r
485 }\r
486 vector.addPcd(new PcdIdentification(name, guidCName, help, type));\r
487 }\r
488 }\r
489 }\r
490 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
491 return vector;\r
492 }\r
493\r
494 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {\r
495 Vector<String> vector = new Vector<String>();\r
496 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
497 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList\r
498 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
499 .get(index)));\r
500 if (v != null && v.size() > 0) {\r
501 vector.addAll(v);\r
502 }\r
503\r
504 }\r
505 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
506 return vector;\r
507 }\r
508\r
509 public Vector<String> getAllLibraryClassDefinitionsFromPackages(Vector<PackageIdentification> vpid) {\r
510 Vector<String> vector = new Vector<String>();\r
511 for (int index = 0; index < vpid.size(); index++) {\r
512 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList\r
513 .getPackageSurfaceAreaFromId(vpid\r
514 .get(index)));\r
515 if (v != null && v.size() > 0) {\r
516 vector.addAll(v);\r
517 }\r
518\r
519 }\r
520 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
521 return vector;\r
522 }\r
523\r
524 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {\r
525 Vector<String> vector = new Vector<String>();\r
526 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
527 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList\r
528 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
529 .get(index)));\r
530 if (v != null && v.size() > 0) {\r
531 vector.addAll(v);\r
532 }\r
533 }\r
534 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
535 return vector;\r
536 }\r
537\r
538 public Vector<String> getAllProtocolDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
539 Vector<String> vector = new Vector<String>();\r
540 for (int index = 0; index < vpid.size(); index++) {\r
541 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList\r
542 .getPackageSurfaceAreaFromId(vpid\r
543 .get(index)));\r
544 if (v != null && v.size() > 0) {\r
545 vector.addAll(v);\r
546 }\r
547 }\r
548 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
549 return vector;\r
550 }\r
551\r
552 public Vector<String> getAllPpiDeclarationsFromWorkspace() {\r
553 Vector<String> vector = new Vector<String>();\r
554 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
555 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList\r
556 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
557 .get(index)));\r
558 if (v != null && v.size() > 0) {\r
559 vector.addAll(v);\r
560 }\r
561 }\r
562 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
563 return vector;\r
564 }\r
565\r
566 public Vector<String> getAllPpiDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
567 Vector<String> vector = new Vector<String>();\r
568 for (int index = 0; index < vpid.size(); index++) {\r
569 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList\r
570 .getPackageSurfaceAreaFromId(vpid\r
571 .get(index)));\r
572 if (v != null && v.size() > 0) {\r
573 vector.addAll(v);\r
574 }\r
575 }\r
576 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
577 return vector;\r
578 }\r
579\r
580 public Vector<String> getAllGuidDeclarationsFromWorkspace(String type) {\r
581 Vector<String> vector = new Vector<String>();\r
582 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
583 Vector<String> v = getAllGuidDeclarationsFromPackage(\r
584 GlobalData.openingPackageList\r
585 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
586 .get(index)),\r
587 type);\r
588 if (v != null && v.size() > 0) {\r
589 vector.addAll(v);\r
590 }\r
591\r
592 }\r
593 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
594 return vector;\r
595 }\r
596\r
597 public Vector<String> getAllGuidDeclarationsFromPackages(Vector<PackageIdentification> vpid, String type) {\r
598 Vector<String> vector = new Vector<String>();\r
599 for (int index = 0; index < vpid.size(); index++) {\r
600 Vector<String> v = getAllGuidDeclarationsFromPackage(\r
601 GlobalData.openingPackageList\r
602 .getPackageSurfaceAreaFromId(vpid\r
603 .get(index)),\r
604 type);\r
605 if (v != null && v.size() > 0) {\r
606 vector.addAll(v);\r
607 }\r
608\r
609 }\r
610 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
611 return vector;\r
612 }\r
613\r
614 public PcdVector getAllPcdDeclarationsFromWorkspace() {\r
615 PcdVector vector = new PcdVector();\r
616 for (int index = 0; index < GlobalData.openingPackageList.size(); index++) {\r
617 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList\r
618 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
619 .get(index)));\r
620 if (v != null && v.size() > 0) {\r
621 vector.addAll(v);\r
622 }\r
623\r
624 }\r
625 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
626 return vector;\r
627 }\r
628\r
629 public PcdVector getAllPcdDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
630 PcdVector vector = new PcdVector();\r
631 for (int index = 0; index < vpid.size(); index++) {\r
632 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList\r
633 .getPackageSurfaceAreaFromId(vpid\r
634 .get(index)));\r
635 if (v != null && v.size() > 0) {\r
636 vector.addAll(v);\r
637 }\r
638\r
639 }\r
640 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
641 return vector;\r
642 }\r
643\r
644 /**\r
645 Find a module's package's id\r
646 \r
647 @param id input module id\r
648 @return package id\r
649 \r
650 **/\r
651 public PackageIdentification getPackageIdByModuleId(Identification id) {\r
652 Vector<String> modulePaths = new Vector<String>();\r
653 Identification mid = null;\r
654 String packagePath = null;\r
655 String modulePath = null;\r
656\r
657 //\r
658 // For each package, get all modules list\r
659 //\r
660 for (int indexI = 0; indexI < GlobalData.vPackageList.size(); indexI++) {\r
661 packagePath = GlobalData.vPackageList.elementAt(indexI).getPath();\r
662 modulePaths = this.getAllModulesOfPackage(packagePath);\r
663 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
664 modulePath = modulePaths.get(indexJ);\r
665 mid = GlobalData.openingModuleList.getIdByPath(modulePath);\r
666 //\r
667 // Check id\r
668 //\r
669 if (mid != null) {\r
670 if (mid.equals(id)) {\r
671 return GlobalData.vPackageList.elementAt(indexI);\r
672 }\r
673 }\r
674 }\r
675 }\r
676\r
677 return null;\r
678 }\r
679\r
680 /**\r
681 Add module information to package surface area\r
682 \r
683 @param mid\r
684 @throws IOException\r
685 @throws XmlException\r
686 @throws Exception\r
687 \r
688 **/\r
689 public void addModuleToPackage(ModuleIdentification mid, PackageSurfaceArea spd) throws IOException, XmlException,\r
690 Exception {\r
691 String packagePath = mid.getPackageId().getPath();\r
692 String modulePath = mid.getPath();\r
693 if (spd == null) {\r
694 spd = OpenFile.openSpdFile(packagePath);\r
695 }\r
696 MsaFiles msaFile = spd.getMsaFiles();\r
697 if (msaFile == null) {\r
698 msaFile = MsaFiles.Factory.newInstance();\r
699 }\r
700 packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR));\r
701 String fn = Tools.getRelativePath(modulePath, packagePath);\r
702 msaFile.addNewFilename();\r
703 msaFile.setFilenameArray(msaFile.getFilenameList().size() - 1, fn);\r
704 spd.setMsaFiles(msaFile);\r
705 SaveFile.saveSpdFile(mid.getPackageId().getPath(), spd);\r
706 //\r
707 // Update GlobalData\r
708 //\r
709 GlobalData.openingPackageList.getPackageSurfaceAreaFromId(mid.getPackageId()).setMsaFiles(msaFile);\r
710 }\r
711\r
712 /**\r
713 Add input package into database\r
714 \r
715 @param id\r
716 * @throws Exception \r
717 \r
718 **/\r
719 public void addPackageToDatabase(PackageIdentification id) throws Exception {\r
720 String path = id.getPath();\r
721 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
722\r
723 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
724 filename.setStringValue(path);\r
725 GlobalData.fdb.getPackageList().addNewFilename();\r
726 GlobalData.fdb.getPackageList().setFilenameArray(GlobalData.fdb.getPackageList().sizeOfFilenameArray() - 1,\r
727 filename);\r
728 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
729 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
730 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
731 }\r
732\r
733 /**\r
734 Add input package into database\r
735 \r
736 @param id\r
737 * @throws Exception \r
738 \r
739 **/\r
740 public void addPlatformToDatabase(PlatformIdentification id) throws Exception {\r
741 String path = id.getPath();\r
742 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
743\r
744 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
745 filename.setStringValue(path);\r
746 GlobalData.fdb.getPlatformList().addNewFilename();\r
747 GlobalData.fdb.getPlatformList().setFilenameArray(GlobalData.fdb.getPlatformList().sizeOfFilenameArray() - 1,\r
748 filename);\r
749 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
750 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
751 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
752 }\r
753\r
754 /**\r
755 Get all file's path from one module\r
756 \r
757 @param path\r
758 @return\r
759 @throws IOException\r
760 @throws XmlException\r
761 @throws Exception\r
762 \r
763 **/\r
764 public Vector<String> getAllFilesPathOfModule(String path) {\r
765 Vector<String> v = new Vector<String>();\r
766 path = Tools.convertPathToCurrentOsType(path);\r
767\r
768 //\r
769 // First add msa file's path\r
770 //\r
771 v.addElement(path);\r
772\r
773 ModuleSurfaceArea msa = GlobalData.openingModuleList\r
774 .getModuleSurfaceAreaFromId(GlobalData.openingModuleList\r
775 .getIdByPath(path));\r
776 //\r
777 // Get common defined files of module\r
778 //\r
779 if (msa != null) {\r
780 //\r
781 // Get all files' path of a module\r
782 //\r
783 SourceFiles sf = msa.getSourceFiles();\r
784 if (sf != null) {\r
785 for (int index = 0; index < sf.getFilenameList().size(); index++) {\r
786 String temp = sf.getFilenameList().get(index).getStringValue();\r
787 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;\r
788 v.addElement(Tools.convertPathToCurrentOsType(temp));\r
789 }\r
790 }\r
791 }\r
792\r
793 //\r
794 // Get include header files for this module\r
795 //\r
796 if (msa.getLibraryClassDefinitions() != null) {\r
797 LibraryClassDefinitions lcd = msa.getLibraryClassDefinitions();\r
798 for (int index = 0; index < lcd.sizeOfLibraryClassArray(); index++) {\r
799 if (lcd.getLibraryClassList().get(index).getUsage().toString()\r
800 .equals(DataType.USAGE_TYPE_ALWAYS_PRODUCED)\r
801 || lcd.getLibraryClassList().get(index).getUsage().toString()\r
802 .equals(DataType.USAGE_TYPE_SOMETIMES_PRODUCED)) {\r
803 //\r
804 // Get library class name\r
805 //\r
806 String name = lcd.getLibraryClassList().get(index).getKeyword();\r
807\r
808 //\r
809 // Find file path for this class\r
810 //\r
811 PackageIdentification pid = GlobalData.openingModuleList.getIdByPath(path).getPackageId();\r
812 PackageSurfaceArea spd = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(pid);\r
813 String headerFile = getHeaderFileFromPackageByLibraryClassName(spd, name);\r
814 if (!Tools.isEmpty(headerFile)) {\r
815 v.addElement(Tools.convertPathToCurrentOsType(Tools.getFilePathOnly(pid.getPath())\r
816 + DataType.FILE_SEPARATOR + headerFile));\r
817 }\r
818 }\r
819 }\r
820 }\r
821\r
822 return v;\r
823 }\r
824\r
825 /**\r
826 Get all file's path from one package\r
827 \r
828 @param path\r
829 @return\r
830 @throws IOException\r
831 @throws XmlException\r
832 @throws Exception\r
833 \r
834 **/\r
835 public Vector<String> getAllFilesPathOfPakcage(String path) {\r
836 Vector<String> v = new Vector<String>();\r
837 path = Tools.convertPathToCurrentOsType(path);\r
838 //\r
839 // First add package\r
840 //\r
841 v.addElement(path);\r
842\r
843 //\r
844 // Add the package's industry std includes one by one\r
845 //\r
846 Vector<String> f1 = new Vector<String>();\r
847 f1 = getAllIndustryStdIncludesOfPackage(path);\r
848 for (int index = 0; index < f1.size(); index++) {\r
849 v.addElement(f1.get(index));\r
850 }\r
851\r
852 //\r
853 // Add module's files one by one\r
854 //\r
855 f1 = new Vector<String>();\r
856 f1 = getAllModulesOfPackage(path);\r
857 for (int indexI = 0; indexI < f1.size(); indexI++) {\r
858 Vector<String> f2 = getAllFilesPathOfModule(f1.get(indexI));\r
859 for (int indexJ = 0; indexJ < f2.size(); indexJ++) {\r
860 v.addElement(f2.get(indexJ));\r
861 }\r
862 }\r
863\r
864 return v;\r
865 }\r
866\r
867 /**\r
868 Get a module's all package dependencies\r
869 \r
870 @param mid The module id\r
871 @return A vector of all package dependency ids\r
872 \r
873 **/\r
874 public Vector<PackageIdentification> getPackageDependenciesOfModule(ModuleIdentification mid) {\r
875 Vector<PackageIdentification> vpid = new Vector<PackageIdentification>();\r
876 ModuleSurfaceArea msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(mid);\r
877 if (msa != null) {\r
878 PackageDependencies pd = msa.getPackageDependencies();\r
879 if (pd != null) {\r
880 for (int index = 0; index < pd.getPackageList().size(); index++) {\r
881 String guid = pd.getPackageList().get(index).getPackageGuid();\r
882 String version = pd.getPackageList().get(index).getPackageVersion();\r
883 PackageIdentification pid = GlobalData.openingPackageList.getIdByGuidVersion(guid, version);\r
884 if (pid != null) {\r
885 vpid.addElement(pid);\r
886 }\r
887 }\r
888 }\r
889 }\r
890 return vpid;\r
891 }\r
892\r
893 public Vector<String> getAllModuleGuidXref() {\r
894 Vector<String> v = new Vector<String>();\r
895 for (int index = 0; index < GlobalData.openingModuleList.size(); index++) {\r
896 ModuleIdentification id = GlobalData.openingModuleList.getOpeningModuleByIndex(index).getId();\r
897 v.addElement(id.getGuid() + " " + id.getName());\r
898 }\r
899 return v;\r
900 }\r
901\r
902 public Vector<String> getModuleArch(ModuleIdentification id) {\r
903 Vector<String> v = new Vector<String>();\r
904 ModuleSurfaceArea msa = null;\r
905 if (id != null) {\r
906 msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(id);\r
907 }\r
908 if (msa != null) {\r
909 if (msa.getModuleDefinitions() != null) {\r
910 v = Tools.convertListToVector(msa.getModuleDefinitions().getSupportedArchitectures());\r
911 }\r
912 }\r
913 return v;\r
914 }\r
915\r
916 public String getHeaderFileFromPackageByLibraryClassName(PackageSurfaceArea spd, String name) {\r
917 String headerFile = "";\r
918 if (spd != null) {\r
919 if (spd.getLibraryClassDeclarations() != null) {\r
920 LibraryClassDeclarations lcdl = spd.getLibraryClassDeclarations();\r
921 for (int indexOfLibOfSpd = 0; indexOfLibOfSpd < lcdl.sizeOfLibraryClassArray(); indexOfLibOfSpd++) {\r
922 if (lcdl.getLibraryClassList().get(indexOfLibOfSpd).getName().equals(name)) {\r
923 return lcdl.getLibraryClassList().get(indexOfLibOfSpd).getIncludeHeader();\r
924 }\r
925 }\r
926 }\r
927 }\r
928\r
929 return headerFile;\r
930 }\r
931}\r