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
.Tools
;
39 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpenFile
;
41 import org
.tianocore
.frameworkwizard
.far
.FarHeader
;
42 import org
.tianocore
.frameworkwizard
.far
.FarIdentification
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
44 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
45 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
47 public class WorkspaceTools
{
49 // Define class members
51 private FrameworkDatabase fdb
= null;
53 private Vector
<ModuleIdentification
> vModuleList
= new Vector
<ModuleIdentification
>();
55 private Vector
<PackageIdentification
> vPackageList
= new Vector
<PackageIdentification
>();
57 private Vector
<PlatformIdentification
> vPlatformList
= new Vector
<PlatformIdentification
>();
61 Open Framework Database file
64 private FrameworkDatabase
openFrameworkDb() {
65 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
66 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
68 fdb
= OpenFile
.openFrameworkDb(strFrameworkDbFilePath
);
69 } catch (XmlException e
) {
70 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, e
.getMessage());
72 } catch (Exception e
) {
73 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, "Invalid file type");
79 public void addFarToDb(List
<String
> packageList
, List
<String
> platformList
, FarHeader far
) {
80 FrameworkDatabase fdb
= openFrameworkDb();
82 for (int i
= 0; i
< packageList
.size(); i
++) {
83 DbPathAndFilename item
= DbPathAndFilename
.Factory
.newInstance();
84 item
.setFarGuid(far
.getGuidValue());
85 item
.setStringValue(packageList
.get(i
));
86 fdb
.getPackageList().getFilenameList().add(item
);
89 for (int i
= 0; i
< platformList
.size(); i
++) {
90 DbPathAndFilename item
= DbPathAndFilename
.Factory
.newInstance();
91 item
.setFarGuid(far
.getGuidValue());
92 item
.setStringValue(platformList
.get(i
));
93 fdb
.getPlatformList().getFilenameList().add(item
);
96 DbPathAndFilename farItem
= DbPathAndFilename
.Factory
.newInstance();
97 farItem
.setFarGuid(far
.getGuidValue());
98 farItem
.setStringValue(far
.getFarName());
99 fdb
.getFarList().getFilenameList().add(farItem
);
101 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
102 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
105 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
106 } catch (Exception e
) {
111 public void removeFarFromDb(FarIdentification far
) {
112 FrameworkDatabase fdb
= openFrameworkDb();
116 XmlCursor cursor
= fdb
.getPackageList().newCursor();
117 cursor
.toFirstChild();
119 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
121 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
124 } while (cursor
.toNextSibling());
130 cursor
= fdb
.getPlatformList().newCursor();
131 cursor
.toFirstChild();
133 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
134 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
137 } while (cursor
.toNextSibling());
142 cursor
= fdb
.getFarList().newCursor();
143 cursor
.toFirstChild();
145 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
146 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
149 } while (cursor
.toNextSibling());
152 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
153 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
155 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
156 } catch (Exception e
) {
161 public String
getPackageFarGuid(Identification packageId
) {
164 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
165 DbPathAndFilename item
= fdb
.getPackageList().getFilenameArray(index
);
166 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
167 File tempFile
= new File(path
);
168 if (tempFile
.getPath().equalsIgnoreCase(packageId
.getPath())) {
169 return fdb
.getPackageList().getFilenameArray(index
).getFarGuid();
176 public String
getPlatformFarGuid(Identification platformId
) {
179 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
180 DbPathAndFilename item
= fdb
.getPlatformList().getFilenameArray(index
);
181 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
182 File tempFile
= new File(path
);
183 if (tempFile
.getPath().equalsIgnoreCase(platformId
.getPath())) {
184 return fdb
.getPlatformList().getFilenameArray(index
).getFarGuid();
191 public String
getModuleFarGuid(Identification moduleId
) {
192 PackageIdentification packageId
= getPackageIdByModuleId(moduleId
);
193 if (packageId
!= null) {
194 return getPackageFarGuid(packageId
);
201 Get all modules' paths from one package
203 @return a Vector with all modules' path
206 public Vector
<String
> getAllModulesOfPackage(String path
) {
207 Vector
<String
> modulePath
= new Vector
<String
>();
209 MsaFiles files
= OpenFile
.openSpdFile(path
).getMsaFiles();
211 for (int index
= 0; index
< files
.getFilenameList().size(); index
++) {
212 String msaPath
= files
.getFilenameList().get(index
);
213 msaPath
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + msaPath
;
214 msaPath
= Tools
.convertPathToCurrentOsType(msaPath
);
215 modulePath
.addElement(msaPath
);
218 } catch (IOException e
) {
220 } catch (XmlException e
) {
222 } catch (Exception e
) {
229 Get all Industry Std Includes' paths from one package
231 @return a Vector with all paths
234 public Vector
<String
> getAllIndustryStdIncludesOfPackage(String path
) {
235 Vector
<String
> includePath
= new Vector
<String
>();
237 IndustryStdIncludes files
= OpenFile
.openSpdFile(path
).getIndustryStdIncludes();
239 for (int index
= 0; index
< files
.getIndustryStdHeaderList().size(); index
++) {
240 String temp
= files
.getIndustryStdHeaderList().get(index
).getIncludeHeader();
241 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
242 temp
= Tools
.convertPathToCurrentOsType(temp
);
243 includePath
.addElement(temp
);
246 } catch (IOException e
) {
248 } catch (XmlException e
) {
250 } catch (Exception e
) {
257 Get all package basic information form the FrameworkDatabase.db file
259 @return vPackageList A vector includes all packages' basic information
262 public Vector
<PackageIdentification
> getAllPackages() {
263 Identification id
= null;
264 vPackageList
.removeAllElements();
268 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
269 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
270 + fdb
.getPackageList().getFilenameArray(index
).getStringValue();
271 path
= Tools
.convertPathToCurrentOsType(path
);
273 id
= getId(path
, OpenFile
.openSpdFile(path
));
274 vPackageList
.addElement(new PackageIdentification(id
));
275 } catch (IOException e
) {
276 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
278 } catch (XmlException e
) {
279 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
281 } catch (Exception e
) {
282 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
286 Tools
.sortPackages(vPackageList
, DataType
.SORT_TYPE_ASCENDING
);
290 public Vector
<FarIdentification
> getAllFars() {
292 Vector
<FarIdentification
> v
= new Vector
<FarIdentification
>();
293 for (int index
= 0; index
< fdb
.getFarList().getFilenameList().size(); index
++) {
294 DbPathAndFilename item
= fdb
.getFarList().getFilenameList().get(index
);
295 FarIdentification far
= new FarIdentification(item
.getFarGuid(), item
.getMd5Sum(), item
.getStringValue());
301 public Vector
<PackageIdentification
> getPackagesByFar(FarIdentification far
) {
302 Identification id
= null;
304 Vector
<PackageIdentification
> v
= new Vector
<PackageIdentification
>();
306 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
307 DbPathAndFilename item
= fdb
.getPackageList().getFilenameArray(index
);
308 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
309 path
= Tools
.convertPathToCurrentOsType(path
);
311 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
314 id
= getId(path
, OpenFile
.openSpdFile(path
));
315 v
.addElement(new PackageIdentification(id
));
316 } catch (IOException e
) {
317 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
319 } catch (XmlException e
) {
320 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
322 } catch (Exception e
) {
323 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
331 public Vector
<PlatformIdentification
> getPlatformsByFar(FarIdentification far
) {
332 Identification id
= null;
334 Vector
<PlatformIdentification
> v
= new Vector
<PlatformIdentification
>();
336 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
337 DbPathAndFilename item
= fdb
.getPlatformList().getFilenameArray(index
);
338 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
339 path
= Tools
.convertPathToCurrentOsType(path
);
341 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
343 id
= getId(path
, OpenFile
.openFpdFile(path
));
344 v
.addElement(new PlatformIdentification(id
));
345 } catch (IOException e
) {
346 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
348 } catch (XmlException e
) {
349 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
351 } catch (Exception e
) {
352 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
361 Get all module basic information from a package
364 @return A vector includes all modules' basic information
367 public Vector
<ModuleIdentification
> getAllModules(PackageIdentification pid
) {
368 Vector
<ModuleIdentification
> v
= new Vector
<ModuleIdentification
>();
369 Vector
<String
> modulePaths
= this.getAllModulesOfPackage(pid
.getPath());
370 Identification id
= null;
371 String modulePath
= null;
373 for (int index
= 0; index
< modulePaths
.size(); index
++) {
375 modulePath
= modulePaths
.get(index
);
376 id
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
377 } catch (IOException e
) {
378 Log
.log("Error when Open Module Surface Area " + modulePath
, e
.getMessage());
379 } catch (XmlException e
) {
380 Log
.log("Error when Open Module Surface Area " + modulePath
, e
.getMessage());
381 } catch (Exception e
) {
382 Log
.log("Error when Open Module Surface Area " + modulePath
, "Invalid file type " + e
.getMessage());
384 v
.addElement(new ModuleIdentification(id
, pid
));
386 Tools
.sortModules(v
, DataType
.SORT_TYPE_ASCENDING
);
392 Get all module basic information form the FrameworkDatabase.db file
394 @return vModuleList A vector includes all modules' basic information
397 public Vector
<ModuleIdentification
> getAllModules() {
398 vModuleList
.removeAllElements();
400 // First get all packages
403 Vector
<String
> modulePaths
= new Vector
<String
>();
404 Identification id
= null;
405 String packagePath
= null;
406 String modulePath
= null;
409 // For each package, get all modules list
411 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
412 packagePath
= vPackageList
.elementAt(indexI
).getPath();
413 modulePaths
= this.getAllModulesOfPackage(packagePath
);
415 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
417 modulePath
= modulePaths
.get(indexJ
);
418 id
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
419 vModuleList
.addElement(new ModuleIdentification(id
, vPackageList
.elementAt(indexI
)));
420 } catch (IOException e
) {
421 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
422 } catch (XmlException e
) {
423 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
424 } catch (Exception e
) {
425 Log
.err("Open Module Surface Area " + modulePath
, "Invalid file type");
429 Tools
.sortModules(vModuleList
, DataType
.SORT_TYPE_ASCENDING
);
434 Get all platform basic information form the FrameworkDatabase.db file
436 @return vplatformList A vector includes all platforms' basic information
439 public Vector
<PlatformIdentification
> getAllPlatforms() {
440 Identification id
= null;
441 vPlatformList
.removeAllElements();
445 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
446 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
447 + fdb
.getPlatformList().getFilenameArray(index
).getStringValue();
448 path
= Tools
.convertPathToCurrentOsType(path
);
450 id
= getId(path
, OpenFile
.openFpdFile(path
));
451 vPlatformList
.addElement(new PlatformIdentification(id
));
452 } catch (IOException e
) {
453 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
454 } catch (XmlException e
) {
455 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
456 } catch (Exception e
) {
457 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
460 Tools
.sortPlatforms(vPlatformList
, DataType
.SORT_TYPE_ASCENDING
);
461 return vPlatformList
;
465 Get all Library Class Definitions from a package
469 public Vector
<String
> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd
) {
470 Vector
<String
> vector
= new Vector
<String
>();
471 if (spd
.getLibraryClassDeclarations() != null) {
472 if (spd
.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {
473 for (int index
= 0; index
< spd
.getLibraryClassDeclarations().getLibraryClassList().size(); index
++) {
474 vector
.addElement(spd
.getLibraryClassDeclarations().getLibraryClassList().get(index
).getName());
478 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
483 Get all Protocol Definitions from a package
487 public Vector
<String
> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd
) {
488 Vector
<String
> vector
= new Vector
<String
>();
489 if (spd
.getProtocolDeclarations() != null) {
490 if (spd
.getProtocolDeclarations().getEntryList().size() > 0) {
491 for (int index
= 0; index
< spd
.getProtocolDeclarations().getEntryList().size(); index
++) {
492 vector
.addElement(spd
.getProtocolDeclarations().getEntryList().get(index
).getCName());
496 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
501 Get all Ppi Definitions from a package
505 public Vector
<String
> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd
) {
506 Vector
<String
> vector
= new Vector
<String
>();
507 if (spd
.getPpiDeclarations() != null) {
508 if (spd
.getPpiDeclarations().getEntryList().size() > 0) {
509 for (int index
= 0; index
< spd
.getPpiDeclarations().getEntryList().size(); index
++) {
510 vector
.addElement(spd
.getPpiDeclarations().getEntryList().get(index
).getCName());
514 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
519 Get all Guid Definitions from a package
523 public Vector
<String
> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd
) {
524 Vector
<String
> vector
= new Vector
<String
>();
525 if (spd
.getGuidDeclarations() != null) {
526 if (spd
.getGuidDeclarations().getEntryList().size() > 0) {
527 for (int index
= 0; index
< spd
.getGuidDeclarations().getEntryList().size(); index
++) {
528 vector
.addElement(spd
.getGuidDeclarations().getEntryList().get(index
).getCName());
532 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
537 Get all Pcd Definitions from a package
541 public Vector
<String
> getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd
) {
542 Vector
<String
> vector
= new Vector
<String
>();
543 if (spd
.getPcdDeclarations() != null) {
544 if (spd
.getPcdDeclarations().getPcdEntryList().size() > 0) {
545 for (int index
= 0; index
< spd
.getPcdDeclarations().getPcdEntryList().size(); index
++) {
546 vector
.addElement(spd
.getPcdDeclarations().getPcdEntryList().get(index
).getCName());
550 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
554 public Vector
<String
> getAllLibraryClassDefinitionsFromWorkspace() {
556 // First get all packages
558 this.getAllPackages();
560 Vector
<String
> vector
= new Vector
<String
>();
561 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
563 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(OpenFile
564 .openSpdFile(vPackageList
567 if (v
!= null && v
.size() > 0) {
570 } catch (IOException e
) {
571 // TODO Auto-generated catch block
572 } catch (XmlException e
) {
573 // TODO Auto-generated catch block
574 } catch (Exception e
) {
575 // TODO Auto-generated catch block
578 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
582 public Vector
<String
> getAllProtocolDeclarationsFromWorkspace() {
584 // First get all packages
586 this.getAllPackages();
588 Vector
<String
> vector
= new Vector
<String
>();
589 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
591 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
593 if (v
!= null && v
.size() > 0) {
596 } catch (IOException e
) {
597 // TODO Auto-generated catch block
598 } catch (XmlException e
) {
599 // TODO Auto-generated catch block
600 } catch (Exception e
) {
601 // TODO Auto-generated catch block
604 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
608 public Vector
<String
> getAllPpiDeclarationsFromWorkspace() {
610 // First get all packages
612 this.getAllPackages();
614 Vector
<String
> vector
= new Vector
<String
>();
615 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
617 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
619 if (v
!= null && v
.size() > 0) {
622 } catch (IOException e
) {
623 // TODO Auto-generated catch block
624 } catch (XmlException e
) {
625 // TODO Auto-generated catch block
626 } catch (Exception e
) {
627 // TODO Auto-generated catch block
630 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
634 public Vector
<String
> getAllGuidDeclarationsFromWorkspace() {
636 // First get all packages
638 this.getAllPackages();
640 Vector
<String
> vector
= new Vector
<String
>();
641 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
643 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
645 if (v
!= null && v
.size() > 0) {
648 } catch (IOException e
) {
649 // TODO Auto-generated catch block
650 } catch (XmlException e
) {
651 // TODO Auto-generated catch block
652 } catch (Exception e
) {
653 // TODO Auto-generated catch block
656 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
660 public Vector
<String
> getAllPcdDeclarationsFromWorkspace() {
662 // First get all packages
664 this.getAllPackages();
666 Vector
<String
> vector
= new Vector
<String
>();
667 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
669 Vector
<String
> v
= getAllPcdDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
671 if (v
!= null && v
.size() > 0) {
674 } catch (IOException e
) {
675 // TODO Auto-generated catch block
676 } catch (XmlException e
) {
677 // TODO Auto-generated catch block
678 } catch (Exception e
) {
679 // TODO Auto-generated catch block
682 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
687 Find a module's package's id
689 @param id input module id
693 public PackageIdentification
getPackageIdByModuleId(Identification id
) {
695 Vector
<String
> modulePaths
= new Vector
<String
>();
696 Identification mid
= null;
697 String packagePath
= null;
698 String modulePath
= null;
701 // For each package, get all modules list
703 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
704 packagePath
= vPackageList
.elementAt(indexI
).getPath();
705 modulePaths
= this.getAllModulesOfPackage(packagePath
);
706 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
707 modulePath
= modulePaths
.get(indexJ
);
709 mid
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
713 if (mid
.equals(id
)) {
714 return vPackageList
.elementAt(indexI
);
716 } catch (IOException e
) {
718 } catch (XmlException e
) {
720 } catch (Exception e
) {
729 public Identification
getId(String path
, ModuleSurfaceArea msa
) {
730 MsaHeader head
= msa
.getMsaHeader();
731 String name
= head
.getModuleName();
732 String guid
= head
.getGuidValue();
733 String version
= head
.getVersion();
734 Identification id
= new Identification(name
, guid
, version
, path
);
738 public Identification
getId(String path
, PackageSurfaceArea spd
) {
739 SpdHeader head
= spd
.getSpdHeader();
740 String name
= head
.getPackageName();
741 String guid
= head
.getGuidValue();
742 String version
= head
.getVersion();
743 Identification id
= new Identification(name
, guid
, version
, path
);
747 public Identification
getId(String path
, PlatformSurfaceArea fpd
) {
748 PlatformHeader head
= fpd
.getPlatformHeader();
749 String name
= head
.getPlatformName();
750 String guid
= head
.getGuidValue();
751 String version
= head
.getVersion();
752 Identification id
= new Identification(name
, guid
, version
, path
);
757 Add module information to package surface area
765 public void addModuleToPackage(ModuleIdentification mid
, PackageSurfaceArea spd
) throws IOException
, XmlException
,
767 String packagePath
= mid
.getPackageId().getPath();
768 String modulePath
= mid
.getPath();
770 spd
= OpenFile
.openSpdFile(packagePath
);
772 MsaFiles msaFile
= spd
.getMsaFiles();
773 if (msaFile
== null) {
774 msaFile
= MsaFiles
.Factory
.newInstance();
776 packagePath
= packagePath
.substring(0, packagePath
.lastIndexOf(DataType
.FILE_SEPARATOR
));
777 String fn
= Tools
.getRelativePath(modulePath
, packagePath
);
778 msaFile
.addNewFilename();
779 msaFile
.setFilenameArray(msaFile
.getFilenameList().size() - 1, fn
);
780 spd
.setMsaFiles(msaFile
);
781 SaveFile
.saveSpdFile(mid
.getPackageId().getPath(), spd
);
785 Add input package into database
791 public void addPackageToDatabase(PackageIdentification id
) throws Exception
{
792 String path
= id
.getPath();
793 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
794 this.openFrameworkDb();
795 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
796 filename
.setStringValue(path
);
797 fdb
.getPackageList().addNewFilename();
798 fdb
.getPackageList().setFilenameArray(fdb
.getPackageList().sizeOfFilenameArray() - 1, filename
);
799 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
800 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
801 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
805 Add input package into database
811 public void addPlatformToDatabase(PlatformIdentification id
) throws Exception
{
812 String path
= id
.getPath();
813 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
814 this.openFrameworkDb();
815 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
816 filename
.setStringValue(path
);
817 fdb
.getPlatformList().addNewFilename();
818 fdb
.getPlatformList().setFilenameArray(fdb
.getPlatformList().sizeOfFilenameArray() - 1, filename
);
819 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
820 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
821 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
825 Get all file's path from one module
834 public Vector
<String
> getAllModuleFilesPath(String path
) throws IOException
, XmlException
, Exception
{
835 Vector
<String
> v
= new Vector
<String
>();
836 path
= Tools
.convertPathToCurrentOsType(path
);
838 ModuleSurfaceArea msa
= OpenFile
.openMsaFile(path
);
841 // Get all files' path of a module
843 SourceFiles sf
= msa
.getSourceFiles();
845 for (int index
= 0; index
< sf
.getFilenameList().size(); index
++) {
846 String temp
= sf
.getFilenameList().get(index
).getStringValue();
847 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
848 v
.addElement(Tools
.convertPathToCurrentOsType(temp
));
857 Get all file's path from one package
866 public Vector
<String
> getAllPakcageFilesPath(String path
) throws IOException
, XmlException
, Exception
{
867 Vector
<String
> v
= new Vector
<String
>();
868 path
= Tools
.convertPathToCurrentOsType(path
);
875 // Add the package's industry std includes one by one
877 Vector
<String
> f1
= new Vector
<String
>();
878 f1
= getAllIndustryStdIncludesOfPackage(path
);
879 for (int index
= 0; index
< f1
.size(); index
++) {
880 v
.addElement(f1
.get(index
));
884 // Add module's files one by one
886 f1
= new Vector
<String
>();
887 f1
= getAllModulesOfPackage(path
);
888 for (int indexI
= 0; indexI
< f1
.size(); indexI
++) {
889 Vector
<String
> f2
= getAllModuleFilesPath(f1
.get(indexI
));
890 for (int indexJ
= 0; indexJ
< f2
.size(); indexJ
++) {
891 v
.addElement(f2
.get(indexJ
));