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