]>
Commit | Line | Data |
---|---|---|
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 | |
13 | package org.tianocore.frameworkwizard.common;\r | |
14 | \r | |
15 | import java.io.IOException;\r | |
16 | import java.util.Vector;\r | |
17 | \r | |
18 | import org.apache.xmlbeans.XmlException;\r | |
19 | import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r | |
20 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r | |
21 | import org.tianocore.MsaFilesDocument.MsaFiles;\r | |
22 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r | |
23 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r | |
24 | import org.tianocore.frameworkwizard.common.Identifications.Identification;\r | |
25 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleList;\r | |
26 | import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageList;\r | |
27 | import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformList;\r | |
28 | import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r | |
29 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r | |
30 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r | |
31 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
32 | \r | |
33 | public 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 | continue;\r | |
97 | } catch (XmlException e) {\r | |
98 | Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r | |
99 | continue;\r | |
100 | } catch (Exception e) {\r | |
101 | Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r | |
102 | continue;\r | |
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 | |
128 | continue;\r | |
129 | } catch (XmlException e) {\r | |
130 | Log.err("Open Package Surface Area " + path, e.getMessage());\r | |
131 | continue;\r | |
132 | } catch (Exception e) {\r | |
133 | Log.err("Open Package Surface Area " + path, "Invalid file type");\r | |
134 | continue;\r | |
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 | |
159 | continue;\r | |
160 | } catch (XmlException e) {\r | |
161 | Log.err("Open Platform Surface Area " + path, e.getMessage());\r | |
162 | continue;\r | |
163 | } catch (Exception e) {\r | |
164 | Log.err("Open Platform Surface Area " + path, "Invalid file type");\r | |
165 | continue;\r | |
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 | |
181 | public static Vector<String> getAllModulesOfPackage(String path) {\r | |
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 | |
194 | Log.err("Get all modules from a package " + path, e.getMessage());\r | |
195 | } catch (XmlException e) {\r | |
196 | Log.err("Get all modules from a package " + path, e.getMessage());\r | |
197 | } catch (Exception e) {\r | |
198 | Log.err("Get all modules from a package " + path, e.getMessage());\r | |
199 | }\r | |
200 | return modulePath;\r | |
201 | }\r | |
202 | }\r |