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