2 The file is used to provide initializing global data.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.frameworkwizard
.common
;
15 import java
.io
.IOException
;
16 import java
.util
.Vector
;
18 import org
.apache
.xmlbeans
.XmlException
;
19 import org
.tianocore
.FrameworkDatabaseDocument
.FrameworkDatabase
;
20 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
21 import org
.tianocore
.MsaFilesDocument
.MsaFiles
;
22 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
23 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
24 import org
.tianocore
.frameworkwizard
.common
.Identifications
.Identification
;
25 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleList
;
26 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningPackageList
;
27 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningPlatformList
;
28 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
29 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
30 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
31 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
33 public class GlobalData
{
35 public static FrameworkDatabase fdb
= null;
37 public static OpeningModuleList openingModuleList
= new OpeningModuleList();
39 public static OpeningPackageList openingPackageList
= new OpeningPackageList();
41 public static OpeningPlatformList openingPlatformList
= new OpeningPlatformList();
43 public static Vector
<ModuleIdentification
> vModuleList
= new Vector
<ModuleIdentification
>();
45 public static Vector
<PackageIdentification
> vPackageList
= new Vector
<PackageIdentification
>();
47 public static Vector
<PlatformIdentification
> vPlatformList
= new Vector
<PlatformIdentification
>();
49 public static void init() {
56 public static void initDatabase() {
57 String strFrameworkDbFilePath
= Workspace
.getCurrentWorkspace() + Workspace
.getStrWorkspaceDatabaseFile();
58 strFrameworkDbFilePath
= Tools
.convertPathToCurrentOsType(strFrameworkDbFilePath
);
60 fdb
= OpenFile
.openFrameworkDb(strFrameworkDbFilePath
);
61 } catch (XmlException e
) {
62 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, e
.getMessage());
64 } catch (Exception e
) {
65 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, "Invalid file type");
70 public static void initModule() {
71 vModuleList
= new Vector
<ModuleIdentification
>();
72 openingModuleList
= new OpeningModuleList();
74 ModuleSurfaceArea msa
= null;
75 Vector
<String
> modulePaths
= new Vector
<String
>();
76 Identification id
= null;
77 ModuleIdentification mid
= null;
78 String packagePath
= null;
79 String modulePath
= null;
82 // For each package, get all modules list
84 if (vPackageList
.size() > 0) {
85 for (int indexI
= 0; indexI
< vPackageList
.size(); indexI
++) {
86 packagePath
= vPackageList
.elementAt(indexI
).getPath();
87 modulePaths
= getAllModulesOfPackage(packagePath
);
89 for (int indexJ
= 0; indexJ
< modulePaths
.size(); indexJ
++) {
91 modulePath
= modulePaths
.get(indexJ
);
92 msa
= OpenFile
.openMsaFile(modulePath
);
94 } catch (IOException e
) {
95 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
97 } catch (XmlException e
) {
98 Log
.err("Open Module Surface Area " + modulePath
, e
.getMessage());
100 } catch (Exception e
) {
101 Log
.err("Open Module Surface Area " + modulePath
, "Invalid file type");
104 id
= Tools
.getId(modulePath
, msa
);
105 mid
= new ModuleIdentification(id
, vPackageList
.elementAt(indexI
));
106 vModuleList
.addElement(mid
);
107 openingModuleList
.insertToOpeningModuleList(mid
, msa
);
110 Sort
.sortModules(vModuleList
, DataType
.SORT_TYPE_ASCENDING
);
114 public static void initPackage() {
115 vPackageList
= new Vector
<PackageIdentification
>();
116 openingPackageList
= new OpeningPackageList();
118 for (int index
= 0; index
< fdb
.getPackageList().getFilenameList().size(); index
++) {
119 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
120 + fdb
.getPackageList().getFilenameArray(index
).getStringValue();
121 path
= Tools
.convertPathToCurrentOsType(path
);
122 PackageSurfaceArea spd
= null;
123 PackageIdentification id
= null;
125 spd
= OpenFile
.openSpdFile(path
);
126 } catch (IOException e
) {
127 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
129 } catch (XmlException e
) {
130 Log
.err("Open Package Surface Area " + path
, e
.getMessage());
132 } catch (Exception e
) {
133 Log
.err("Open Package Surface Area " + path
, "Invalid file type");
136 id
= Tools
.getId(path
, spd
);
137 vPackageList
.addElement(id
);
138 openingPackageList
.insertToOpeningPackageList(id
, spd
);
140 Sort
.sortPackages(vPackageList
, DataType
.SORT_TYPE_ASCENDING
);
144 public static void initPlatform() {
145 vPlatformList
= new Vector
<PlatformIdentification
>();
146 openingPlatformList
= new OpeningPlatformList();
149 for (int index
= 0; index
< fdb
.getPlatformList().getFilenameList().size(); index
++) {
150 String path
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
151 + fdb
.getPlatformList().getFilenameArray(index
).getStringValue();
152 path
= Tools
.convertPathToCurrentOsType(path
);
153 PlatformSurfaceArea fpd
= null;
154 PlatformIdentification id
= null;
156 fpd
= OpenFile
.openFpdFile(path
);
157 } catch (IOException e
) {
158 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
160 } catch (XmlException e
) {
161 Log
.err("Open Platform Surface Area " + path
, e
.getMessage());
163 } catch (Exception e
) {
164 Log
.err("Open Platform Surface Area " + path
, "Invalid file type");
167 id
= Tools
.getId(path
, fpd
);
168 vPlatformList
.addElement(new PlatformIdentification(id
));
169 openingPlatformList
.insertToOpeningPlatformList(id
, fpd
);
171 Sort
.sortPlatforms(vPlatformList
, DataType
.SORT_TYPE_ASCENDING
);
176 Get all modules' paths from one package
178 @return a Vector with all modules' path
181 public static Vector
<String
> getAllModulesOfPackage(String path
) {
182 Vector
<String
> modulePath
= new Vector
<String
>();
184 MsaFiles files
= OpenFile
.openSpdFile(path
).getMsaFiles();
186 for (int index
= 0; index
< files
.getFilenameList().size(); index
++) {
187 String msaPath
= files
.getFilenameList().get(index
);
188 msaPath
= Tools
.addFileSeparator(Tools
.getFilePathOnly(path
)) + msaPath
;
189 msaPath
= Tools
.convertPathToCurrentOsType(msaPath
);
190 modulePath
.addElement(msaPath
);
193 } catch (IOException e
) {
194 Log
.err("Get all modules from a package " + path
, e
.getMessage());
195 } catch (XmlException e
) {
196 Log
.err("Get all modules from a package " + path
, e
.getMessage());
197 } catch (Exception e
) {
198 Log
.err("Get all modules from a package " + path
, e
.getMessage());
209 @param packageVersion
213 public static ModuleIdentification
findModuleId(String moduleGuid
, String moduleVersion
, String packageGuid
,
214 String packageVersion
) {
215 ModuleIdentification mid
= null;
216 for (int index
= 0; index
< vModuleList
.size(); index
++) {
217 if (vModuleList
.elementAt(index
).equals(moduleGuid
, moduleVersion
, packageGuid
, packageVersion
)) {
218 mid
= vModuleList
.elementAt(index
);
229 @param packageVersion
233 public static PackageIdentification
findPackageId(String packageGuid
, String packageVersion
) {
234 PackageIdentification pid
= null;
235 for (int index
= 0; index
< vPackageList
.size(); index
++) {
236 if (vPackageList
.elementAt(index
).equals(packageGuid
, packageVersion
)) {
237 pid
= vPackageList
.elementAt(index
);
248 @param platformVersion
252 public static PlatformIdentification
findPlatformId(String platformGuid
, String platformVersion
) {
253 PlatformIdentification pid
= null;
254 for (int index
= 0; index
< vPlatformList
.size(); index
++) {
255 if (vPlatformList
.elementAt(index
).equals(platformGuid
, platformVersion
)) {
256 pid
= vPlatformList
.elementAt(index
);
270 public static boolean isDuplicateRelativePath(String relativePath
, int mode
) {
271 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
272 for (int index
= 0; index
< vModuleList
.size(); index
++) {
273 String path
= vModuleList
.elementAt(index
).getPath();
274 if (Tools
.getFilePathOnly(path
).equals(relativePath
)) {
280 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
281 for (int index
= 0; index
< vPackageList
.size(); index
++) {
282 String path
= vPackageList
.elementAt(index
).getPath();
283 if (Tools
.getFilePathOnly(path
).equals(relativePath
)) {
289 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
290 for (int index
= 0; index
< vPlatformList
.size(); index
++) {
291 String path
= vPlatformList
.elementAt(index
).getPath();
292 if (Tools
.getFilePathOnly(path
).equals(relativePath
)) {