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
;
17 import java
.io
.IOException
;
18 import java
.util
.Vector
;
20 import org
.apache
.xmlbeans
.XmlException
;
21 import org
.tianocore
.DbPathAndFilename
;
22 import org
.tianocore
.FrameworkDatabaseDocument
;
23 import org
.tianocore
.IndustryStdIncludesDocument
.IndustryStdIncludes
;
24 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
25 import org
.tianocore
.MsaFilesDocument
.MsaFiles
;
26 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
27 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
28 import org
.tianocore
.PlatformHeaderDocument
.PlatformHeader
;
29 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
30 import org
.tianocore
.SourceFilesDocument
.SourceFiles
;
31 import org
.tianocore
.SpdHeaderDocument
.SpdHeader
;
32 import org
.tianocore
.frameworkwizard
.common
.DataType
;
33 import org
.tianocore
.frameworkwizard
.common
.Log
;
34 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
35 import org
.tianocore
.frameworkwizard
.common
.Tools
;
36 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
37 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpenFile
;
38 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
39 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
40 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
42 public class WorkspaceTools
{
44 // Define class members
46 private FrameworkDatabaseDocument
.FrameworkDatabase fdb
= null;
48 private Vector
<ModuleIdentification
> vModuleList
= new Vector
<ModuleIdentification
>();
50 private Vector
<PackageIdentification
> vPackageList
= new Vector
<PackageIdentification
>();
52 private Vector
<PlatformIdentification
> vPlatformList
= new Vector
<PlatformIdentification
>();
56 Open Framework Database file
59 private void openFrameworkDb() {
60 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
61 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
63 fdb
= OpenFile
.openFrameworkDb(strFrameworkDbFilePath
);
64 } catch (XmlException e
) {
65 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, e
.getMessage());
67 } catch (Exception e
) {
68 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, "Invalid file type");
74 Get all modules' paths from one package
76 @return a Vector with all modules' path
79 public Vector
<String
> getAllModulesOfPackage(String path
) {
80 Vector
<String
> modulePath
= new Vector
<String
>();
82 MsaFiles files
= OpenFile
.openSpdFile(path
).getMsaFiles();
84 for (int index
= 0; index
< files
.getFilenameList().size(); index
++) {
85 String msaPath
= files
.getFilenameList().get(index
);
86 msaPath
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + msaPath
;
87 msaPath
= Tools
.convertPathToCurrentOsType(msaPath
);
88 modulePath
.addElement(msaPath
);
91 } catch (IOException e
) {
93 } catch (XmlException e
) {
95 } catch (Exception e
) {
102 Get all Industry Std Includes' paths from one package
104 @return a Vector with all paths
107 public Vector
<String
> getAllIndustryStdIncludesOfPackage(String path
) {
108 Vector
<String
> includePath
= new Vector
<String
>();
110 IndustryStdIncludes files
= OpenFile
.openSpdFile(path
).getIndustryStdIncludes();
112 for (int index
= 0; index
< files
.getIndustryStdHeaderList().size(); index
++) {
113 String temp
= files
.getIndustryStdHeaderList().get(index
).getName();
114 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
115 temp
= Tools
.convertPathToCurrentOsType(temp
);
116 includePath
.addElement(temp
);
119 } catch (IOException e
) {
121 } catch (XmlException e
) {
123 } catch (Exception e
) {
130 Get all package basic information form the FrameworkDatabase.db file
132 @return vPackageList A vector includes all packages' basic information
135 public Vector
<PackageIdentification
> getAllPackages() {
136 Identification id
= null;
137 vPackageList
.removeAllElements();
141 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
142 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
143 + fdb
.getPackageList().getFilenameArray(index
).getStringValue();
144 path
= Tools
.convertPathToCurrentOsType(path
);
146 id
= getId(path
, OpenFile
.openSpdFile(path
));
147 vPackageList
.addElement(new PackageIdentification(id
));
148 } catch (IOException e
) {
149 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
151 } catch (XmlException e
) {
152 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
154 } catch (Exception e
) {
155 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
163 Get all package basic information form the FrameworkDatabase.db file
165 @return vPackageList A vector includes all packages' basic information
168 public Vector
<ModuleIdentification
> getAllModules() {
169 vModuleList
.removeAllElements();
171 // First get all packages
174 Vector
<String
> modulePaths
= new Vector
<String
>();
175 Identification id
= null;
176 String packagePath
= null;
177 String modulePath
= null;
180 // For each package, get all modules list
182 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
183 packagePath
= vPackageList
.elementAt(indexI
).getPath();
184 modulePaths
= this.getAllModulesOfPackage(packagePath
);
186 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
188 modulePath
= modulePaths
.get(indexJ
);
189 id
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
190 vModuleList
.addElement(new ModuleIdentification(id
, vPackageList
.elementAt(indexI
)));
191 } catch (IOException e
) {
192 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
194 } catch (XmlException e
) {
195 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
197 } catch (Exception e
) {
198 Log
.err("Open Module Surface Area " + modulePath
, "Invalid file type");
208 Get all platform basic information form the FrameworkDatabase.db file
210 @return vplatformList A vector includes all platforms' basic information
213 public Vector
<PlatformIdentification
> getAllPlatforms() {
214 Identification id
= null;
215 vPlatformList
.removeAllElements();
219 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
220 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
221 + fdb
.getPlatformList().getFilenameArray(index
).getStringValue();
222 path
= Tools
.convertPathToCurrentOsType(path
);
224 id
= getId(path
, OpenFile
.openFpdFile(path
));
225 vPlatformList
.addElement(new PlatformIdentification(id
));
226 } catch (IOException e
) {
227 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
229 } catch (XmlException e
) {
230 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
232 } catch (Exception e
) {
233 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
237 return vPlatformList
;
241 Get all Library Class Definitions from a package
245 public Vector
<String
> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd
) {
246 Vector
<String
> vector
= new Vector
<String
>();
247 if (spd
.getLibraryClassDeclarations() != null) {
248 if (spd
.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {
249 for (int index
= 0; index
< spd
.getLibraryClassDeclarations().getLibraryClassList().size(); index
++) {
250 vector
.addElement(spd
.getLibraryClassDeclarations().getLibraryClassList().get(index
).getName());
258 Get all Protocol Definitions from a package
262 public Vector
<String
> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd
) {
263 Vector
<String
> vector
= new Vector
<String
>();
264 if (spd
.getProtocolDeclarations() != null) {
265 if (spd
.getProtocolDeclarations().getEntryList().size() > 0) {
266 for (int index
= 0; index
< spd
.getProtocolDeclarations().getEntryList().size(); index
++) {
267 vector
.addElement(spd
.getProtocolDeclarations().getEntryList().get(index
).getCName());
275 Get all Ppi Definitions from a package
279 public Vector
<String
> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd
) {
280 Vector
<String
> vector
= new Vector
<String
>();
281 if (spd
.getPpiDeclarations() != null) {
282 if (spd
.getPpiDeclarations().getEntryList().size() > 0) {
283 for (int index
= 0; index
< spd
.getPpiDeclarations().getEntryList().size(); index
++) {
284 vector
.addElement(spd
.getPpiDeclarations().getEntryList().get(index
).getCName());
292 Get all Guid Definitions from a package
296 public Vector
<String
> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd
) {
297 Vector
<String
> vector
= new Vector
<String
>();
298 if (spd
.getGuidDeclarations() != null) {
299 if (spd
.getGuidDeclarations().getEntryList().size() > 0) {
300 for (int index
= 0; index
< spd
.getGuidDeclarations().getEntryList().size(); index
++) {
301 vector
.addElement(spd
.getGuidDeclarations().getEntryList().get(index
).getCName());
309 Get all Pcd Definitions from a package
313 public Vector
<String
> getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd
) {
314 Vector
<String
> vector
= new Vector
<String
>();
315 if (spd
.getPcdDeclarations() != null) {
316 if (spd
.getPcdDeclarations().getPcdEntryList().size() > 0) {
317 for (int index
= 0; index
< spd
.getPcdDeclarations().getPcdEntryList().size(); index
++) {
318 vector
.addElement(spd
.getPcdDeclarations().getPcdEntryList().get(index
).getCName());
325 public Vector
<String
> getAllLibraryClassDefinitionsFromWorkspace() {
327 // First get all packages
329 this.getAllPackages();
331 Vector
<String
> vector
= new Vector
<String
>();
332 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
334 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(OpenFile
335 .openSpdFile(vPackageList
338 if (v
!= null && v
.size() > 0) {
341 } catch (IOException e
) {
342 // TODO Auto-generated catch block
344 } catch (XmlException e
) {
345 // TODO Auto-generated catch block
347 } catch (Exception e
) {
348 // TODO Auto-generated catch block
355 public Vector
<String
> getAllProtocolDeclarationsFromWorkspace() {
357 // First get all packages
359 this.getAllPackages();
361 Vector
<String
> vector
= new Vector
<String
>();
362 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
364 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
366 if (v
!= null && v
.size() > 0) {
369 } catch (IOException e
) {
370 // TODO Auto-generated catch block
372 } catch (XmlException e
) {
373 // TODO Auto-generated catch block
375 } catch (Exception e
) {
376 // TODO Auto-generated catch block
383 public Vector
<String
> getAllPpiDeclarationsFromWorkspace() {
385 // First get all packages
387 this.getAllPackages();
389 Vector
<String
> vector
= new Vector
<String
>();
390 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
392 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
394 if (v
!= null && v
.size() > 0) {
397 } catch (IOException e
) {
398 // TODO Auto-generated catch block
400 } catch (XmlException e
) {
401 // TODO Auto-generated catch block
403 } catch (Exception e
) {
404 // TODO Auto-generated catch block
411 public Vector
<String
> getAllGuidDeclarationsFromWorkspace() {
413 // First get all packages
415 this.getAllPackages();
417 Vector
<String
> vector
= new Vector
<String
>();
418 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
420 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
422 if (v
!= null && v
.size() > 0) {
425 } catch (IOException e
) {
426 // TODO Auto-generated catch block
428 } catch (XmlException e
) {
429 // TODO Auto-generated catch block
431 } catch (Exception e
) {
432 // TODO Auto-generated catch block
439 public Vector
<String
> getAllPcdDeclarationsFromWorkspace() {
441 // First get all packages
443 this.getAllPackages();
445 Vector
<String
> vector
= new Vector
<String
>();
446 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
448 Vector
<String
> v
= getAllPcdDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
450 if (v
!= null && v
.size() > 0) {
453 } catch (IOException e
) {
454 // TODO Auto-generated catch block
456 } catch (XmlException e
) {
457 // TODO Auto-generated catch block
459 } catch (Exception e
) {
460 // TODO Auto-generated catch block
468 Find a module's package's id
470 @param id input module id
474 public PackageIdentification
getPackageIdByModuleId(Identification id
) {
476 Vector
<String
> modulePaths
= new Vector
<String
>();
477 Identification mid
= null;
478 String packagePath
= null;
479 String modulePath
= null;
482 // For each package, get all modules list
484 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
485 packagePath
= vPackageList
.elementAt(indexI
).getPath();
486 modulePaths
= this.getAllModulesOfPackage(packagePath
);
487 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
488 modulePath
= modulePaths
.get(indexJ
);
490 mid
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
494 if (mid
.equals(id
)) {
495 return vPackageList
.elementAt(indexI
);
497 } catch (IOException e
) {
499 } catch (XmlException e
) {
501 } catch (Exception e
) {
510 public Identification
getId(String path
, ModuleSurfaceArea msa
) {
511 MsaHeader head
= msa
.getMsaHeader();
512 String name
= head
.getModuleName();
513 String guid
= head
.getGuidValue();
514 String version
= head
.getVersion();
515 Identification id
= new Identification(name
, guid
, version
, path
);
519 public Identification
getId(String path
, PackageSurfaceArea spd
) {
520 SpdHeader head
= spd
.getSpdHeader();
521 String name
= head
.getPackageName();
522 String guid
= head
.getGuidValue();
523 String version
= head
.getVersion();
524 Identification id
= new Identification(name
, guid
, version
, path
);
528 public Identification
getId(String path
, PlatformSurfaceArea fpd
) {
529 PlatformHeader head
= fpd
.getPlatformHeader();
530 String name
= head
.getPlatformName();
531 String guid
= head
.getGuidValue();
532 String version
= head
.getVersion();
533 Identification id
= new Identification(name
, guid
, version
, path
);
538 Add module information to package surface area
546 public void addModuleToPackage(ModuleIdentification mid
, PackageSurfaceArea spd
) throws IOException
, XmlException
,
548 String packagePath
= mid
.getPackageId().getPath();
549 String modulePath
= mid
.getPath();
551 spd
= OpenFile
.openSpdFile(packagePath
);
553 MsaFiles msaFile
= spd
.getMsaFiles();
554 if (msaFile
== null) {
555 msaFile
= MsaFiles
.Factory
.newInstance();
557 packagePath
= packagePath
.substring(0, packagePath
.lastIndexOf(DataType
.FILE_SEPARATOR
));
558 String fn
= Tools
.getRelativePath(modulePath
, packagePath
);
559 msaFile
.addNewFilename();
560 msaFile
.setFilenameArray(msaFile
.getFilenameList().size() - 1, fn
);
561 spd
.setMsaFiles(msaFile
);
562 SaveFile
.saveSpdFile(mid
.getPackageId().getPath(), spd
);
566 Add input package into database
572 public void addPackageToDatabase(PackageIdentification id
) throws Exception
{
573 String path
= id
.getPath();
574 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
575 this.openFrameworkDb();
576 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
577 filename
.setStringValue(path
);
578 fdb
.getPackageList().addNewFilename();
579 fdb
.getPackageList().setFilenameArray(fdb
.getPackageList().sizeOfFilenameArray() - 1, filename
);
580 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
581 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
582 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
586 Add input package into database
592 public void addPlatformToDatabase(PlatformIdentification id
) throws Exception
{
593 String path
= id
.getPath();
594 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
595 this.openFrameworkDb();
596 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
597 filename
.setStringValue(path
);
598 fdb
.getPlatformList().addNewFilename();
599 fdb
.getPlatformList().setFilenameArray(fdb
.getPlatformList().sizeOfFilenameArray() - 1, filename
);
600 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
601 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
602 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
606 Get all file's path from one module
615 public Vector
<String
> getAllModuleFilesPath(String path
) throws IOException
, XmlException
, Exception
{
616 Vector
<String
> v
= new Vector
<String
>();
617 path
= Tools
.convertPathToCurrentOsType(path
);
619 ModuleSurfaceArea msa
= OpenFile
.openMsaFile(path
);
622 // Get all files' path of a module
624 SourceFiles sf
= msa
.getSourceFiles();
626 for (int index
= 0; index
< sf
.getFilenameList().size(); index
++) {
627 String temp
= sf
.getFilenameList().get(index
).getStringValue();
628 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
629 v
.addElement(Tools
.convertPathToCurrentOsType(temp
));
638 Get all file's path from one package
647 public Vector
<String
> getAllPakcageFilesPath(String path
) throws IOException
, XmlException
, Exception
{
648 Vector
<String
> v
= new Vector
<String
>();
649 path
= Tools
.convertPathToCurrentOsType(path
);
656 // Add the package's industry std includes one by one
658 Vector
<String
> f1
= new Vector
<String
>();
659 f1
= getAllIndustryStdIncludesOfPackage(path
);
660 for (int index
= 0; index
< f1
.size(); index
++) {
661 v
.addElement(f1
.get(index
));
665 // Add module's files one by one
667 f1
= new Vector
<String
>();
668 f1
= getAllModulesOfPackage(path
);
669 for (int indexI
= 0; indexI
< f1
.size(); indexI
++) {
670 Vector
<String
> f2
= getAllModuleFilesPath(f1
.get(indexI
));
671 for (int indexJ
= 0; indexJ
< f2
.size(); indexJ
++) {
672 v
.addElement(f2
.get(indexJ
));