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
.IndustryStdIncludesDocument
.IndustryStdIncludes
;
26 import org
.tianocore
.LibraryClassDeclarationsDocument
.LibraryClassDeclarations
;
27 import org
.tianocore
.LibraryClassDefinitionsDocument
.LibraryClassDefinitions
;
28 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
29 import org
.tianocore
.MsaFilesDocument
.MsaFiles
;
30 import org
.tianocore
.PackageDependenciesDocument
.PackageDependencies
;
31 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
32 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
33 import org
.tianocore
.SourceFilesDocument
.SourceFiles
;
34 import org
.tianocore
.frameworkwizard
.common
.DataType
;
35 import org
.tianocore
.frameworkwizard
.common
.GlobalData
;
36 import org
.tianocore
.frameworkwizard
.common
.Log
;
37 import org
.tianocore
.frameworkwizard
.common
.OpenFile
;
38 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
39 import org
.tianocore
.frameworkwizard
.common
.Sort
;
40 import org
.tianocore
.frameworkwizard
.common
.Tools
;
41 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
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 public void addFarToDb(List
<String
> packageList
, List
<String
> platformList
, FarHeader far
) {
53 //FrameworkDatabase fdb = openFrameworkDb();
55 for (int i
= 0; i
< packageList
.size(); i
++) {
56 DbPathAndFilename item
= DbPathAndFilename
.Factory
.newInstance();
57 item
.setFarGuid(far
.getGuidValue());
58 item
.setStringValue(packageList
.get(i
));
59 GlobalData
.fdb
.getPackageList().getFilenameList().add(item
);
62 for (int i
= 0; i
< platformList
.size(); i
++) {
63 DbPathAndFilename item
= DbPathAndFilename
.Factory
.newInstance();
64 item
.setFarGuid(far
.getGuidValue());
65 item
.setStringValue(platformList
.get(i
));
66 GlobalData
.fdb
.getPlatformList().getFilenameList().add(item
);
69 DbPathAndFilename farItem
= DbPathAndFilename
.Factory
.newInstance();
70 farItem
.setFarGuid(far
.getGuidValue());
71 farItem
.setStringValue(far
.getFarName());
72 GlobalData
.fdb
.getFarList().getFilenameList().add(farItem
);
74 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
75 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
78 SaveFile
.saveDbFile(strFrameworkDbFilePath
, GlobalData
.fdb
);
79 } catch (Exception e
) {
80 Log
.err("Save Database File", e
.getMessage());
84 public void removeFarFromDb(FarIdentification far
) {
88 XmlCursor cursor
= GlobalData
.fdb
.getPackageList().newCursor();
89 cursor
.toFirstChild();
91 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
93 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
96 } while (cursor
.toNextSibling());
102 cursor
= GlobalData
.fdb
.getPlatformList().newCursor();
103 cursor
.toFirstChild();
105 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
106 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
109 } while (cursor
.toNextSibling());
114 cursor
= GlobalData
.fdb
.getFarList().newCursor();
115 cursor
.toFirstChild();
117 DbPathAndFilename item
= (DbPathAndFilename
) cursor
.getObject();
118 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
121 } while (cursor
.toNextSibling());
124 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
125 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
127 SaveFile
.saveDbFile(strFrameworkDbFilePath
, GlobalData
.fdb
);
128 } catch (Exception e
) {
129 Log
.err("Save Database File", e
.getMessage());
133 public String
getPackageFarGuid(Identification packageId
) {
134 for (int index
= 0; index
< GlobalData
.fdb
.getPackageList().getFilenameList().size(); index
++) {
135 DbPathAndFilename item
= GlobalData
.fdb
.getPackageList().getFilenameArray(index
);
136 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
137 File tempFile
= new File(path
);
138 if (tempFile
.getPath().equalsIgnoreCase(packageId
.getPath())) {
139 return GlobalData
.fdb
.getPackageList().getFilenameArray(index
).getFarGuid();
146 public String
getPlatformFarGuid(Identification platformId
) {
147 for (int index
= 0; index
< GlobalData
.fdb
.getPlatformList().getFilenameList().size(); index
++) {
148 DbPathAndFilename item
= GlobalData
.fdb
.getPlatformList().getFilenameArray(index
);
149 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
150 File tempFile
= new File(path
);
151 if (tempFile
.getPath().equalsIgnoreCase(platformId
.getPath())) {
152 return GlobalData
.fdb
.getPlatformList().getFilenameArray(index
).getFarGuid();
159 public String
getModuleFarGuid(Identification moduleId
) {
160 PackageIdentification packageId
= getPackageIdByModuleId(moduleId
);
161 if (packageId
!= null) {
162 return getPackageFarGuid(packageId
);
169 Get all modules' paths from one package
171 @return a Vector with all modules' path
174 public Vector
<String
> getAllModulesOfPackage(String path
) {
175 Vector
<String
> modulePath
= new Vector
<String
>();
176 PackageIdentification id
= new PackageIdentification(null, null, null, path
);
177 MsaFiles files
= GlobalData
.openingPackageList
.getPackageSurfaceAreaFromId(id
).getMsaFiles();
179 for (int index
= 0; index
< files
.getFilenameList().size(); index
++) {
180 String msaPath
= files
.getFilenameList().get(index
);
181 msaPath
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + msaPath
;
182 msaPath
= Tools
.convertPathToCurrentOsType(msaPath
);
183 modulePath
.addElement(msaPath
);
191 Get all Industry Std Includes' paths from one package
193 @return a Vector with all paths
196 public Vector
<String
> getAllIndustryStdIncludesOfPackage(String path
) {
197 Vector
<String
> includePath
= new Vector
<String
>();
198 PackageIdentification id
= new PackageIdentification(null, null, null, path
);
199 IndustryStdIncludes files
= GlobalData
.openingPackageList
.getPackageSurfaceAreaFromId(id
)
200 .getIndustryStdIncludes();
202 for (int index
= 0; index
< files
.getIndustryStdHeaderList().size(); index
++) {
203 String temp
= files
.getIndustryStdHeaderList().get(index
).getIncludeHeader();
204 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
205 temp
= Tools
.convertPathToCurrentOsType(temp
);
206 includePath
.addElement(temp
);
213 Get all package basic information form the FrameworkDatabase.db file
215 @return vPackageList A vector includes all packages' basic information
218 public Vector
<PackageIdentification
> getAllPackages() {
219 return GlobalData
.vPackageList
;
222 public Vector
<FarIdentification
> getAllFars() {
224 Vector
<FarIdentification
> v
= new Vector
<FarIdentification
>();
225 for (int index
= 0; index
< GlobalData
.fdb
.getFarList().getFilenameList().size(); index
++) {
226 DbPathAndFilename item
= GlobalData
.fdb
.getFarList().getFilenameList().get(index
);
227 FarIdentification far
= new FarIdentification(item
.getFarGuid(), item
.getMd5Sum(), item
.getStringValue());
233 public Vector
<PackageIdentification
> getPackagesByFar(FarIdentification far
) {
234 Identification id
= null;
236 Vector
<PackageIdentification
> v
= new Vector
<PackageIdentification
>();
238 for (int index
= 0; index
< GlobalData
.fdb
.getPackageList().getFilenameList().size(); index
++) {
239 DbPathAndFilename item
= GlobalData
.fdb
.getPackageList().getFilenameArray(index
);
240 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
241 path
= Tools
.convertPathToCurrentOsType(path
);
243 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
246 id
= Tools
.getId(path
, OpenFile
.openSpdFile(path
));
247 v
.addElement(new PackageIdentification(id
));
248 } catch (IOException e
) {
249 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
250 } catch (XmlException e
) {
251 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
252 } catch (Exception e
) {
253 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
260 public Vector
<PlatformIdentification
> getPlatformsByFar(FarIdentification far
) {
261 Identification id
= null;
263 Vector
<PlatformIdentification
> v
= new Vector
<PlatformIdentification
>();
265 for (int index
= 0; index
< GlobalData
.fdb
.getPlatformList().getFilenameList().size(); index
++) {
266 DbPathAndFilename item
= GlobalData
.fdb
.getPlatformList().getFilenameArray(index
);
267 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ item
.getStringValue();
268 path
= Tools
.convertPathToCurrentOsType(path
);
270 if (item
.getFarGuid() != null && item
.getFarGuid().equalsIgnoreCase(far
.getGuid())) {
272 id
= Tools
.getId(path
, OpenFile
.openFpdFile(path
));
273 v
.addElement(new PlatformIdentification(id
));
274 } catch (IOException e
) {
275 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
276 } catch (XmlException e
) {
277 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
278 } catch (Exception e
) {
279 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
287 Get all module basic information from a package
290 @return A vector includes all modules' basic information
293 public Vector
<ModuleIdentification
> getAllModules(PackageIdentification pid
) {
294 Vector
<ModuleIdentification
> v
= new Vector
<ModuleIdentification
>();
295 Vector
<String
> modulePaths
= this.getAllModulesOfPackage(pid
.getPath());
296 String modulePath
= null;
298 for (int index
= 0; index
< modulePaths
.size(); index
++) {
299 modulePath
= modulePaths
.get(index
);
300 ModuleIdentification id
= GlobalData
.openingModuleList
.getIdByPath(modulePath
);
305 Sort
.sortModules(v
, DataType
.SORT_TYPE_ASCENDING
);
310 Get all module basic information from a platform
313 @return A vector includes all modules' basic information
316 public Vector
<ModuleIdentification
> getAllModules(PlatformIdentification fid
) {
317 Vector
<ModuleIdentification
> v
= new Vector
<ModuleIdentification
>();
318 PlatformSurfaceArea fpd
= GlobalData
.openingPlatformList
.getOpeningPlatformById(fid
).getXmlFpd();
319 if (fpd
.getFrameworkModules() != null) {
320 for (int index
= 0; index
< fpd
.getFrameworkModules().getModuleSAList().size(); index
++) {
321 String guid
= fpd
.getFrameworkModules().getModuleSAList().get(index
).getModuleGuid();
322 String version
= fpd
.getFrameworkModules().getModuleSAList().get(index
).getModuleVersion();
323 ModuleIdentification id
= GlobalData
.openingModuleList
.getIdByGuidVersion(guid
, version
);
325 boolean isFind
= false;
326 for (int indexOfModules
= 0; indexOfModules
< v
.size(); indexOfModules
++) {
327 if (v
.elementAt(indexOfModules
).equals(id
)) {
338 Sort
.sortModules(v
, DataType
.SORT_TYPE_ASCENDING
);
343 Get all module basic information form the FrameworkDatabase.db file
345 @return vModuleList A vector includes all modules' basic information
348 public Vector
<ModuleIdentification
> getAllModules() {
349 return GlobalData
.vModuleList
;
353 Get all platform basic information form the FrameworkDatabase.db file
355 @return vplatformList A vector includes all platforms' basic information
358 public Vector
<PlatformIdentification
> getAllPlatforms() {
359 return GlobalData
.vPlatformList
;
363 Get all Library Class Definitions from a package
367 public Vector
<String
> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd
) {
368 Vector
<String
> vector
= new Vector
<String
>();
369 if (spd
.getLibraryClassDeclarations() != null) {
370 if (spd
.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {
371 for (int index
= 0; index
< spd
.getLibraryClassDeclarations().getLibraryClassList().size(); index
++) {
372 vector
.addElement(spd
.getLibraryClassDeclarations().getLibraryClassList().get(index
).getName());
376 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
381 Get all Protocol Definitions from a package
385 public Vector
<String
> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd
) {
386 Vector
<String
> vector
= new Vector
<String
>();
387 if (spd
.getProtocolDeclarations() != null) {
388 if (spd
.getProtocolDeclarations().getEntryList().size() > 0) {
389 for (int index
= 0; index
< spd
.getProtocolDeclarations().getEntryList().size(); index
++) {
390 vector
.addElement(spd
.getProtocolDeclarations().getEntryList().get(index
).getCName());
394 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
399 Get all Ppi Definitions from a package
403 public Vector
<String
> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd
) {
404 Vector
<String
> vector
= new Vector
<String
>();
405 if (spd
.getPpiDeclarations() != null) {
406 if (spd
.getPpiDeclarations().getEntryList().size() > 0) {
407 for (int index
= 0; index
< spd
.getPpiDeclarations().getEntryList().size(); index
++) {
408 vector
.addElement(spd
.getPpiDeclarations().getEntryList().get(index
).getCName());
412 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
417 Get all Guid Definitions from a package
421 public Vector
<String
> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd
, String type
) {
422 Vector
<String
> vector
= new Vector
<String
>();
423 boolean isFound
= false;
424 if (spd
.getGuidDeclarations() != null) {
425 if (spd
.getGuidDeclarations().getEntryList().size() > 0) {
426 for (int index
= 0; index
< spd
.getGuidDeclarations().getEntryList().size(); index
++) {
427 Vector
<String
> vArch
= Tools
.convertListToVector(spd
.getGuidDeclarations().getEntryList()
428 .get(index
).getGuidTypeList());
429 for (int indexOfArch
= 0; indexOfArch
< vArch
.size(); indexOfArch
++) {
430 if (vArch
.get(indexOfArch
).equals(type
)) {
435 if ((isFound
) || (vArch
== null) || (vArch
.size() < 1)) {
436 vector
.addElement(spd
.getGuidDeclarations().getEntryList().get(index
).getCName());
442 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
447 Get all Pcd Definitions from a package
451 public PcdVector
getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd
) {
452 PcdVector vector
= new PcdVector();
453 if (spd
.getPcdDeclarations() != null) {
454 if (spd
.getPcdDeclarations().getPcdEntryList().size() > 0) {
455 for (int index
= 0; index
< spd
.getPcdDeclarations().getPcdEntryList().size(); index
++) {
456 String name
= spd
.getPcdDeclarations().getPcdEntryList().get(index
).getCName();
457 String guidCName
= spd
.getPcdDeclarations().getPcdEntryList().get(index
).getTokenSpaceGuidCName();
458 String help
= spd
.getPcdDeclarations().getPcdEntryList().get(index
).getHelpText();
459 Vector
<String
> type
= Tools
.convertListToVector(spd
.getPcdDeclarations().getPcdEntryList()
460 .get(index
).getValidUsage());
462 vector
.addPcd(new PcdIdentification(name
, guidCName
, help
, type
));
466 Sort
.sortPcds(vector
, DataType
.SORT_TYPE_ASCENDING
);
470 public Vector
<String
> getAllLibraryClassDefinitionsFromWorkspace() {
471 Vector
<String
> vector
= new Vector
<String
>();
472 for (int index
= 0; index
< GlobalData
.vPackageList
.size(); index
++) {
473 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(GlobalData
.openingPackageList
474 .getPackageSurfaceAreaFromId(GlobalData
.vPackageList
476 if (v
!= null && v
.size() > 0) {
481 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
485 public Vector
<String
> getAllLibraryClassDefinitionsFromPackages(Vector
<PackageIdentification
> vpid
) {
486 Vector
<String
> vector
= new Vector
<String
>();
487 for (int index
= 0; index
< vpid
.size(); index
++) {
488 Vector
<String
> v
= getAllLibraryClassDefinitionsFromPackage(GlobalData
.openingPackageList
489 .getPackageSurfaceAreaFromId(vpid
491 if (v
!= null && v
.size() > 0) {
496 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
500 public Vector
<String
> getAllProtocolDeclarationsFromWorkspace() {
501 Vector
<String
> vector
= new Vector
<String
>();
502 for (int index
= 0; index
< GlobalData
.vPackageList
.size(); index
++) {
503 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(GlobalData
.openingPackageList
504 .getPackageSurfaceAreaFromId(GlobalData
.vPackageList
506 if (v
!= null && v
.size() > 0) {
510 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
514 public Vector
<String
> getAllProtocolDeclarationsFromPackages(Vector
<PackageIdentification
> vpid
) {
515 Vector
<String
> vector
= new Vector
<String
>();
516 for (int index
= 0; index
< vpid
.size(); index
++) {
517 Vector
<String
> v
= getAllProtocolDeclarationsFromPackage(GlobalData
.openingPackageList
518 .getPackageSurfaceAreaFromId(vpid
520 if (v
!= null && v
.size() > 0) {
524 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
528 public Vector
<String
> getAllPpiDeclarationsFromWorkspace() {
529 Vector
<String
> vector
= new Vector
<String
>();
530 for (int index
= 0; index
< GlobalData
.vPackageList
.size(); index
++) {
531 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(GlobalData
.openingPackageList
532 .getPackageSurfaceAreaFromId(GlobalData
.vPackageList
534 if (v
!= null && v
.size() > 0) {
538 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
542 public Vector
<String
> getAllPpiDeclarationsFromPackages(Vector
<PackageIdentification
> vpid
) {
543 Vector
<String
> vector
= new Vector
<String
>();
544 for (int index
= 0; index
< vpid
.size(); index
++) {
545 Vector
<String
> v
= getAllPpiDeclarationsFromPackage(GlobalData
.openingPackageList
546 .getPackageSurfaceAreaFromId(vpid
548 if (v
!= null && v
.size() > 0) {
552 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
556 public Vector
<String
> getAllGuidDeclarationsFromWorkspace(String type
) {
557 Vector
<String
> vector
= new Vector
<String
>();
558 for (int index
= 0; index
< GlobalData
.vPackageList
.size(); index
++) {
559 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(
560 GlobalData
.openingPackageList
561 .getPackageSurfaceAreaFromId(GlobalData
.vPackageList
564 if (v
!= null && v
.size() > 0) {
569 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
573 public Vector
<String
> getAllGuidDeclarationsFromPackages(Vector
<PackageIdentification
> vpid
, String type
) {
574 Vector
<String
> vector
= new Vector
<String
>();
575 for (int index
= 0; index
< vpid
.size(); index
++) {
576 Vector
<String
> v
= getAllGuidDeclarationsFromPackage(
577 GlobalData
.openingPackageList
578 .getPackageSurfaceAreaFromId(vpid
581 if (v
!= null && v
.size() > 0) {
586 Sort
.sortVectorString(vector
, DataType
.SORT_TYPE_ASCENDING
);
590 public PcdVector
getAllPcdDeclarationsFromWorkspace() {
591 PcdVector vector
= new PcdVector();
592 for (int index
= 0; index
< GlobalData
.openingPackageList
.size(); index
++) {
593 PcdVector v
= getAllPcdDeclarationsFromPackage(GlobalData
.openingPackageList
594 .getPackageSurfaceAreaFromId(GlobalData
.vPackageList
596 if (v
!= null && v
.size() > 0) {
601 Sort
.sortPcds(vector
, DataType
.SORT_TYPE_ASCENDING
);
605 public PcdVector
getAllPcdDeclarationsFromPackages(Vector
<PackageIdentification
> vpid
) {
606 PcdVector vector
= new PcdVector();
607 for (int index
= 0; index
< vpid
.size(); index
++) {
608 PcdVector v
= getAllPcdDeclarationsFromPackage(GlobalData
.openingPackageList
609 .getPackageSurfaceAreaFromId(vpid
611 if (v
!= null && v
.size() > 0) {
616 Sort
.sortPcds(vector
, DataType
.SORT_TYPE_ASCENDING
);
621 Find a module's package's id
623 @param id input module id
627 public PackageIdentification
getPackageIdByModuleId(Identification id
) {
628 Vector
<String
> modulePaths
= new Vector
<String
>();
629 Identification mid
= null;
630 String packagePath
= null;
631 String modulePath
= null;
634 // For each package, get all modules list
636 for (int indexI
= 0; indexI
< GlobalData
.vPackageList
.size(); indexI
++) {
637 packagePath
= GlobalData
.vPackageList
.elementAt(indexI
).getPath();
638 modulePaths
= this.getAllModulesOfPackage(packagePath
);
639 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
640 modulePath
= modulePaths
.get(indexJ
);
641 mid
= GlobalData
.openingModuleList
.getIdByPath(modulePath
);
645 if (mid
.equals(id
)) {
646 return GlobalData
.vPackageList
.elementAt(indexI
);
656 Add module information to package surface area
664 public void addModuleToPackage(ModuleIdentification mid
, PackageSurfaceArea spd
) throws IOException
, XmlException
,
666 String packagePath
= mid
.getPackageId().getPath();
667 String modulePath
= mid
.getPath();
669 spd
= OpenFile
.openSpdFile(packagePath
);
671 MsaFiles msaFile
= spd
.getMsaFiles();
672 if (msaFile
== null) {
673 msaFile
= MsaFiles
.Factory
.newInstance();
675 packagePath
= packagePath
.substring(0, packagePath
.lastIndexOf(DataType
.FILE_SEPARATOR
));
676 String fn
= Tools
.getRelativePath(modulePath
, packagePath
);
677 msaFile
.addNewFilename();
678 msaFile
.setFilenameArray(msaFile
.getFilenameList().size() - 1, fn
);
679 spd
.setMsaFiles(msaFile
);
680 SaveFile
.saveSpdFile(mid
.getPackageId().getPath(), spd
);
684 GlobalData
.openingPackageList
.getPackageSurfaceAreaFromId(mid
.getPackageId()).setMsaFiles(msaFile
);
688 Add input package into database
694 public void addPackageToDatabase(PackageIdentification id
) throws Exception
{
695 String path
= id
.getPath();
696 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
698 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
699 filename
.setStringValue(path
);
700 GlobalData
.fdb
.getPackageList().addNewFilename();
701 GlobalData
.fdb
.getPackageList().setFilenameArray(GlobalData
.fdb
.getPackageList().sizeOfFilenameArray() - 1,
703 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
704 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
705 SaveFile
.saveDbFile(strFrameworkDbFilePath
, GlobalData
.fdb
);
709 Add input package into database
715 public void addPlatformToDatabase(PlatformIdentification id
) throws Exception
{
716 String path
= id
.getPath();
717 path
= Tools
.getRelativePath(path
, Workspace
.getCurrentWorkspace());
719 DbPathAndFilename filename
= DbPathAndFilename
.Factory
.newInstance();
720 filename
.setStringValue(path
);
721 GlobalData
.fdb
.getPlatformList().addNewFilename();
722 GlobalData
.fdb
.getPlatformList().setFilenameArray(GlobalData
.fdb
.getPlatformList().sizeOfFilenameArray() - 1,
724 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
725 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
726 SaveFile
.saveDbFile(strFrameworkDbFilePath
, GlobalData
.fdb
);
730 Get all file's path from one module
739 public Vector
<String
> getAllFilesPathOfModule(String path
) {
740 Vector
<String
> v
= new Vector
<String
>();
741 path
= Tools
.convertPathToCurrentOsType(path
);
744 // First add msa file's path
748 ModuleSurfaceArea msa
= GlobalData
.openingModuleList
749 .getModuleSurfaceAreaFromId(GlobalData
.openingModuleList
752 // Get common defined files of module
756 // Get all files' path of a module
758 SourceFiles sf
= msa
.getSourceFiles();
760 for (int index
= 0; index
< sf
.getFilenameList().size(); index
++) {
761 String temp
= sf
.getFilenameList().get(index
).getStringValue();
762 temp
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + temp
;
763 v
.addElement(Tools
.convertPathToCurrentOsType(temp
));
769 // Get include header files for this module
771 if (msa
.getLibraryClassDefinitions() != null) {
772 LibraryClassDefinitions lcd
= msa
.getLibraryClassDefinitions();
773 for (int index
= 0; index
< lcd
.sizeOfLibraryClassArray(); index
++) {
774 if (lcd
.getLibraryClassList().get(index
).getUsage().toString()
775 .equals(DataType
.USAGE_TYPE_ALWAYS_PRODUCED
)
776 || lcd
.getLibraryClassList().get(index
).getUsage().toString()
777 .equals(DataType
.USAGE_TYPE_SOMETIMES_PRODUCED
)) {
779 // Get library class name
781 String name
= lcd
.getLibraryClassList().get(index
).getKeyword();
784 // Find file path for this class
786 PackageIdentification pid
= GlobalData
.openingModuleList
.getIdByPath(path
).getPackageId();
787 PackageSurfaceArea spd
= GlobalData
.openingPackageList
.getPackageSurfaceAreaFromId(pid
);
789 if (spd
.getLibraryClassDeclarations() != null) {
790 LibraryClassDeclarations lcdl
= spd
.getLibraryClassDeclarations();
791 for (int indexOfLibOfSpd
= 0; indexOfLibOfSpd
< lcdl
.sizeOfLibraryClassArray(); indexOfLibOfSpd
++) {
792 if (lcdl
.getLibraryClassList().get(indexOfLibOfSpd
).getName().equals(name
)) {
793 v
.addElement(Tools
.convertPathToCurrentOsType(Tools
.getFilePathOnly(pid
.getPath())
794 + DataType
.FILE_SEPARATOR
795 + lcdl
.getLibraryClassList()
796 .get(indexOfLibOfSpd
)
797 .getIncludeHeader()));
810 Get all file's path from one package
819 public Vector
<String
> getAllFilesPathOfPakcage(String path
) {
820 Vector
<String
> v
= new Vector
<String
>();
821 path
= Tools
.convertPathToCurrentOsType(path
);
828 // Add the package's industry std includes one by one
830 Vector
<String
> f1
= new Vector
<String
>();
831 f1
= getAllIndustryStdIncludesOfPackage(path
);
832 for (int index
= 0; index
< f1
.size(); index
++) {
833 v
.addElement(f1
.get(index
));
837 // Add module's files one by one
839 f1
= new Vector
<String
>();
840 f1
= getAllModulesOfPackage(path
);
841 for (int indexI
= 0; indexI
< f1
.size(); indexI
++) {
842 Vector
<String
> f2
= getAllFilesPathOfModule(f1
.get(indexI
));
843 for (int indexJ
= 0; indexJ
< f2
.size(); indexJ
++) {
844 v
.addElement(f2
.get(indexJ
));
852 Get a module's all package dependencies
854 @param mid The module id
855 @return A vector of all package dependency ids
858 public Vector
<PackageIdentification
> getPackageDependenciesOfModule(ModuleIdentification mid
) {
859 Vector
<PackageIdentification
> vpid
= new Vector
<PackageIdentification
>();
860 ModuleSurfaceArea msa
= GlobalData
.openingModuleList
.getModuleSurfaceAreaFromId(mid
);
862 PackageDependencies pd
= msa
.getPackageDependencies();
864 for (int index
= 0; index
< pd
.getPackageList().size(); index
++) {
865 String guid
= pd
.getPackageList().get(index
).getPackageGuid();
866 String version
= pd
.getPackageList().get(index
).getPackageVersion();
867 PackageIdentification pid
= GlobalData
.openingPackageList
.getIdByGuidVersion(guid
, version
);
869 vpid
.addElement(pid
);
877 public Vector
<String
> getAllModuleGuidXref() {
878 Vector
<String
> v
= new Vector
<String
>();
879 for (int index
= 0; index
< GlobalData
.openingModuleList
.size(); index
++) {
880 ModuleIdentification id
= GlobalData
.openingModuleList
.getOpeningModuleByIndex(index
).getId();
881 v
.addElement(id
.getGuid() + " " + id
.getName());
886 public Vector
<String
> getModuleArch(ModuleIdentification id
) {
887 Vector
<String
> v
= new Vector
<String
>();
888 ModuleSurfaceArea msa
= null;
890 msa
= GlobalData
.openingModuleList
.getModuleSurfaceAreaFromId(id
);
893 if (msa
.getModuleDefinitions() != null) {
894 v
= Tools
.convertListToVector(msa
.getModuleDefinitions().getSupportedArchitectures());