Fix include .h file error.
[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
a13899c5 44import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
45import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
46\r
47public class WorkspaceTools {\r
48 //\r
49 // Define class members\r
50 //\r
5a24e806 51 private FrameworkDatabase fdb = null;\r
a13899c5 52\r
53 private Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();\r
54\r
55 private Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();\r
56\r
57 private Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();\r
58\r
59 /**\r
60 \r
61 Open Framework Database file\r
62 \r
63 */\r
5a24e806 64 private FrameworkDatabase openFrameworkDb() {\r
a13899c5 65 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
66 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
67 try {\r
68 fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);\r
69 } catch (XmlException e) {\r
70 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());\r
5a24e806 71 return null;\r
a13899c5 72 } catch (Exception e) {\r
73 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");\r
5a24e806 74 return null;\r
a13899c5 75 }\r
5a24e806 76 return fdb;\r
a13899c5 77 }\r
78\r
5a24e806 79 public void addFarToDb(List<String> packageList, List<String> platformList, FarHeader far) {\r
80 FrameworkDatabase fdb = openFrameworkDb();\r
81 \r
82 for (int i = 0; i < packageList.size(); i++) {\r
83 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();\r
84 item.setFarGuid(far.getGuidValue());\r
85 item.setStringValue(packageList.get(i));\r
86 fdb.getPackageList().getFilenameList().add(item);\r
87 }\r
88 \r
89 for (int i = 0; i < platformList.size(); i++) {\r
90 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();\r
91 item.setFarGuid(far.getGuidValue());\r
92 item.setStringValue(platformList.get(i));\r
93 fdb.getPlatformList().getFilenameList().add(item);\r
94 }\r
95 \r
96 DbPathAndFilename farItem = DbPathAndFilename.Factory.newInstance();\r
97 farItem.setFarGuid(far.getGuidValue());\r
98 farItem.setStringValue(far.getFarName());\r
99 fdb.getFarList().getFilenameList().add(farItem);\r
100 \r
101 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
102 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
103 \r
104 try {\r
105 SaveFile.saveDbFile(strFrameworkDbFilePath, fdb);\r
106 }\r
107 catch (Exception e) {\r
108 e.printStackTrace();\r
109 }\r
110 }\r
111 \r
112 \r
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
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
126 } while (cursor.toNextSibling());\r
127 cursor.dispose();\r
128 \r
129 //\r
130 // Remove Platforms\r
131 //\r
132 cursor = fdb.getPlatformList().newCursor();\r
133 cursor.toFirstChild();\r
134 do {\r
135 DbPathAndFilename item = (DbPathAndFilename)cursor.getObject();\r
136 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
137 cursor.removeXml();\r
138 }\r
139 } while (cursor.toNextSibling());\r
140 \r
141 //\r
142 // Remove Far\r
143 //\r
144 cursor = fdb.getFarList().newCursor();\r
145 cursor.toFirstChild();\r
146 do {\r
147 DbPathAndFilename item = (DbPathAndFilename)cursor.getObject();\r
148 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
149 cursor.removeXml();\r
150 }\r
151 } while (cursor.toNextSibling());\r
152 cursor.dispose();\r
153 \r
154 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
155 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
156 try {\r
157 SaveFile.saveDbFile(strFrameworkDbFilePath, fdb);\r
158 }\r
159 catch (Exception e) {\r
160 e.printStackTrace();\r
161 }\r
162 }\r
163 \r
164 public String getPackageFarGuid(PackageIdentification 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\r
170 + item.getStringValue();\r
171 File tempFile = new File(path);\r
172 if (tempFile.getPath().equalsIgnoreCase(packageId.getSpdFile().getPath())) {\r
173 return fdb.getPackageList().getFilenameArray(index).getFarGuid();\r
174 }\r
175 }\r
176 \r
177 return null;\r
178 }\r
179 \r
180 public String getPlatformFarGuid(PlatformIdentification platformId) {\r
181 openFrameworkDb();\r
182 \r
183 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
184 DbPathAndFilename item = fdb.getPlatformList().getFilenameArray(index);\r
185 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
186 + item.getStringValue();\r
187 File tempFile = new File(path);\r
188 if (tempFile.getPath().equalsIgnoreCase(platformId.getFpdFile().getPath())) {\r
189 return fdb.getPlatformList().getFilenameArray(index).getFarGuid();\r
190 }\r
191 }\r
192 \r
193 return null;\r
194 }\r
195 \r
196 public String getModuleFarGuid(ModuleIdentification moduleId) {\r
197 PackageIdentification packageId = getPackageIdByModuleId(moduleId);\r
198 if (packageId != null) {\r
199 return getPackageFarGuid(packageId);\r
200 }\r
201 else {\r
202 return null;\r
203 }\r
204 }\r
a13899c5 205 /**\r
206 Get all modules' paths from one package\r
207 \r
208 @return a Vector with all modules' path\r
209 \r
210 **/\r
211 public Vector<String> getAllModulesOfPackage(String path) {\r
212 Vector<String> modulePath = new Vector<String>();\r
213 try {\r
214 MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();\r
215 if (files != null) {\r
216 for (int index = 0; index < files.getFilenameList().size(); index++) {\r
79cb6fdb 217 String msaPath = files.getFilenameList().get(index);\r
218 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;\r
219 msaPath = Tools.convertPathToCurrentOsType(msaPath);\r
220 modulePath.addElement(msaPath);\r
a13899c5 221 }\r
222 }\r
223 } catch (IOException e) {\r
92e29378 224\r
a13899c5 225 } catch (XmlException e) {\r
92e29378 226\r
a13899c5 227 } catch (Exception e) {\r
92e29378 228\r
a13899c5 229 }\r
230 return modulePath;\r
231 }\r
8f9acbd7 232 \r
233 /**\r
234 Get all Industry Std Includes' paths from one package\r
235 \r
236 @return a Vector with all paths\r
237 \r
238 **/\r
239 public Vector<String> getAllIndustryStdIncludesOfPackage(String path) {\r
240 Vector<String> includePath = new Vector<String>();\r
241 try {\r
242 IndustryStdIncludes files = OpenFile.openSpdFile(path).getIndustryStdIncludes();\r
243 if (files != null) {\r
244 for (int index = 0; index < files.getIndustryStdHeaderList().size(); index++) {\r
245 String temp = files.getIndustryStdHeaderList().get(index).getName();\r
246 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;\r
247 temp = Tools.convertPathToCurrentOsType(temp);\r
248 includePath.addElement(temp);\r
249 }\r
250 }\r
251 } catch (IOException e) {\r
92e29378 252\r
8f9acbd7 253 } catch (XmlException e) {\r
92e29378 254\r
8f9acbd7 255 } catch (Exception e) {\r
92e29378 256\r
8f9acbd7 257 }\r
258 return includePath;\r
259 }\r
a13899c5 260\r
261 /**\r
262 Get all package basic information form the FrameworkDatabase.db file\r
263 \r
264 @return vPackageList A vector includes all packages' basic information\r
265 \r
266 */\r
267 public Vector<PackageIdentification> getAllPackages() {\r
268 Identification id = null;\r
269 vPackageList.removeAllElements();\r
270\r
271 openFrameworkDb();\r
272\r
273 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
274 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
275 + fdb.getPackageList().getFilenameArray(index).getStringValue();\r
276 path = Tools.convertPathToCurrentOsType(path);\r
277 try {\r
278 id = getId(path, OpenFile.openSpdFile(path));\r
279 vPackageList.addElement(new PackageIdentification(id));\r
280 } catch (IOException e) {\r
281 Log.err("Open Package Surface Area " + path, e.getMessage());\r
92e29378 282\r
a13899c5 283 } catch (XmlException e) {\r
284 Log.err("Open Package Surface Area " + path, e.getMessage());\r
92e29378 285\r
a13899c5 286 } catch (Exception e) {\r
287 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
92e29378 288\r
a13899c5 289 }\r
290 }\r
92e29378 291 Tools.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 292 return vPackageList;\r
293 }\r
5a24e806 294\r
295 public Vector<FarIdentification> getAllFars() {\r
296 openFrameworkDb();\r
297 Vector<FarIdentification> v = new Vector<FarIdentification>();\r
298 for (int index = 0; index < fdb.getFarList().getFilenameList().size(); index++) {\r
299 DbPathAndFilename item = fdb.getFarList().getFilenameList().get(index);\r
300 FarIdentification far = new FarIdentification(item.getFarGuid(), item.getMd5Sum(), item.getStringValue());\r
301 v.addElement(far);\r
302 }\r
303 return v;\r
304 }\r
305 \r
306 public Vector<PackageIdentification> getPackagesByFar(FarIdentification far) {\r
307 Identification id = null;\r
308 openFrameworkDb();\r
309 Vector<PackageIdentification> v = new Vector<PackageIdentification>();\r
310 \r
311 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
312 DbPathAndFilename item = fdb.getPackageList().getFilenameArray(index);\r
313 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
314 + item.getStringValue();\r
315 path = Tools.convertPathToCurrentOsType(path);\r
316 \r
317 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
318 \r
319 try {\r
320 id = getId(path, OpenFile.openSpdFile(path));\r
321 v.addElement(new PackageIdentification(id));\r
322 } catch (IOException e) {\r
323 Log.err("Open Package Surface Area " + path, e.getMessage());\r
324 e.printStackTrace();\r
325 } catch (XmlException e) {\r
326 Log.err("Open Package Surface Area " + path, e.getMessage());\r
327 e.printStackTrace();\r
328 } catch (Exception e) {\r
329 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
330 e.printStackTrace();\r
331 }\r
332 }\r
333 }\r
334 return v;\r
335 }\r
92e29378 336 \r
5a24e806 337 public Vector<PlatformIdentification> getPlatformsByFar(FarIdentification far) {\r
338 Identification id = null;\r
339 openFrameworkDb();\r
340 Vector<PlatformIdentification> v = new Vector<PlatformIdentification>();\r
341 \r
342 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
343 DbPathAndFilename item = fdb.getPlatformList().getFilenameArray(index);\r
344 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
345 + item.getStringValue();\r
346 path = Tools.convertPathToCurrentOsType(path);\r
347 \r
348 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r
349 try {\r
350 id = getId(path, OpenFile.openFpdFile(path));\r
351 v.addElement(new PlatformIdentification(id));\r
352 } catch (IOException e) {\r
353 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
354 e.printStackTrace();\r
355 } catch (XmlException e) {\r
356 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
357 e.printStackTrace();\r
358 } catch (Exception e) {\r
359 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
360 e.printStackTrace();\r
361 }\r
362 }\r
363 }\r
364 return v;\r
365 }\r
366\r
92e29378 367 /**\r
368 Get all module basic information from a package\r
369 \r
370 @param id Package id\r
371 @return A vector includes all modules' basic information\r
372 \r
373 **/\r
374 public Vector<ModuleIdentification> getAllModules(PackageIdentification pid) {\r
375 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();\r
376 Vector<String> modulePaths = this.getAllModulesOfPackage(pid.getPath());\r
377 Identification id = null;\r
378 String modulePath = null;\r
379 \r
380 for (int index = 0; index < modulePaths.size(); index++) {\r
381 try {\r
382 modulePath = modulePaths.get(index);\r
383 id = getId(modulePath, OpenFile.openMsaFile(modulePath));\r
384 } catch (IOException e) {\r
385 Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage());\r
386 } catch (XmlException e) {\r
387 Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage());\r
388 } catch (Exception e) {\r
389 Log.log("Error when Open Module Surface Area " + modulePath, "Invalid file type " + e.getMessage());\r
390 }\r
391 v.addElement(new ModuleIdentification(id, pid));\r
392 }\r
393 Tools.sortModules(v, DataType.SORT_TYPE_ASCENDING);\r
394 return v;\r
395 \r
396 }\r
a13899c5 397\r
398 /**\r
92e29378 399 Get all module basic information form the FrameworkDatabase.db file\r
a13899c5 400 \r
92e29378 401 @return vModuleList A vector includes all modules' basic information\r
a13899c5 402 \r
403 */\r
404 public Vector<ModuleIdentification> getAllModules() {\r
405 vModuleList.removeAllElements();\r
406 //\r
407 // First get all packages\r
408 //\r
409 getAllPackages();\r
410 Vector<String> modulePaths = new Vector<String>();\r
411 Identification id = null;\r
412 String packagePath = null;\r
413 String modulePath = null;\r
414\r
415 //\r
416 // For each package, get all modules list\r
417 //\r
418 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {\r
419 packagePath = vPackageList.elementAt(indexI).getPath();\r
420 modulePaths = this.getAllModulesOfPackage(packagePath);\r
79cb6fdb 421 \r
a13899c5 422 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
a13899c5 423 try {\r
79cb6fdb 424 modulePath = modulePaths.get(indexJ);\r
a13899c5 425 id = getId(modulePath, OpenFile.openMsaFile(modulePath));\r
426 vModuleList.addElement(new ModuleIdentification(id, vPackageList.elementAt(indexI)));\r
427 } catch (IOException e) {\r
428 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
a13899c5 429 } catch (XmlException e) {\r
430 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
a13899c5 431 } catch (Exception e) {\r
432 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r
a13899c5 433 }\r
434 }\r
435 }\r
92e29378 436 Tools.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 437 return vModuleList;\r
438 }\r
439\r
440 /**\r
441 Get all platform basic information form the FrameworkDatabase.db file\r
442 \r
443 @return vplatformList A vector includes all platforms' basic information\r
444 \r
445 */\r
446 public Vector<PlatformIdentification> getAllPlatforms() {\r
447 Identification id = null;\r
448 vPlatformList.removeAllElements();\r
449\r
450 openFrameworkDb();\r
451\r
452 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
453 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
454 + fdb.getPlatformList().getFilenameArray(index).getStringValue();\r
455 path = Tools.convertPathToCurrentOsType(path);\r
456 try {\r
457 id = getId(path, OpenFile.openFpdFile(path));\r
458 vPlatformList.addElement(new PlatformIdentification(id));\r
459 } catch (IOException e) {\r
460 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
a13899c5 461 } catch (XmlException e) {\r
462 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
a13899c5 463 } catch (Exception e) {\r
464 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
a13899c5 465 }\r
466 }\r
92e29378 467 Tools.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 468 return vPlatformList;\r
469 }\r
470\r
471 /**\r
472 Get all Library Class Definitions from a package\r
473 \r
474 @return Vector\r
475 **/\r
476 public Vector<String> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd) {\r
477 Vector<String> vector = new Vector<String>();\r
478 if (spd.getLibraryClassDeclarations() != null) {\r
479 if (spd.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {\r
480 for (int index = 0; index < spd.getLibraryClassDeclarations().getLibraryClassList().size(); index++) {\r
481 vector.addElement(spd.getLibraryClassDeclarations().getLibraryClassList().get(index).getName());\r
482 }\r
483 }\r
484 }\r
92e29378 485 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 486 return vector;\r
487 }\r
488\r
489 /**\r
490 Get all Protocol Definitions from a package\r
491 \r
492 @return Vector\r
493 **/\r
494 public Vector<String> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd) {\r
495 Vector<String> vector = new Vector<String>();\r
496 if (spd.getProtocolDeclarations() != null) {\r
497 if (spd.getProtocolDeclarations().getEntryList().size() > 0) {\r
498 for (int index = 0; index < spd.getProtocolDeclarations().getEntryList().size(); index++) {\r
499 vector.addElement(spd.getProtocolDeclarations().getEntryList().get(index).getCName());\r
500 }\r
501 }\r
502 }\r
92e29378 503 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 504 return vector;\r
505 }\r
506\r
507 /**\r
508 Get all Ppi Definitions from a package\r
509 \r
510 @return Vector\r
511 **/\r
512 public Vector<String> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd) {\r
513 Vector<String> vector = new Vector<String>();\r
514 if (spd.getPpiDeclarations() != null) {\r
515 if (spd.getPpiDeclarations().getEntryList().size() > 0) {\r
516 for (int index = 0; index < spd.getPpiDeclarations().getEntryList().size(); index++) {\r
517 vector.addElement(spd.getPpiDeclarations().getEntryList().get(index).getCName());\r
518 }\r
79cb6fdb 519 }\r
a13899c5 520 }\r
92e29378 521 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 522 return vector;\r
523 }\r
524\r
525 /**\r
526 Get all Guid Definitions from a package\r
527 \r
528 @return Vector\r
529 **/\r
530 public Vector<String> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd) {\r
531 Vector<String> vector = new Vector<String>();\r
532 if (spd.getGuidDeclarations() != null) {\r
533 if (spd.getGuidDeclarations().getEntryList().size() > 0) {\r
534 for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) {\r
535 vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName());\r
536 }\r
79cb6fdb 537 }\r
a13899c5 538 }\r
92e29378 539 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 540 return vector;\r
541 }\r
542\r
543 /**\r
544 Get all Pcd Definitions from a package\r
545 \r
546 @return Vector\r
547 **/\r
548 public Vector<String> getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {\r
549 Vector<String> vector = new Vector<String>();\r
550 if (spd.getPcdDeclarations() != null) {\r
551 if (spd.getPcdDeclarations().getPcdEntryList().size() > 0) {\r
552 for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) {\r
553 vector.addElement(spd.getPcdDeclarations().getPcdEntryList().get(index).getCName());\r
554 }\r
79cb6fdb 555 }\r
a13899c5 556 }\r
92e29378 557 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 558 return vector;\r
559 }\r
560\r
561 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {\r
562 //\r
563 // First get all packages\r
564 //\r
565 this.getAllPackages();\r
566\r
567 Vector<String> vector = new Vector<String>();\r
568 for (int index = 0; index < this.vPackageList.size(); index++) {\r
569 try {\r
570 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(OpenFile\r
571 .openSpdFile(vPackageList\r
572 .get(index)\r
573 .getPath()));\r
574 if (v != null && v.size() > 0) {\r
575 vector.addAll(v);\r
576 }\r
577 } catch (IOException e) {\r
578 // TODO Auto-generated catch block\r
a13899c5 579 } catch (XmlException e) {\r
580 // TODO Auto-generated catch block\r
a13899c5 581 } catch (Exception e) {\r
582 // TODO Auto-generated catch block\r
a13899c5 583 }\r
584 }\r
92e29378 585 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 586 return vector;\r
587 }\r
588\r
589 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {\r
590 //\r
591 // First get all packages\r
592 //\r
593 this.getAllPackages();\r
594\r
595 Vector<String> vector = new Vector<String>();\r
596 for (int index = 0; index < this.vPackageList.size(); index++) {\r
597 try {\r
598 Vector<String> v = getAllProtocolDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
599 .getPath()));\r
600 if (v != null && v.size() > 0) {\r
601 vector.addAll(v);\r
602 }\r
603 } catch (IOException e) {\r
604 // TODO Auto-generated catch block\r
a13899c5 605 } catch (XmlException e) {\r
606 // TODO Auto-generated catch block\r
a13899c5 607 } catch (Exception e) {\r
608 // TODO Auto-generated catch block\r
a13899c5 609 }\r
610 }\r
92e29378 611 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 612 return vector;\r
613 }\r
614\r
615 public Vector<String> getAllPpiDeclarationsFromWorkspace() {\r
616 //\r
617 // First get all packages\r
618 //\r
619 this.getAllPackages();\r
620\r
621 Vector<String> vector = new Vector<String>();\r
622 for (int index = 0; index < this.vPackageList.size(); index++) {\r
623 try {\r
624 Vector<String> v = getAllPpiDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
625 .getPath()));\r
626 if (v != null && v.size() > 0) {\r
627 vector.addAll(v);\r
628 }\r
629 } catch (IOException e) {\r
630 // TODO Auto-generated catch block\r
a13899c5 631 } catch (XmlException e) {\r
632 // TODO Auto-generated catch block\r
a13899c5 633 } catch (Exception e) {\r
634 // TODO Auto-generated catch block\r
a13899c5 635 }\r
636 }\r
92e29378 637 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 638 return vector;\r
639 }\r
640\r
641 public Vector<String> getAllGuidDeclarationsFromWorkspace() {\r
642 //\r
643 // First get all packages\r
644 //\r
645 this.getAllPackages();\r
646\r
647 Vector<String> vector = new Vector<String>();\r
648 for (int index = 0; index < this.vPackageList.size(); index++) {\r
649 try {\r
650 Vector<String> v = getAllGuidDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
651 .getPath()));\r
652 if (v != null && v.size() > 0) {\r
653 vector.addAll(v);\r
654 }\r
655 } catch (IOException e) {\r
656 // TODO Auto-generated catch block\r
a13899c5 657 } catch (XmlException e) {\r
658 // TODO Auto-generated catch block\r
a13899c5 659 } catch (Exception e) {\r
660 // TODO Auto-generated catch block\r
a13899c5 661 }\r
662 }\r
92e29378 663 Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 664 return vector;\r
665 }\r
666\r
667 public Vector<String> getAllPcdDeclarationsFromWorkspace() {\r
668 //\r
669 // First get all packages\r
670 //\r
671 this.getAllPackages();\r
672\r
673 Vector<String> vector = new Vector<String>();\r
674 for (int index = 0; index < this.vPackageList.size(); index++) {\r
675 try {\r
676 Vector<String> v = getAllPcdDeclarationsFromPackage(OpenFile.openSpdFile(vPackageList.get(index)\r
677 .getPath()));\r
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
92e29378 689 Tools.sortVectorString(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
92e29378 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
880 \r
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
889 \r
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