]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
739c6b04 1/** @file \r
2 The file is used to provide initializing global data.\r
3 \r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12 **/\r
13package org.tianocore.frameworkwizard.common;\r
14\r
15import java.io.IOException;\r
16import java.util.Vector;\r
17\r
18import org.apache.xmlbeans.XmlException;\r
19import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r
20import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
21import org.tianocore.MsaFilesDocument.MsaFiles;\r
22import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
23import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
24import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
25import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleList;\r
26import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageList;\r
27import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformList;\r
28import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
29import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
30import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
31import org.tianocore.frameworkwizard.workspace.Workspace;\r
32\r
33public class GlobalData {\r
34\r
35 public static FrameworkDatabase fdb = null;\r
36\r
37 public static OpeningModuleList openingModuleList = new OpeningModuleList();\r
38\r
39 public static OpeningPackageList openingPackageList = new OpeningPackageList();\r
40\r
41 public static OpeningPlatformList openingPlatformList = new OpeningPlatformList();\r
42\r
43 public static Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();\r
44\r
45 public static Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();\r
46\r
47 public static Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();\r
48\r
49 public static void init() {\r
50 initDatabase();\r
51 initPackage();\r
52 initPlatform();\r
53 initModule();\r
54 }\r
55\r
56 public static void initDatabase() {\r
57 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
58 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
59 try {\r
60 fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);\r
61 } catch (XmlException e) {\r
62 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());\r
63 return;\r
64 } catch (Exception e) {\r
65 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");\r
66 return;\r
67 }\r
68 }\r
69\r
70 public static void initModule() {\r
71 vModuleList = new Vector<ModuleIdentification>();\r
72 openingModuleList = new OpeningModuleList();\r
73\r
74 ModuleSurfaceArea msa = null;\r
75 Vector<String> modulePaths = new Vector<String>();\r
76 Identification id = null;\r
77 ModuleIdentification mid = null;\r
78 String packagePath = null;\r
79 String modulePath = null;\r
80\r
81 //\r
82 // For each package, get all modules list\r
83 //\r
84 if (vPackageList.size() > 0) {\r
85 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {\r
86 packagePath = vPackageList.elementAt(indexI).getPath();\r
87 modulePaths = getAllModulesOfPackage(packagePath);\r
88\r
89 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
90 try {\r
91 modulePath = modulePaths.get(indexJ);\r
92 msa = OpenFile.openMsaFile(modulePath);\r
93\r
94 } catch (IOException e) {\r
95 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
94b0f428 96 continue;\r
739c6b04 97 } catch (XmlException e) {\r
98 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
94b0f428 99 continue;\r
739c6b04 100 } catch (Exception e) {\r
101 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r
94b0f428 102 continue;\r
739c6b04 103 }\r
104 id = Tools.getId(modulePath, msa);\r
105 mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));\r
106 vModuleList.addElement(mid);\r
107 openingModuleList.insertToOpeningModuleList(mid, msa);\r
108 }\r
109 }\r
110 Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);\r
111 }\r
112 }\r
113\r
114 public static void initPackage() {\r
115 vPackageList = new Vector<PackageIdentification>();\r
116 openingPackageList = new OpeningPackageList();\r
117 if (fdb != null) {\r
118 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
119 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
120 + fdb.getPackageList().getFilenameArray(index).getStringValue();\r
121 path = Tools.convertPathToCurrentOsType(path);\r
122 PackageSurfaceArea spd = null;\r
123 PackageIdentification id = null;\r
124 try {\r
125 spd = OpenFile.openSpdFile(path);\r
126 } catch (IOException e) {\r
127 Log.err("Open Package Surface Area " + path, e.getMessage());\r
94b0f428 128 continue;\r
739c6b04 129 } catch (XmlException e) {\r
130 Log.err("Open Package Surface Area " + path, e.getMessage());\r
94b0f428 131 continue;\r
739c6b04 132 } catch (Exception e) {\r
133 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
94b0f428 134 continue;\r
739c6b04 135 }\r
136 id = Tools.getId(path, spd);\r
137 vPackageList.addElement(id);\r
138 openingPackageList.insertToOpeningPackageList(id, spd);\r
139 }\r
140 Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);\r
141 }\r
142 }\r
143\r
144 public static void initPlatform() {\r
145 vPlatformList = new Vector<PlatformIdentification>();\r
146 openingPlatformList = new OpeningPlatformList();\r
147\r
148 if (fdb != null) {\r
149 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
150 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
151 + fdb.getPlatformList().getFilenameArray(index).getStringValue();\r
152 path = Tools.convertPathToCurrentOsType(path);\r
153 PlatformSurfaceArea fpd = null;\r
154 PlatformIdentification id = null;\r
155 try {\r
156 fpd = OpenFile.openFpdFile(path);\r
157 } catch (IOException e) {\r
158 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
94b0f428 159 continue;\r
739c6b04 160 } catch (XmlException e) {\r
161 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
94b0f428 162 continue;\r
739c6b04 163 } catch (Exception e) {\r
164 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
94b0f428 165 continue;\r
739c6b04 166 }\r
167 id = Tools.getId(path, fpd);\r
168 vPlatformList.addElement(new PlatformIdentification(id));\r
169 openingPlatformList.insertToOpeningPlatformList(id, fpd);\r
170 }\r
171 Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);\r
172 }\r
173 }\r
174\r
175 /**\r
176 Get all modules' paths from one package\r
177 \r
178 @return a Vector with all modules' path\r
179 \r
180 **/\r
4917d9dd 181 public static Vector<String> getAllModulesOfPackage(String path) {\r
739c6b04 182 Vector<String> modulePath = new Vector<String>();\r
183 try {\r
184 MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();\r
185 if (files != null) {\r
186 for (int index = 0; index < files.getFilenameList().size(); index++) {\r
187 String msaPath = files.getFilenameList().get(index);\r
188 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;\r
189 msaPath = Tools.convertPathToCurrentOsType(msaPath);\r
190 modulePath.addElement(msaPath);\r
191 }\r
192 }\r
193 } catch (IOException e) {\r
af6afe48 194 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 195 } catch (XmlException e) {\r
af6afe48 196 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 197 } catch (Exception e) {\r
af6afe48 198 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 199 }\r
200 return modulePath;\r
201 }\r
d8be5b14 202\r
419558bb 203 /**\r
204 Get a module id\r
205 \r
206 @param moduleGuid\r
207 @param moduleVersion\r
208 @param packageGuid\r
209 @param packageVersion\r
210 @return\r
d8be5b14 211 \r
212 **/\r
fc87d0ba 213 public static ModuleIdentification findModuleId(String moduleGuid, String moduleVersion, String packageGuid,\r
214 String packageVersion) {\r
419558bb 215 ModuleIdentification mid = null;\r
216 for (int index = 0; index < vModuleList.size(); index++) {\r
217 if (vModuleList.elementAt(index).equals(moduleGuid, moduleVersion, packageGuid, packageVersion)) {\r
218 mid = vModuleList.elementAt(index);\r
219 break;\r
220 }\r
221 }\r
222 return mid;\r
223 }\r
d8be5b14 224\r
225 /**\r
226 Get a package id\r
227 \r
228 @param packageGuid\r
229 @param packageVersion\r
230 @return\r
231 \r
232 **/\r
fc87d0ba 233 public static PackageIdentification findPackageId(String packageGuid, String packageVersion) {\r
d8be5b14 234 PackageIdentification pid = null;\r
235 for (int index = 0; index < vPackageList.size(); index++) {\r
236 if (vPackageList.elementAt(index).equals(packageGuid, packageVersion)) {\r
237 pid = vPackageList.elementAt(index);\r
238 break;\r
239 }\r
240 }\r
241 return pid;\r
242 }\r
243\r
244 /**\r
245 Get a platform id \r
246 \r
247 @param platformGuid\r
248 @param platformVersion\r
249 @return\r
250 \r
251 **/\r
fc87d0ba 252 public static PlatformIdentification findPlatformId(String platformGuid, String platformVersion) {\r
d8be5b14 253 PlatformIdentification pid = null;\r
254 for (int index = 0; index < vPlatformList.size(); index++) {\r
255 if (vPlatformList.elementAt(index).equals(platformGuid, platformVersion)) {\r
256 pid = vPlatformList.elementAt(index);\r
257 break;\r
258 }\r
259 }\r
260 return pid;\r
261 }\r
fc87d0ba 262\r
263 /**\r
264 \r
265 @param relativePath\r
266 @param mode\r
267 @return\r
268 \r
269 **/\r
270 public static boolean isDuplicateRelativePath(String relativePath, int mode) {\r
271 if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
272 for (int index = 0; index < vModuleList.size(); index++) {\r
273 String path = vModuleList.elementAt(index).getPath();\r
274 if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
275 return true;\r
276 }\r
277 }\r
278 }\r
279\r
280 if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
281 for (int index = 0; index < vPackageList.size(); index++) {\r
282 String path = vPackageList.elementAt(index).getPath();\r
283 if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
284 return true;\r
285 }\r
286 }\r
287 }\r
288\r
289 if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
290 for (int index = 0; index < vPlatformList.size(); index++) {\r
291 String path = vPlatformList.elementAt(index).getPath();\r
292 if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
293 return true;\r
294 }\r
295 }\r
296 }\r
297\r
298 return false;\r
299 }\r
739c6b04 300}\r