]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/GlobalData.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / 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
96 } catch (XmlException e) {\r
97 Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
98 } catch (Exception e) {\r
99 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r
100 }\r
101 id = Tools.getId(modulePath, msa);\r
102 mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));\r
103 vModuleList.addElement(mid);\r
104 openingModuleList.insertToOpeningModuleList(mid, msa);\r
105 }\r
106 }\r
107 Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);\r
108 }\r
109 }\r
110\r
111 public static void initPackage() {\r
112 vPackageList = new Vector<PackageIdentification>();\r
113 openingPackageList = new OpeningPackageList();\r
114 if (fdb != null) {\r
115 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
116 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
117 + fdb.getPackageList().getFilenameArray(index).getStringValue();\r
118 path = Tools.convertPathToCurrentOsType(path);\r
119 PackageSurfaceArea spd = null;\r
120 PackageIdentification id = null;\r
121 try {\r
122 spd = OpenFile.openSpdFile(path);\r
123 } catch (IOException e) {\r
124 Log.err("Open Package Surface Area " + path, e.getMessage());\r
125 } catch (XmlException e) {\r
126 Log.err("Open Package Surface Area " + path, e.getMessage());\r
127 } catch (Exception e) {\r
128 Log.err("Open Package Surface Area " + path, "Invalid file type");\r
129 }\r
130 id = Tools.getId(path, spd);\r
131 vPackageList.addElement(id);\r
132 openingPackageList.insertToOpeningPackageList(id, spd);\r
133 }\r
134 Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);\r
135 }\r
136 }\r
137\r
138 public static void initPlatform() {\r
139 vPlatformList = new Vector<PlatformIdentification>();\r
140 openingPlatformList = new OpeningPlatformList();\r
141\r
142 if (fdb != null) {\r
143 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
144 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
145 + fdb.getPlatformList().getFilenameArray(index).getStringValue();\r
146 path = Tools.convertPathToCurrentOsType(path);\r
147 PlatformSurfaceArea fpd = null;\r
148 PlatformIdentification id = null;\r
149 try {\r
150 fpd = OpenFile.openFpdFile(path);\r
151 } catch (IOException e) {\r
152 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
153 } catch (XmlException e) {\r
154 Log.err("Open Platform Surface Area " + path, e.getMessage());\r
155 } catch (Exception e) {\r
156 Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
157 }\r
158 id = Tools.getId(path, fpd);\r
159 vPlatformList.addElement(new PlatformIdentification(id));\r
160 openingPlatformList.insertToOpeningPlatformList(id, fpd);\r
161 }\r
162 Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);\r
163 }\r
164 }\r
165\r
166 /**\r
167 Get all modules' paths from one package\r
168 \r
169 @return a Vector with all modules' path\r
170 \r
171 **/\r
172 private static Vector<String> getAllModulesOfPackage(String path) {\r
173 Vector<String> modulePath = new Vector<String>();\r
174 try {\r
175 MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();\r
176 if (files != null) {\r
177 for (int index = 0; index < files.getFilenameList().size(); index++) {\r
178 String msaPath = files.getFilenameList().get(index);\r
179 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;\r
180 msaPath = Tools.convertPathToCurrentOsType(msaPath);\r
181 modulePath.addElement(msaPath);\r
182 }\r
183 }\r
184 } catch (IOException e) {\r
af6afe48 185 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 186 } catch (XmlException e) {\r
af6afe48 187 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 188 } catch (Exception e) {\r
af6afe48 189 Log.err("Get all modules from a package " + path, e.getMessage());\r
739c6b04 190 }\r
191 return modulePath;\r
192 }\r
193}\r