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