]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java
1. Enhance Source Files selection in msa:
[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
2003a22e 38import org.tianocore.frameworkwizard.common.Sort;\r
a13899c5 39import org.tianocore.frameworkwizard.common.Tools;\r
79cb6fdb 40import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
41import org.tianocore.frameworkwizard.common.Identifications.OpenFile;\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
110 e.printStackTrace();\r
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
160 e.printStackTrace();\r
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
92e29378 222\r
a13899c5 223 } catch (XmlException e) {\r
92e29378 224\r
a13899c5 225 } catch (Exception e) {\r
92e29378 226\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
250\r
251 } catch (XmlException e) {\r
252\r
253 } catch (Exception e) {\r
254\r
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
92e29378 280\r
a13899c5 281 } catch (XmlException e) {\r
282 Log.err("Open Package Surface Area " + path, e.getMessage());\r
92e29378 283\r
a13899c5 284 } catch (Exception e) {\r
285 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
92e29378 286\r
a13899c5 287 }\r
288 }\r
2003a22e 289 Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 290 return vPackageList;\r
291 }\r
5a24e806 292\r
293 public Vector<FarIdentification> getAllFars() {\r
55a2762d 294 openFrameworkDb();\r
295 Vector<FarIdentification> v = new Vector<FarIdentification>();\r
296 for (int index = 0; index < fdb.getFarList().getFilenameList().size(); index++) {\r
297 DbPathAndFilename item = fdb.getFarList().getFilenameList().get(index);\r
298 FarIdentification far = new FarIdentification(item.getFarGuid(), item.getMd5Sum(), item.getStringValue());\r
299 v.addElement(far);\r
300 }\r
301 return v;\r
302 }\r
303\r
5a24e806 304 public Vector<PackageIdentification> getPackagesByFar(FarIdentification far) {\r
55a2762d 305 Identification id = null;\r
306 openFrameworkDb();\r
307 Vector<PackageIdentification> v = new Vector<PackageIdentification>();\r
308\r
309 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
310 DbPathAndFilename item = fdb.getPackageList().getFilenameArray(index);\r
311 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
312 path = Tools.convertPathToCurrentOsType(path);\r
313\r
314 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
315\r
316 try {\r
317 id = getId(path, OpenFile.openSpdFile(path));\r
318 v.addElement(new PackageIdentification(id));\r
319 } catch (IOException e) {\r
320 Log.err("Open Package Surface Area " + path, e.getMessage());\r
321 e.printStackTrace();\r
322 } catch (XmlException e) {\r
323 Log.err("Open Package Surface Area " + path, e.getMessage());\r
324 e.printStackTrace();\r
325 } catch (Exception e) {\r
326 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
327 e.printStackTrace();\r
328 }\r
329 }\r
5a24e806 330 }\r
55a2762d 331 return v;\r
5a24e806 332 }\r
55a2762d 333\r
5a24e806 334 public Vector<PlatformIdentification> getPlatformsByFar(FarIdentification far) {\r
55a2762d 335 Identification id = null;\r
336 openFrameworkDb();\r
337 Vector<PlatformIdentification> v = new Vector<PlatformIdentification>();\r
338\r
339 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
340 DbPathAndFilename item = fdb.getPlatformList().getFilenameArray(index);\r
341 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();\r
342 path = Tools.convertPathToCurrentOsType(path);\r
343\r
344 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
345 try {\r
346 id = getId(path, OpenFile.openFpdFile(path));\r
347 v.addElement(new PlatformIdentification(id));\r
348 } catch (IOException e) {\r
349 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
350 e.printStackTrace();\r
351 } catch (XmlException e) {\r
352 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
353 e.printStackTrace();\r
354 } catch (Exception e) {\r
355 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
356 e.printStackTrace();\r
357 }\r
358 }\r
5a24e806 359 }\r
55a2762d 360 return v;\r
5a24e806 361 }\r
362\r
92e29378 363 /**\r
364 Get all module basic information from a package\r
55a2762d 365 \r
92e29378 366 @param id Package id\r
367 @return A vector includes all modules' basic information\r
55a2762d 368 \r
369 **/\r
92e29378 370 public Vector<ModuleIdentification> getAllModules(PackageIdentification pid) {\r
371 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();\r
372 Vector<String> modulePaths = this.getAllModulesOfPackage(pid.getPath());\r
373 Identification id = null;\r
374 String modulePath = null;\r
55a2762d 375\r
92e29378 376 for (int index = 0; index < modulePaths.size(); index++) {\r
377 try {\r
378 modulePath = modulePaths.get(index);\r
379 id = getId(modulePath, OpenFile.openMsaFile(modulePath));\r
380 } catch (IOException e) {\r
381 Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage());\r
382 } catch (XmlException e) {\r
383 Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage());\r
384 } catch (Exception e) {\r
385 Log.log("Error when Open Module Surface Area " + modulePath, "Invalid file type " + e.getMessage());\r
386 }\r
387 v.addElement(new ModuleIdentification(id, pid));\r
388 }\r
2003a22e 389 Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);\r
92e29378 390 return v;\r
55a2762d 391\r
92e29378 392 }\r
a13899c5 393\r
394 /**\r
92e29378 395 Get all module basic information form the FrameworkDatabase.db file\r
a13899c5 396 \r
92e29378 397 @return vModuleList A vector includes all modules' basic information\r
a13899c5 398 \r
399 */\r
400 public Vector<ModuleIdentification> getAllModules() {\r
401 vModuleList.removeAllElements();\r
402 //\r
403 // First get all packages\r
404 //\r
405 getAllPackages();\r
406 Vector<String> modulePaths = new Vector<String>();\r
407 Identification id = null;\r
408 String packagePath = null;\r
409 String modulePath = null;\r
410\r
411 //\r
412 // For each package, get all modules list\r
413 //\r
414 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {\r
415 packagePath = vPackageList.elementAt(indexI).getPath();\r
416 modulePaths = this.getAllModulesOfPackage(packagePath);\r
55a2762d 417\r
a13899c5 418 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
a13899c5 419 try {\r
79cb6fdb 420 modulePath = modulePaths.get(indexJ);\r
a13899c5 421 id = getId(modulePath, OpenFile.openMsaFile(modulePath));\r
422 vModuleList.addElement(new ModuleIdentification(id, vPackageList.elementAt(indexI)));\r
423 } catch (IOException e) {\r
424 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
a13899c5 425 } catch (XmlException e) {\r
426 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
a13899c5 427 } catch (Exception e) {\r
428 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r
a13899c5 429 }\r
430 }\r
431 }\r
2003a22e 432 Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 433 return vModuleList;\r
434 }\r
435\r
436 /**\r
437 Get all platform basic information form the FrameworkDatabase.db file\r
438 \r
439 @return vplatformList A vector includes all platforms' basic information\r
440 \r
441 */\r
442 public Vector<PlatformIdentification> getAllPlatforms() {\r
443 Identification id = null;\r
444 vPlatformList.removeAllElements();\r
445\r
446 openFrameworkDb();\r
447\r
448 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
449 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
450 + fdb.getPlatformList().getFilenameArray(index).getStringValue();\r
451 path = Tools.convertPathToCurrentOsType(path);\r
452 try {\r
453 id = getId(path, OpenFile.openFpdFile(path));\r
454 vPlatformList.addElement(new PlatformIdentification(id));\r
455 } catch (IOException e) {\r
456 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
a13899c5 457 } catch (XmlException e) {\r
458 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
a13899c5 459 } catch (Exception e) {\r
460 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
a13899c5 461 }\r
462 }\r
2003a22e 463 Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 464 return vPlatformList;\r
465 }\r
466\r
467 /**\r
468 Get all Library Class Definitions from a package\r
469 \r
470 @return Vector\r
471 **/\r
472 public Vector<String> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd) {\r
473 Vector<String> vector = new Vector<String>();\r
474 if (spd.getLibraryClassDeclarations() != null) {\r
475 if (spd.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {\r
476 for (int index = 0; index < spd.getLibraryClassDeclarations().getLibraryClassList().size(); index++) {\r
477 vector.addElement(spd.getLibraryClassDeclarations().getLibraryClassList().get(index).getName());\r
478 }\r
479 }\r
480 }\r
2003a22e 481 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 482 return vector;\r
483 }\r
484\r
485 /**\r
486 Get all Protocol Definitions from a package\r
487 \r
488 @return Vector\r
489 **/\r
490 public Vector<String> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd) {\r
491 Vector<String> vector = new Vector<String>();\r
492 if (spd.getProtocolDeclarations() != null) {\r
493 if (spd.getProtocolDeclarations().getEntryList().size() > 0) {\r
494 for (int index = 0; index < spd.getProtocolDeclarations().getEntryList().size(); index++) {\r
495 vector.addElement(spd.getProtocolDeclarations().getEntryList().get(index).getCName());\r
496 }\r
497 }\r
498 }\r
2003a22e 499 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 500 return vector;\r
501 }\r
502\r
503 /**\r
504 Get all Ppi Definitions from a package\r
505 \r
506 @return Vector\r
507 **/\r
508 public Vector<String> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd) {\r
509 Vector<String> vector = new Vector<String>();\r
510 if (spd.getPpiDeclarations() != null) {\r
511 if (spd.getPpiDeclarations().getEntryList().size() > 0) {\r
512 for (int index = 0; index < spd.getPpiDeclarations().getEntryList().size(); index++) {\r
513 vector.addElement(spd.getPpiDeclarations().getEntryList().get(index).getCName());\r
514 }\r
79cb6fdb 515 }\r
a13899c5 516 }\r
2003a22e 517 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 518 return vector;\r
519 }\r
520\r
521 /**\r
522 Get all Guid Definitions from a package\r
523 \r
524 @return Vector\r
525 **/\r
526 public Vector<String> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd) {\r
527 Vector<String> vector = new Vector<String>();\r
528 if (spd.getGuidDeclarations() != null) {\r
529 if (spd.getGuidDeclarations().getEntryList().size() > 0) {\r
530 for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) {\r
531 vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName());\r
532 }\r
79cb6fdb 533 }\r
a13899c5 534 }\r
2003a22e 535 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 536 return vector;\r
537 }\r
538\r
539 /**\r
540 Get all Pcd Definitions from a package\r
541 \r
542 @return Vector\r
543 **/\r
9a8d6d9f 544 public PcdVector getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {\r
545 PcdVector vector = new PcdVector();\r
a13899c5 546 if (spd.getPcdDeclarations() != null) {\r
547 if (spd.getPcdDeclarations().getPcdEntryList().size() > 0) {\r
548 for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) {\r
9a8d6d9f 549 String name = spd.getPcdDeclarations().getPcdEntryList().get(index).getCName();\r
550 String guidCName = spd.getPcdDeclarations().getPcdEntryList().get(index).getTokenSpaceGuidCName();\r
551 String help = spd.getPcdDeclarations().getPcdEntryList().get(index).getHelpText();\r
552 Vector<String> type = Tools.convertListToVector(spd.getPcdDeclarations().getPcdEntryList()\r
553 .get(index).getValidUsage());\r
554\r
555 vector.addPcd(new PcdIdentification(name, guidCName, help, type));\r
a13899c5 556 }\r
79cb6fdb 557 }\r
a13899c5 558 }\r
2003a22e 559 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 560 return vector;\r
561 }\r
562\r
563 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {\r
564 //\r
565 // First get all packages\r
566 //\r
567 this.getAllPackages();\r
568\r
569 Vector<String> vector = new Vector<String>();\r
570 for (int index = 0; index < this.vPackageList.size(); index++) {\r
571 try {\r
572 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(OpenFile\r
573 .openSpdFile(vPackageList\r
574 .get(index)\r
575 .getPath()));\r
576 if (v != null && v.size() > 0) {\r
577 vector.addAll(v);\r
578 }\r
579 } catch (IOException e) {\r
580 // TODO Auto-generated catch block\r
a13899c5 581 } catch (XmlException e) {\r
582 // TODO Auto-generated catch block\r
a13899c5 583 } catch (Exception e) {\r
584 // TODO Auto-generated catch block\r
a13899c5 585 }\r
586 }\r
2003a22e 587 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 588 return vector;\r
589 }\r
590\r
591 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {\r
592 //\r
593 // First get all packages\r
594 //\r
595 this.getAllPackages();\r
596\r
597 Vector<String> vector = new Vector<String>();\r
598 for (int index = 0; index < this.vPackageList.size(); index++) {\r
599 try {\r
600 Vector<String> v = getAllProtocolDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
601 .getPath()));\r
602 if (v != null && v.size() > 0) {\r
603 vector.addAll(v);\r
604 }\r
605 } catch (IOException e) {\r
606 // TODO Auto-generated catch block\r
a13899c5 607 } catch (XmlException e) {\r
608 // TODO Auto-generated catch block\r
a13899c5 609 } catch (Exception e) {\r
610 // TODO Auto-generated catch block\r
a13899c5 611 }\r
612 }\r
2003a22e 613 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 614 return vector;\r
615 }\r
616\r
617 public Vector<String> getAllPpiDeclarationsFromWorkspace() {\r
618 //\r
619 // First get all packages\r
620 //\r
621 this.getAllPackages();\r
622\r
623 Vector<String> vector = new Vector<String>();\r
624 for (int index = 0; index < this.vPackageList.size(); index++) {\r
625 try {\r
626 Vector<String> v = getAllPpiDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
627 .getPath()));\r
628 if (v != null && v.size() > 0) {\r
629 vector.addAll(v);\r
630 }\r
631 } catch (IOException e) {\r
632 // TODO Auto-generated catch block\r
a13899c5 633 } catch (XmlException e) {\r
634 // TODO Auto-generated catch block\r
a13899c5 635 } catch (Exception e) {\r
636 // TODO Auto-generated catch block\r
a13899c5 637 }\r
638 }\r
2003a22e 639 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 640 return vector;\r
641 }\r
642\r
643 public Vector<String> getAllGuidDeclarationsFromWorkspace() {\r
644 //\r
645 // First get all packages\r
646 //\r
647 this.getAllPackages();\r
648\r
649 Vector<String> vector = new Vector<String>();\r
650 for (int index = 0; index < this.vPackageList.size(); index++) {\r
651 try {\r
652 Vector<String> v = getAllGuidDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
653 .getPath()));\r
654 if (v != null && v.size() > 0) {\r
655 vector.addAll(v);\r
656 }\r
657 } catch (IOException e) {\r
658 // TODO Auto-generated catch block\r
a13899c5 659 } catch (XmlException e) {\r
660 // TODO Auto-generated catch block\r
a13899c5 661 } catch (Exception e) {\r
662 // TODO Auto-generated catch block\r
a13899c5 663 }\r
664 }\r
2003a22e 665 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 666 return vector;\r
667 }\r
668\r
9a8d6d9f 669 public PcdVector getAllPcdDeclarationsFromWorkspace() {\r
a13899c5 670 //\r
671 // First get all packages\r
672 //\r
673 this.getAllPackages();\r
674\r
9a8d6d9f 675 PcdVector vector = new PcdVector();\r
a13899c5 676 for (int index = 0; index < this.vPackageList.size(); index++) {\r
677 try {\r
9a8d6d9f 678 PcdVector v = getAllPcdDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index).getPath()));\r
a13899c5 679 if (v != null && v.size() > 0) {\r
680 vector.addAll(v);\r
681 }\r
682 } catch (IOException e) {\r
683 // TODO Auto-generated catch block\r
a13899c5 684 } catch (XmlException e) {\r
685 // TODO Auto-generated catch block\r
a13899c5 686 } catch (Exception e) {\r
687 // TODO Auto-generated catch block\r
a13899c5 688 }\r
689 }\r
2003a22e 690 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 691 return vector;\r
692 }\r
693\r
694 /**\r
695 Find a module's package's id\r
696 \r
697 @param id input module id\r
698 @return package id\r
699 \r
700 **/\r
701 public PackageIdentification getPackageIdByModuleId(Identification id) {\r
702 getAllPackages();\r
703 Vector<String> modulePaths = new Vector<String>();\r
704 Identification mid = null;\r
705 String packagePath = null;\r
706 String modulePath = null;\r
707\r
708 //\r
709 // For each package, get all modules list\r
710 //\r
711 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {\r
712 packagePath = vPackageList.elementAt(indexI).getPath();\r
713 modulePaths = this.getAllModulesOfPackage(packagePath);\r
a13899c5 714 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
79cb6fdb 715 modulePath = modulePaths.get(indexJ);\r
a13899c5 716 try {\r
717 mid = getId(modulePath, OpenFile.openMsaFile(modulePath));\r
718 //\r
719 // Check id\r
720 //\r
721 if (mid.equals(id)) {\r
722 return vPackageList.elementAt(indexI);\r
723 }\r
724 } catch (IOException e) {\r
92e29378 725\r
a13899c5 726 } catch (XmlException e) {\r
55a2762d 727\r
a13899c5 728 } catch (Exception e) {\r
92e29378 729\r
a13899c5 730 }\r
731 }\r
732 }\r
733\r
734 return null;\r
735 }\r
736\r
737 public Identification getId(String path, ModuleSurfaceArea msa) {\r
738 MsaHeader head = msa.getMsaHeader();\r
739 String name = head.getModuleName();\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, PackageSurfaceArea spd) {\r
747 SpdHeader head = spd.getSpdHeader();\r
748 String name = head.getPackageName();\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 public Identification getId(String path, PlatformSurfaceArea fpd) {\r
756 PlatformHeader head = fpd.getPlatformHeader();\r
757 String name = head.getPlatformName();\r
758 String guid = head.getGuidValue();\r
759 String version = head.getVersion();\r
760 Identification id = new Identification(name, guid, version, path);\r
761 return id;\r
762 }\r
763\r
764 /**\r
765 Add module information to package surface area\r
766 \r
767 @param mid\r
768 @throws IOException\r
769 @throws XmlException\r
770 @throws Exception\r
771 \r
772 **/\r
773 public void addModuleToPackage(ModuleIdentification mid, PackageSurfaceArea spd) throws IOException, XmlException,\r
774 Exception {\r
775 String packagePath = mid.getPackageId().getPath();\r
776 String modulePath = mid.getPath();\r
777 if (spd == null) {\r
778 spd = OpenFile.openSpdFile(packagePath);\r
779 }\r
780 MsaFiles msaFile = spd.getMsaFiles();\r
781 if (msaFile == null) {\r
782 msaFile = MsaFiles.Factory.newInstance();\r
783 }\r
784 packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR));\r
785 String fn = Tools.getRelativePath(modulePath, packagePath);\r
786 msaFile.addNewFilename();\r
787 msaFile.setFilenameArray(msaFile.getFilenameList().size() - 1, fn);\r
788 spd.setMsaFiles(msaFile);\r
789 SaveFile.saveSpdFile(mid.getPackageId().getPath(), spd);\r
790 }\r
791\r
792 /**\r
793 Add input package into database\r
794 \r
795 @param id\r
796 * @throws Exception \r
797 \r
798 **/\r
799 public void addPackageToDatabase(PackageIdentification id) throws Exception {\r
800 String path = id.getPath();\r
801 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
802 this.openFrameworkDb();\r
803 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
804 filename.setStringValue(path);\r
805 fdb.getPackageList().addNewFilename();\r
806 fdb.getPackageList().setFilenameArray(fdb.getPackageList().sizeOfFilenameArray() - 1, filename);\r
807 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
808 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
809 SaveFile.saveDbFile(strFrameworkDbFilePath, fdb);\r
810 }\r
811\r
812 /**\r
813 Add input package into database\r
814 \r
815 @param id\r
816 * @throws Exception \r
817 \r
818 **/\r
819 public void addPlatformToDatabase(PlatformIdentification id) throws Exception {\r
820 String path = id.getPath();\r
821 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
822 this.openFrameworkDb();\r
823 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
824 filename.setStringValue(path);\r
825 fdb.getPlatformList().addNewFilename();\r
826 fdb.getPlatformList().setFilenameArray(fdb.getPlatformList().sizeOfFilenameArray() - 1, filename);\r
827 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
828 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
829 SaveFile.saveDbFile(strFrameworkDbFilePath, fdb);\r
830 }\r
79cb6fdb 831\r
832 /**\r
833 Get all file's path from one module\r
834 \r
835 @param path\r
836 @return\r
837 @throws IOException\r
838 @throws XmlException\r
839 @throws Exception\r
840 \r
841 **/\r
8f9acbd7 842 public Vector<String> getAllModuleFilesPath(String path) throws IOException, XmlException, Exception {\r
79cb6fdb 843 Vector<String> v = new Vector<String>();\r
844 path = Tools.convertPathToCurrentOsType(path);\r
845 v.addElement(path);\r
846 ModuleSurfaceArea msa = OpenFile.openMsaFile(path);\r
847 if (msa != null) {\r
848 //\r
849 // Get all files' path of a module\r
850 //\r
851 SourceFiles sf = msa.getSourceFiles();\r
852 if (sf != null) {\r
853 for (int index = 0; index < sf.getFilenameList().size(); index++) {\r
854 String temp = sf.getFilenameList().get(index).getStringValue();\r
855 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;\r
856 v.addElement(Tools.convertPathToCurrentOsType(temp));\r
857 }\r
858 }\r
859 }\r
860\r
861 return v;\r
862 }\r
863\r
864 /**\r
865 Get all file's path from one package\r
866 \r
867 @param path\r
868 @return\r
869 @throws IOException\r
870 @throws XmlException\r
871 @throws Exception\r
872 \r
873 **/\r
8f9acbd7 874 public Vector<String> getAllPakcageFilesPath(String path) throws IOException, XmlException, Exception {\r
79cb6fdb 875 Vector<String> v = new Vector<String>();\r
876 path = Tools.convertPathToCurrentOsType(path);\r
877 //\r
878 // First add package\r
879 //\r
880 v.addElement(path);\r
55a2762d 881\r
79cb6fdb 882 //\r
8f9acbd7 883 // Add the package's industry std includes one by one\r
79cb6fdb 884 //\r
885 Vector<String> f1 = new Vector<String>();\r
8f9acbd7 886 f1 = getAllIndustryStdIncludesOfPackage(path);\r
887 for (int index = 0; index < f1.size(); index++) {\r
888 v.addElement(f1.get(index));\r
889 }\r
55a2762d 890\r
8f9acbd7 891 //\r
892 // Add module's files one by one\r
893 //\r
894 f1 = new Vector<String>();\r
79cb6fdb 895 f1 = getAllModulesOfPackage(path);\r
896 for (int indexI = 0; indexI < f1.size(); indexI++) {\r
8f9acbd7 897 Vector<String> f2 = getAllModuleFilesPath(f1.get(indexI));\r
79cb6fdb 898 for (int indexJ = 0; indexJ < f2.size(); indexJ++) {\r
899 v.addElement(f2.get(indexJ));\r
900 }\r
901 }\r
79cb6fdb 902\r
903 return v;\r
904 }\r
a13899c5 905}\r