3 The file is used to init workspace and get basic information of workspace
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
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.
15 package org
.tianocore
.frameworkwizard
.workspace
;
18 import java
.io
.IOException
;
19 import java
.util
.List
;
20 import java
.util
.Vector
;
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
;
50 public class WorkspaceTools
{
52 // Define class members
54 private FrameworkDatabase fdb
= null;
56 private Vector
<ModuleIdentification
> vModuleList
= new Vector
<ModuleIdentification
>();
58 private Vector
<PackageIdentification
> vPackageList
= new Vector
<PackageIdentification
>();
60 private Vector
<PlatformIdentification
> vPlatformList
= new Vector
<PlatformIdentification
>();
64 Open Framework Database file
67 private FrameworkDatabase
openFrameworkDb() {
68 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
69 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
71 fdb
= OpenFile
.openFrameworkDb(strFrameworkDbFilePath
);
72 } catch (XmlException e
) {
73 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, e
.getMessage());
75 } catch (Exception e
) {
76 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, "Invalid file type");
82 public void addFarToDb(List
<String
> packageList
, List
<String
> platformList
, FarHeader far
) {
83 FrameworkDatabase fdb
= openFrameworkDb();
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
);
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
);
99 DbPathAndFilename farItem
= DbPathAndFilename
.Factory
.newInstance();
100 farItem
.setFarGuid(far
.getGuidValue());
101 farItem
.setStringValue(far
.getFarName());
102 fdb
.getFarList().getFilenameList().add(farItem
);
104 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
105 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
108 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
109 } catch (Exception e
) {
114 public void removeFarFromDb(FarIdentification far
) {
115 FrameworkDatabase fdb
= openFrameworkDb();
119 XmlCursor cursor
= fdb
.getPackageList().newCursor();
120 cursor
.toFirstChild();
122 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
124 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
127 } while (cursor
.toNextSibling());
133 cursor
= fdb
.getPlatformList().newCursor();
134 cursor
.toFirstChild();
136 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
137 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
140 } while (cursor
.toNextSibling());
145 cursor
= fdb
.getFarList().newCursor();
146 cursor
.toFirstChild();
148 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
149 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
152 } while (cursor
.toNextSibling());
155 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
156 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
158 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
159 } catch (Exception e
) {
164 public String
getPackageFarGuid(Identification packageId
) {
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();
179 public String
getPlatformFarGuid(Identification platformId
) {
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();
194 public String
getModuleFarGuid(Identification moduleId
) {
195 PackageIdentification packageId
= getPackageIdByModuleId(moduleId
);
196 if (packageId
!= null) {
197 return getPackageFarGuid(packageId
);
204 Get all modules' paths from one package
206 @return a Vector with all modules' path
209 public Vector
<String
> getAllModulesOfPackage(String path
) {
210 Vector
<String
> modulePath
= new Vector
<String
>();
212 MsaFiles files
= OpenFile
.openSpdFile(path
).getMsaFiles();
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
);
221 } catch (IOException e
) {
223 } catch (XmlException e
) {
225 } catch (Exception e
) {
232 Get all Industry Std Includes' paths from one package
234 @return a Vector with all paths
237 public Vector
<String
> getAllIndustryStdIncludesOfPackage(String path
) {
238 Vector
<String
> includePath
= new Vector
<String
>();
240 IndustryStdIncludes files
= OpenFile
.openSpdFile(path
).getIndustryStdIncludes();
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
);
249 } catch (IOException e
) {
251 } catch (XmlException e
) {
253 } catch (Exception e
) {
260 Get all package basic information form the FrameworkDatabase.db file
262 @return vPackageList A vector includes all packages' basic information
265 public Vector
<PackageIdentification
> getAllPackages() {
266 Identification id
= null;
267 vPackageList
.removeAllElements();
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
);
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());
281 } catch (XmlException e
) {
282 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
284 } catch (Exception e
) {
285 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
289 Sort
.sortPackages(vPackageList
, DataType
.SORT_TYPE_ASCENDING
);
293 public Vector
<FarIdentification
> getAllFars() {
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());
304 public Vector
<PackageIdentification
> getPackagesByFar(FarIdentification far
) {
305 Identification id
= null;
307 Vector
<PackageIdentification
> v
= new Vector
<PackageIdentification
>();
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
);
314 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
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());
322 } catch (XmlException e
) {
323 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
325 } catch (Exception e
) {
326 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
334 public Vector
<PlatformIdentification
> getPlatformsByFar(FarIdentification far
) {
335 Identification id
= null;
337 Vector
<PlatformIdentification
> v
= new Vector
<PlatformIdentification
>();
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
);
344 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
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());
351 } catch (XmlException e
) {
352 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
354 } catch (Exception e
) {
355 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
364 Get all module basic information from a package
367 @return A vector includes all modules' basic information
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;
376 for (int index
= 0; index
< modulePaths
.size(); index
++) {
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());
387 v
.addElement(new ModuleIdentification(id
, pid
));
389 Sort
.sortModules(v
, DataType
.SORT_TYPE_ASCENDING
);
395 Get all module basic information form the FrameworkDatabase.db file
397 @return vModuleList A vector includes all modules' basic information
400 public Vector
<ModuleIdentification
> getAllModules() {
401 vModuleList
.removeAllElements();
403 // First get all packages
406 Vector
<String
> modulePaths
= new Vector
<String
>();
407 Identification id
= null;
408 String packagePath
= null;
409 String modulePath
= null;
412 // For each package, get all modules list
414 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
415 packagePath
= vPackageList
.elementAt(indexI
).getPath();
416 modulePaths
= this.getAllModulesOfPackage(packagePath
);
418 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
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");
432 Sort
.sortModules(vModuleList
, DataType
.SORT_TYPE_ASCENDING
);
437 Get all platform basic information form the FrameworkDatabase.db file
439 @return vplatformList A vector includes all platforms' basic information
442 public Vector
<PlatformIdentification
> getAllPlatforms() {
443 Identification id
= null;
444 vPlatformList
.removeAllElements();
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
);
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");
463 Sort
.sortPlatforms(vPlatformList
, DataType
.SORT_TYPE_ASCENDING
);
464 return vPlatformList
;
468 Get all Library Class Definitions from a package
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());
481 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
486 Get all Protocol Definitions from a package
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());
499 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
504 Get all Ppi Definitions from a package
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());
517 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
522 Get all Guid Definitions from a package
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());
535 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
540 Get all Pcd Definitions from a package
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());
555 vector
.addPcd(new PcdIdentification(name
, guidCName
, help
, type
));
559 Sort
.sortPcds(vector
, DataType
.SORT_TYPE_ASCENDING
);
563 public Vector
<String
> getAllLibraryClassDefinitionsFromWorkspace() {
565 // First get all packages
567 this.getAllPackages();
569 Vector
<String
> vector
= new Vector
<String
>();
570 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
572 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(OpenFile
573 .openSpdFile(vPackageList
576 if (v
!= null && v
.size() > 0) {
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
587 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
591 public Vector
<String
> getAllProtocolDeclarationsFromWorkspace() {
593 // First get all packages
595 this.getAllPackages();
597 Vector
<String
> vector
= new Vector
<String
>();
598 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
600 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
602 if (v
!= null && v
.size() > 0) {
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
613 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
617 public Vector
<String
> getAllPpiDeclarationsFromWorkspace() {
619 // First get all packages
621 this.getAllPackages();
623 Vector
<String
> vector
= new Vector
<String
>();
624 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
626 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
628 if (v
!= null && v
.size() > 0) {
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
639 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
643 public Vector
<String
> getAllGuidDeclarationsFromWorkspace() {
645 // First get all packages
647 this.getAllPackages();
649 Vector
<String
> vector
= new Vector
<String
>();
650 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
652 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
654 if (v
!= null && v
.size() > 0) {
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
665 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
669 public PcdVector
getAllPcdDeclarationsFromWorkspace() {
671 // First get all packages
673 this.getAllPackages();
675 PcdVector vector
= new PcdVector();
676 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
678 PcdVector v
= getAllPcdDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
).getPath()));
679 if (v
!= null && v
.size() > 0) {
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
690 Sort
.sortPcds(vector
, DataType
.SORT_TYPE_ASCENDING
);
695 Find a module's package's id
697 @param id input module id
701 public PackageIdentification
getPackageIdByModuleId(Identification id
) {
703 Vector
<String
> modulePaths
= new Vector
<String
>();
704 Identification mid
= null;
705 String packagePath
= null;
706 String modulePath
= null;
709 // For each package, get all modules list
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
);
717 mid
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
721 if (mid
.equals(id
)) {
722 return vPackageList
.elementAt(indexI
);
724 } catch (IOException e
) {
726 } catch (XmlException e
) {
728 } catch (Exception e
) {
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
);
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
);
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
);
765 Add module information to package surface area
773 public void addModuleToPackage(ModuleIdentification mid
, PackageSurfaceArea spd
) throws IOException
, XmlException
,
775 String packagePath
= mid
.getPackageId().getPath();
776 String modulePath
= mid
.getPath();
778 spd
= OpenFile
.openSpdFile(packagePath
);
780 MsaFiles msaFile
= spd
.getMsaFiles();
781 if (msaFile
== null) {
782 msaFile
= MsaFiles
.Factory
.newInstance();
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
);
793 Add input package into database
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
);
813 Add input package into database
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
);
833 Get all file's path from one module
842 public Vector
<String
> getAllModuleFilesPath(String path
) throws IOException
, XmlException
, Exception
{
843 Vector
<String
> v
= new Vector
<String
>();
844 path
= Tools
.convertPathToCurrentOsType(path
);
846 ModuleSurfaceArea msa
= OpenFile
.openMsaFile(path
);
849 // Get all files' path of a module
851 SourceFiles sf
= msa
.getSourceFiles();
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
));
865 Get all file's path from one package
874 public Vector
<String
> getAllPakcageFilesPath(String path
) throws IOException
, XmlException
, Exception
{
875 Vector
<String
> v
= new Vector
<String
>();
876 path
= Tools
.convertPathToCurrentOsType(path
);
883 // Add the package's industry std includes one by one
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
));
892 // Add module's files one by one
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
));