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