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
);
107 catch (Exception e
) {
113 public void removeFarFromDb(FarIdentification far
) {
114 FrameworkDatabase fdb
= openFrameworkDb();
118 XmlCursor cursor
= fdb
.getPackageList().newCursor();
119 cursor
.toFirstChild();
121 DbPathAndFilename item
= (DbPathAndFilename
)cursor
.getObject();
123 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
126 } while (cursor
.toNextSibling());
132 cursor
= fdb
.getPlatformList().newCursor();
133 cursor
.toFirstChild();
135 DbPathAndFilename item
= (DbPathAndFilename
)cursor
.getObject();
136 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
139 } while (cursor
.toNextSibling());
144 cursor
= fdb
.getFarList().newCursor();
145 cursor
.toFirstChild();
147 DbPathAndFilename item
= (DbPathAndFilename
)cursor
.getObject();
148 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
151 } while (cursor
.toNextSibling());
154 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
155 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
157 SaveFile
.saveDbFile(strFrameworkDbFilePath
, fdb
);
159 catch (Exception e
) {
164 public String
getPackageFarGuid(PackageIdentification 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
170 + item
.getStringValue();
171 File tempFile
= new File(path
);
172 if (tempFile
.getPath().equalsIgnoreCase(packageId
.getSpdFile().getPath())) {
173 return fdb
.getPackageList().getFilenameArray(index
).getFarGuid();
180 public String
getPlatformFarGuid(PlatformIdentification platformId
) {
183 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
184 DbPathAndFilename item
= fdb
.getPlatformList().getFilenameArray(index
);
185 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
186 + item
.getStringValue();
187 File tempFile
= new File(path
);
188 if (tempFile
.getPath().equalsIgnoreCase(platformId
.getFpdFile().getPath())) {
189 return fdb
.getPlatformList().getFilenameArray(index
).getFarGuid();
196 public String
getModuleFarGuid(ModuleIdentification moduleId
) {
197 PackageIdentification packageId
= getPackageIdByModuleId(moduleId
);
198 if (packageId
!= null) {
199 return getPackageFarGuid(packageId
);
206 Get all modules' paths from one package
208 @return a Vector with all modules' path
211 public Vector
<String
> getAllModulesOfPackage(String path
) {
212 Vector
<String
> modulePath
= new Vector
<String
>();
214 MsaFiles files
= OpenFile
.openSpdFile(path
).getMsaFiles();
216 for (int index
= 0; index
< files
.getFilenameList().size(); index
++) {
217 String msaPath
= files
.getFilenameList().get(index
);
218 msaPath
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + msaPath
;
219 msaPath
= Tools
.convertPathToCurrentOsType(msaPath
);
220 modulePath
.addElement(msaPath
);
223 } catch (IOException e
) {
225 } catch (XmlException e
) {
227 } catch (Exception e
) {
234 Get all Industry Std Includes' paths from one package
236 @return a Vector with all paths
239 public Vector
<String
> getAllIndustryStdIncludesOfPackage(String path
) {
240 Vector
<String
> includePath
= new Vector
<String
>();
242 IndustryStdIncludes files
= OpenFile
.openSpdFile(path
).getIndustryStdIncludes();
244 for (int index
= 0; index
< files
.getIndustryStdHeaderList().size(); index
++) {
245 String temp
= files
.getIndustryStdHeaderList().get(index
).getName();
246 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
247 temp
= Tools
.convertPathToCurrentOsType(temp
);
248 includePath
.addElement(temp
);
251 } catch (IOException e
) {
253 } catch (XmlException e
) {
255 } catch (Exception e
) {
262 Get all package basic information form the FrameworkDatabase.db file
264 @return vPackageList A vector includes all packages' basic information
267 public Vector
<PackageIdentification
> getAllPackages() {
268 Identification id
= null;
269 vPackageList
.removeAllElements();
273 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
274 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
275 + fdb
.getPackageList().getFilenameArray(index
).getStringValue();
276 path
= Tools
.convertPathToCurrentOsType(path
);
278 id
= getId(path
, OpenFile
.openSpdFile(path
));
279 vPackageList
.addElement(new PackageIdentification(id
));
280 } catch (IOException e
) {
281 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
283 } catch (XmlException e
) {
284 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
286 } catch (Exception e
) {
287 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
291 Tools
.sortPackages(vPackageList
, DataType
.SORT_TYPE_ASCENDING
);
295 public Vector
<FarIdentification
> getAllFars() {
297 Vector
<FarIdentification
> v
= new Vector
<FarIdentification
>();
298 for (int index
= 0; index
< fdb
.getFarList().getFilenameList().size(); index
++) {
299 DbPathAndFilename item
= fdb
.getFarList().getFilenameList().get(index
);
300 FarIdentification far
= new FarIdentification(item
.getFarGuid(), item
.getMd5Sum(), item
.getStringValue());
306 public Vector
<PackageIdentification
> getPackagesByFar(FarIdentification far
) {
307 Identification id
= null;
309 Vector
<PackageIdentification
> v
= new Vector
<PackageIdentification
>();
311 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
312 DbPathAndFilename item
= fdb
.getPackageList().getFilenameArray(index
);
313 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
314 + item
.getStringValue();
315 path
= Tools
.convertPathToCurrentOsType(path
);
317 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
320 id
= getId(path
, OpenFile
.openSpdFile(path
));
321 v
.addElement(new PackageIdentification(id
));
322 } catch (IOException e
) {
323 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
325 } catch (XmlException e
) {
326 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
328 } catch (Exception e
) {
329 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
337 public Vector
<PlatformIdentification
> getPlatformsByFar(FarIdentification far
) {
338 Identification id
= null;
340 Vector
<PlatformIdentification
> v
= new Vector
<PlatformIdentification
>();
342 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
343 DbPathAndFilename item
= fdb
.getPlatformList().getFilenameArray(index
);
344 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
345 + item
.getStringValue();
346 path
= Tools
.convertPathToCurrentOsType(path
);
348 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
350 id
= getId(path
, OpenFile
.openFpdFile(path
));
351 v
.addElement(new PlatformIdentification(id
));
352 } catch (IOException e
) {
353 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
355 } catch (XmlException e
) {
356 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
358 } catch (Exception e
) {
359 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
368 Get all module basic information from a package
371 @return A vector includes all modules' basic information
374 public Vector
<ModuleIdentification
> getAllModules(PackageIdentification pid
) {
375 Vector
<ModuleIdentification
> v
= new Vector
<ModuleIdentification
>();
376 Vector
<String
> modulePaths
= this.getAllModulesOfPackage(pid
.getPath());
377 Identification id
= null;
378 String modulePath
= null;
380 for (int index
= 0; index
< modulePaths
.size(); index
++) {
382 modulePath
= modulePaths
.get(index
);
383 id
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
384 } catch (IOException e
) {
385 Log
.log("Error when Open Module Surface Area " + modulePath
, e
.getMessage());
386 } catch (XmlException e
) {
387 Log
.log("Error when Open Module Surface Area " + modulePath
, e
.getMessage());
388 } catch (Exception e
) {
389 Log
.log("Error when Open Module Surface Area " + modulePath
, "Invalid file type " + e
.getMessage());
391 v
.addElement(new ModuleIdentification(id
, pid
));
393 Tools
.sortModules(v
, DataType
.SORT_TYPE_ASCENDING
);
399 Get all module basic information form the FrameworkDatabase.db file
401 @return vModuleList A vector includes all modules' basic information
404 public Vector
<ModuleIdentification
> getAllModules() {
405 vModuleList
.removeAllElements();
407 // First get all packages
410 Vector
<String
> modulePaths
= new Vector
<String
>();
411 Identification id
= null;
412 String packagePath
= null;
413 String modulePath
= null;
416 // For each package, get all modules list
418 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
419 packagePath
= vPackageList
.elementAt(indexI
).getPath();
420 modulePaths
= this.getAllModulesOfPackage(packagePath
);
422 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
424 modulePath
= modulePaths
.get(indexJ
);
425 id
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
426 vModuleList
.addElement(new ModuleIdentification(id
, vPackageList
.elementAt(indexI
)));
427 } catch (IOException e
) {
428 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
429 } catch (XmlException e
) {
430 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
431 } catch (Exception e
) {
432 Log
.err("Open Module Surface Area " + modulePath
, "Invalid file type");
436 Tools
.sortModules(vModuleList
, DataType
.SORT_TYPE_ASCENDING
);
441 Get all platform basic information form the FrameworkDatabase.db file
443 @return vplatformList A vector includes all platforms' basic information
446 public Vector
<PlatformIdentification
> getAllPlatforms() {
447 Identification id
= null;
448 vPlatformList
.removeAllElements();
452 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
453 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
454 + fdb
.getPlatformList().getFilenameArray(index
).getStringValue();
455 path
= Tools
.convertPathToCurrentOsType(path
);
457 id
= getId(path
, OpenFile
.openFpdFile(path
));
458 vPlatformList
.addElement(new PlatformIdentification(id
));
459 } catch (IOException e
) {
460 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
461 } catch (XmlException e
) {
462 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
463 } catch (Exception e
) {
464 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
467 Tools
.sortPlatforms(vPlatformList
, DataType
.SORT_TYPE_ASCENDING
);
468 return vPlatformList
;
472 Get all Library Class Definitions from a package
476 public Vector
<String
> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd
) {
477 Vector
<String
> vector
= new Vector
<String
>();
478 if (spd
.getLibraryClassDeclarations() != null) {
479 if (spd
.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {
480 for (int index
= 0; index
< spd
.getLibraryClassDeclarations().getLibraryClassList().size(); index
++) {
481 vector
.addElement(spd
.getLibraryClassDeclarations().getLibraryClassList().get(index
).getName());
485 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
490 Get all Protocol Definitions from a package
494 public Vector
<String
> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd
) {
495 Vector
<String
> vector
= new Vector
<String
>();
496 if (spd
.getProtocolDeclarations() != null) {
497 if (spd
.getProtocolDeclarations().getEntryList().size() > 0) {
498 for (int index
= 0; index
< spd
.getProtocolDeclarations().getEntryList().size(); index
++) {
499 vector
.addElement(spd
.getProtocolDeclarations().getEntryList().get(index
).getCName());
503 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
508 Get all Ppi Definitions from a package
512 public Vector
<String
> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd
) {
513 Vector
<String
> vector
= new Vector
<String
>();
514 if (spd
.getPpiDeclarations() != null) {
515 if (spd
.getPpiDeclarations().getEntryList().size() > 0) {
516 for (int index
= 0; index
< spd
.getPpiDeclarations().getEntryList().size(); index
++) {
517 vector
.addElement(spd
.getPpiDeclarations().getEntryList().get(index
).getCName());
521 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
526 Get all Guid Definitions from a package
530 public Vector
<String
> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd
) {
531 Vector
<String
> vector
= new Vector
<String
>();
532 if (spd
.getGuidDeclarations() != null) {
533 if (spd
.getGuidDeclarations().getEntryList().size() > 0) {
534 for (int index
= 0; index
< spd
.getGuidDeclarations().getEntryList().size(); index
++) {
535 vector
.addElement(spd
.getGuidDeclarations().getEntryList().get(index
).getCName());
539 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
544 Get all Pcd Definitions from a package
548 public Vector
<String
> getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd
) {
549 Vector
<String
> vector
= new Vector
<String
>();
550 if (spd
.getPcdDeclarations() != null) {
551 if (spd
.getPcdDeclarations().getPcdEntryList().size() > 0) {
552 for (int index
= 0; index
< spd
.getPcdDeclarations().getPcdEntryList().size(); index
++) {
553 vector
.addElement(spd
.getPcdDeclarations().getPcdEntryList().get(index
).getCName());
557 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
561 public Vector
<String
> getAllLibraryClassDefinitionsFromWorkspace() {
563 // First get all packages
565 this.getAllPackages();
567 Vector
<String
> vector
= new Vector
<String
>();
568 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
570 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(OpenFile
571 .openSpdFile(vPackageList
574 if (v
!= null && v
.size() > 0) {
577 } catch (IOException e
) {
578 // TODO Auto-generated catch block
579 } catch (XmlException e
) {
580 // TODO Auto-generated catch block
581 } catch (Exception e
) {
582 // TODO Auto-generated catch block
585 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
589 public Vector
<String
> getAllProtocolDeclarationsFromWorkspace() {
591 // First get all packages
593 this.getAllPackages();
595 Vector
<String
> vector
= new Vector
<String
>();
596 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
598 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
600 if (v
!= null && v
.size() > 0) {
603 } catch (IOException e
) {
604 // TODO Auto-generated catch block
605 } catch (XmlException e
) {
606 // TODO Auto-generated catch block
607 } catch (Exception e
) {
608 // TODO Auto-generated catch block
611 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
615 public Vector
<String
> getAllPpiDeclarationsFromWorkspace() {
617 // First get all packages
619 this.getAllPackages();
621 Vector
<String
> vector
= new Vector
<String
>();
622 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
624 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
626 if (v
!= null && v
.size() > 0) {
629 } catch (IOException e
) {
630 // TODO Auto-generated catch block
631 } catch (XmlException e
) {
632 // TODO Auto-generated catch block
633 } catch (Exception e
) {
634 // TODO Auto-generated catch block
637 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
641 public Vector
<String
> getAllGuidDeclarationsFromWorkspace() {
643 // First get all packages
645 this.getAllPackages();
647 Vector
<String
> vector
= new Vector
<String
>();
648 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
650 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
652 if (v
!= null && v
.size() > 0) {
655 } catch (IOException e
) {
656 // TODO Auto-generated catch block
657 } catch (XmlException e
) {
658 // TODO Auto-generated catch block
659 } catch (Exception e
) {
660 // TODO Auto-generated catch block
663 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
667 public Vector
<String
> getAllPcdDeclarationsFromWorkspace() {
669 // First get all packages
671 this.getAllPackages();
673 Vector
<String
> vector
= new Vector
<String
>();
674 for (int index
= 0; index
< this.vPackageList
.size(); index
++) {
676 Vector
<String
> v
= getAllPcdDeclarationsFromPackage(OpenFile
.openSpdFile(vPackageList
.get(index
)
678 if (v
!= null && v
.size() > 0) {
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
689 Tools
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
694 Find a module's package's id
696 @param id input module id
700 public PackageIdentification
getPackageIdByModuleId(Identification id
) {
702 Vector
<String
> modulePaths
= new Vector
<String
>();
703 Identification mid
= null;
704 String packagePath
= null;
705 String modulePath
= null;
708 // For each package, get all modules list
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
);
716 mid
= getId(modulePath
, OpenFile
.openMsaFile(modulePath
));
720 if (mid
.equals(id
)) {
721 return vPackageList
.elementAt(indexI
);
723 } catch (IOException e
) {
725 } catch (XmlException e
) {
727 } catch (Exception e
) {
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
);
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
);
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
);
764 Add module information to package surface area
772 public void addModuleToPackage(ModuleIdentification mid
, PackageSurfaceArea spd
) throws IOException
, XmlException
,
774 String packagePath
= mid
.getPackageId().getPath();
775 String modulePath
= mid
.getPath();
777 spd
= OpenFile
.openSpdFile(packagePath
);
779 MsaFiles msaFile
= spd
.getMsaFiles();
780 if (msaFile
== null) {
781 msaFile
= MsaFiles
.Factory
.newInstance();
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
);
792 Add input package into database
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
);
812 Add input package into database
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
);
832 Get all file's path from one module
841 public Vector
<String
> getAllModuleFilesPath(String path
) throws IOException
, XmlException
, Exception
{
842 Vector
<String
> v
= new Vector
<String
>();
843 path
= Tools
.convertPathToCurrentOsType(path
);
845 ModuleSurfaceArea msa
= OpenFile
.openMsaFile(path
);
848 // Get all files' path of a module
850 SourceFiles sf
= msa
.getSourceFiles();
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
));
864 Get all file's path from one package
873 public Vector
<String
> getAllPakcageFilesPath(String path
) throws IOException
, XmlException
, Exception
{
874 Vector
<String
> v
= new Vector
<String
>();
875 path
= Tools
.convertPathToCurrentOsType(path
);
882 // Add the package's industry std includes one by one
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
));
891 // Add module's files one by one
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
));