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