]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/GlobalData.java
1. Fix EDKT463: When wizard new or clone a msa/spd/fpd, should follow these rules
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / GlobalData.java
1 /** @file
2 The file is used to provide initializing global data.
3
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
9
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.
12 **/
13 package org.tianocore.frameworkwizard.common;
14
15 import java.io.IOException;
16 import java.util.Vector;
17
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;
32
33 public class GlobalData {
34
35 public static FrameworkDatabase fdb = null;
36
37 public static OpeningModuleList openingModuleList = new OpeningModuleList();
38
39 public static OpeningPackageList openingPackageList = new OpeningPackageList();
40
41 public static OpeningPlatformList openingPlatformList = new OpeningPlatformList();
42
43 public static Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();
44
45 public static Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();
46
47 public static Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();
48
49 public static void init() {
50 initDatabase();
51 initPackage();
52 initPlatform();
53 initModule();
54 }
55
56 public static void initDatabase() {
57 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
58 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
59 try {
60 fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);
61 } catch (XmlException e) {
62 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());
63 return;
64 } catch (Exception e) {
65 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");
66 return;
67 }
68 }
69
70 public static void initModule() {
71 vModuleList = new Vector<ModuleIdentification>();
72 openingModuleList = new OpeningModuleList();
73
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;
80
81 //
82 // For each package, get all modules list
83 //
84 if (vPackageList.size() > 0) {
85 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {
86 packagePath = vPackageList.elementAt(indexI).getPath();
87 modulePaths = getAllModulesOfPackage(packagePath);
88
89 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {
90 try {
91 modulePath = modulePaths.get(indexJ);
92 msa = OpenFile.openMsaFile(modulePath);
93
94 } catch (IOException e) {
95 Log.err("Open Module Surface Area " + modulePath, e.getMessage());
96 continue;
97 } catch (XmlException e) {
98 Log.err("Open Module Surface Area " + modulePath, e.getMessage());
99 continue;
100 } catch (Exception e) {
101 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");
102 continue;
103 }
104 id = Tools.getId(modulePath, msa);
105 mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));
106 vModuleList.addElement(mid);
107 openingModuleList.insertToOpeningModuleList(mid, msa);
108 }
109 }
110 Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);
111 }
112 }
113
114 public static void initPackage() {
115 vPackageList = new Vector<PackageIdentification>();
116 openingPackageList = new OpeningPackageList();
117 if (fdb != null) {
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;
124 try {
125 spd = OpenFile.openSpdFile(path);
126 } catch (IOException e) {
127 Log.err("Open Package Surface Area " + path, e.getMessage());
128 continue;
129 } catch (XmlException e) {
130 Log.err("Open Package Surface Area " + path, e.getMessage());
131 continue;
132 } catch (Exception e) {
133 Log.err("Open Package Surface Area " + path, "Invalid file type");
134 continue;
135 }
136 id = Tools.getId(path, spd);
137 vPackageList.addElement(id);
138 openingPackageList.insertToOpeningPackageList(id, spd);
139 }
140 Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);
141 }
142 }
143
144 public static void initPlatform() {
145 vPlatformList = new Vector<PlatformIdentification>();
146 openingPlatformList = new OpeningPlatformList();
147
148 if (fdb != null) {
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;
155 try {
156 fpd = OpenFile.openFpdFile(path);
157 } catch (IOException e) {
158 Log.err("Open Platform Surface Area " + path, e.getMessage());
159 continue;
160 } catch (XmlException e) {
161 Log.err("Open Platform Surface Area " + path, e.getMessage());
162 continue;
163 } catch (Exception e) {
164 Log.err("Open Platform Surface Area " + path, "Invalid file type");
165 continue;
166 }
167 id = Tools.getId(path, fpd);
168 vPlatformList.addElement(new PlatformIdentification(id));
169 openingPlatformList.insertToOpeningPlatformList(id, fpd);
170 }
171 Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);
172 }
173 }
174
175 /**
176 Get all modules' paths from one package
177
178 @return a Vector with all modules' path
179
180 **/
181 public static Vector<String> getAllModulesOfPackage(String path) {
182 Vector<String> modulePath = new Vector<String>();
183 try {
184 MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();
185 if (files != null) {
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);
191 }
192 }
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());
199 }
200 return modulePath;
201 }
202
203 /**
204 Get a module id
205
206 @param moduleGuid
207 @param moduleVersion
208 @param packageGuid
209 @param packageVersion
210 @return
211
212 **/
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);
219 break;
220 }
221 }
222 return mid;
223 }
224
225 /**
226 Get a package id
227
228 @param packageGuid
229 @param packageVersion
230 @return
231
232 **/
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);
238 break;
239 }
240 }
241 return pid;
242 }
243
244 /**
245 Get a platform id
246
247 @param platformGuid
248 @param platformVersion
249 @return
250
251 **/
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);
257 break;
258 }
259 }
260 return pid;
261 }
262
263 /**
264
265 @param relativePath
266 @param mode
267 @return
268
269 **/
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)) {
275 return true;
276 }
277 }
278 }
279
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)) {
284 return true;
285 }
286 }
287 }
288
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)) {
293 return true;
294 }
295 }
296 }
297
298 return false;
299 }
300 }