]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Update GlobalData, SPD, SurfaceAreaQuery to using EdkException.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / Spd.java
CommitLineData
878ddf1f 1/** @file\r
2 Spd class.\r
3\r
4 This class is to generate a global table for the content of spd file.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.build.global;\r
a29c47e0 17\r
18import java.io.File;\r
892b0e7a 19import java.io.IOException;\r
878ddf1f 20import java.util.HashMap;\r
a29c47e0 21import java.util.Iterator;\r
878ddf1f 22import java.util.Map;\r
a29c47e0 23import java.util.Set;\r
878ddf1f 24\r
892b0e7a 25import org.apache.xmlbeans.XmlException;\r
a29c47e0 26import org.apache.xmlbeans.XmlObject;\r
27import org.tianocore.build.id.ModuleIdentification;\r
28import org.tianocore.build.id.PackageIdentification;\r
892b0e7a 29import org.tianocore.common.exception.EdkException;\r
878ddf1f 30\r
31/**\r
32 \r
a29c47e0 33 This class is to generate a global table for the content of spd file.\r
34 \r
892b0e7a 35**/\r
878ddf1f 36public class Spd {\r
37 ///\r
878ddf1f 38 ///\r
a29c47e0 39 ///\r
40 Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();\r
878ddf1f 41\r
42 ///\r
43 /// Map of module info. \r
44 /// Key : moduletype\r
45 /// Value: moduletype related include file\r
46 ///\r
a29c47e0 47 Map<String, String> packageHeaderInfo = new HashMap<String, String>();\r
878ddf1f 48\r
49 ///\r
50 /// Map of PPI info.\r
51 /// Key : PPI name\r
52 /// value: String[] a. PPI C_NAME; b. PPI GUID;\r
53 ///\r
54 Map<String, String[]> ppiInfo = new HashMap<String, String[]>();\r
55\r
56 ///\r
57 /// Map of Protocol info.\r
58 /// Key : Protocol name\r
59 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;\r
60 ///\r
61 Map<String, String[]> protocolInfo = new HashMap<String, String[]>();\r
62\r
63 ///\r
64 /// Map of Guid info.\r
65 /// Key : Guid name\r
66 /// value: String[] a. Guid C_NAME; b. Guid's GUID;\r
67 ///\r
68 Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
69\r
878ddf1f 70 ///\r
136adffc 71 /// Map of Guid info\r
72 /// Key: GuidCName\r
73 /// value: String Guid's GUID\r
74 ///\r
75 Map<String, String> guidCnameInfo = new HashMap<String, String>();\r
76 \r
878ddf1f 77 /// Map of library class and its exposed header file.\r
78 /// Key : library class name\r
79 /// value : library class corresponding header file\r
80 ///\r
a29c47e0 81 Map<String, String[]> libClassHeaderList = new HashMap<String, String[]>();\r
878ddf1f 82\r
83 ///\r
84 /// Package path.\r
85 ///\r
a29c47e0 86 PackageIdentification packageId;\r
878ddf1f 87\r
88 /**\r
a29c47e0 89 Constructor function\r
90 \r
91 This function mainly initialize some member variables. \r
878ddf1f 92 **/\r
892b0e7a 93 Spd(File packageFile) throws EdkException {\r
a29c47e0 94 //\r
95 // If specified package file not exists\r
96 //\r
97 if ( ! packageFile.exists()) {\r
892b0e7a 98 throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");\r
878ddf1f 99 }\r
a29c47e0 100 try {\r
101 XmlObject spdDoc = XmlObject.Factory.parse(packageFile);\r
102 //\r
103 // Verify SPD file, if is invalid, throw Exception\r
104 //\r
105 if (! spdDoc.validate()) {\r
892b0e7a 106 throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!");\r
878ddf1f 107 }\r
892b0e7a 108 //\r
a29c47e0 109 // We can change Map to XmlObject\r
892b0e7a 110 //\r
a29c47e0 111 Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();\r
112 spdDocMap.put("PackageSurfaceArea", spdDoc);\r
83fba802 113 SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap);\r
892b0e7a 114\r
83fba802 115 packageId = saq.getSpdHeader();\r
a29c47e0 116 packageId.setSpdFile(packageFile);\r
117 \r
118 //\r
119 // initialize Msa Files\r
120 // MSA file is absolute file path\r
121 //\r
83fba802 122 String[] msaFilenames = saq.getSpdMsaFile();\r
a29c47e0 123 for (int i = 0; i < msaFilenames.length; i++){\r
124 File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);\r
125 Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );\r
83fba802 126 saq.push(msaDoc);\r
127 ModuleIdentification moduleId = saq.getMsaHeader();\r
128 saq.pop();\r
a29c47e0 129 moduleId.setPackage(packageId);\r
130 moduleId.setMsaFile(msaFile);\r
131 if (msaInfo.containsKey(moduleId)) {\r
892b0e7a 132 throw new EdkException("Found two modules with the same GUID and Version in package " + packageId + ".\nThey are module [" + msaInfo.get(moduleId) + "] and MSA file [" + msaFile + "]!");\r
878ddf1f 133 }\r
a29c47e0 134 msaInfo.put(moduleId, msaFile);\r
878ddf1f 135 }\r
878ddf1f 136 \r
a29c47e0 137 //\r
138 // initialize Package header files\r
139 //\r
83fba802 140 Map<String, String> packageHeaders = saq.getSpdPackageHeaderFiles();\r
a29c47e0 141 Set keys = packageHeaders.keySet();\r
142 Iterator iter = keys.iterator();\r
143 while (iter.hasNext()){\r
144 String moduleType = (String)iter.next();\r
145 String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);\r
146 \r
147 //\r
148 // Change path seperator to system-dependent path separator\r
149 //\r
150 File file = new File (header);\r
136adffc 151 header = file.getPath();\r
a29c47e0 152 packageHeaderInfo.put(moduleType, header);\r
878ddf1f 153 }\r
a29c47e0 154 \r
155 //\r
156 // initialize Guid Info\r
157 //\r
83fba802 158 guidInfo.putAll(saq.getSpdGuid());\r
a29c47e0 159 \r
136adffc 160 //\r
161 // For Pcd get TokenSpaceGuid\r
162 //\r
163 Set<String> key = guidInfo.keySet();\r
164 Iterator item = key.iterator();\r
165 String [] nameValue = new String[2];\r
166 while(item.hasNext()){\r
167 nameValue = guidInfo.get(item.next());\r
168 guidCnameInfo.put(nameValue[0], nameValue[1]);\r
169 }\r
170 \r
a29c47e0 171 //\r
172 // initialize PPI info\r
173 //\r
83fba802 174 ppiInfo.putAll(saq.getSpdPpi());\r
a29c47e0 175 \r
176 //\r
177 // initialize Protocol info\r
178 //\r
83fba802 179 protocolInfo.putAll(saq.getSpdProtocol());\r
a29c47e0 180 \r
181 //\r
182 // initialize library class declaration\r
183 //\r
83fba802 184 Map<String, String[]> libraryClassHeaders = saq.getSpdLibraryClasses();\r
a29c47e0 185 keys = libraryClassHeaders.keySet();\r
186 iter = keys.iterator();\r
187 while (iter.hasNext()){\r
188 String libraryClassName = (String)iter.next();\r
189 String[] headerFiles = libraryClassHeaders.get(libraryClassName);\r
190 for (int i = 0; i < headerFiles.length; i++){\r
191 headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i];\r
192 \r
193 //\r
194 // Change path separator to system system-dependent path separator. \r
195 //\r
196 File file = new File (headerFiles[i]);\r
197 headerFiles[i] = file.getPath();\r
878ddf1f 198 }\r
a29c47e0 199 libClassHeaderList.put(libraryClassName, headerFiles);\r
878ddf1f 200 }\r
892b0e7a 201 } catch (IOException ex) {\r
202 EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
203 edkException.setStackTrace(ex.getStackTrace());\r
204 throw edkException;\r
205 } catch (XmlException ex) {\r
206 EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
207 edkException.setStackTrace(ex.getStackTrace());\r
208 throw edkException;\r
878ddf1f 209 }\r
878ddf1f 210 }\r
211\r
a29c47e0 212 public PackageIdentification getPackageId() {\r
213 return packageId;\r
878ddf1f 214 }\r
215\r
a29c47e0 216 public File getModuleFile(ModuleIdentification moduleId) {\r
217 return msaInfo.get(moduleId);\r
218 }\r
219 \r
220 public Set<ModuleIdentification> getModules(){\r
221 return msaInfo.keySet();\r
878ddf1f 222 }\r
223\r
224 /**\r
a29c47e0 225 return two value {CName, Guid}. If not found, return null.\r
226 **/\r
227 public String[] getPpi(String ppiName) {\r
228 return ppiInfo.get(ppiName);\r
878ddf1f 229 }\r
230\r
231 /**\r
a29c47e0 232 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 233 **/\r
a29c47e0 234 public String[] getProtocol(String protocolName) {\r
235 return protocolInfo.get(protocolName);\r
878ddf1f 236 }\r
237\r
238 /**\r
a29c47e0 239 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 240 **/\r
a29c47e0 241 public String[] getGuid(String guidName) {\r
242 return guidInfo.get(guidName);\r
878ddf1f 243 }\r
244\r
136adffc 245 /**\r
246 * return Guid Value. \r
247 */\r
248 public String getGuidFromCname(String cName){\r
249 return guidCnameInfo.get(cName);\r
250 }\r
251 \r
878ddf1f 252 /**\r
a29c47e0 253 getLibClassInclude \r
254 \r
255 This function is to get the library exposed header file name according \r
256 library class name.\r
257 \r
258 @param libName Name of library class \r
259 @return Name of header file\r
878ddf1f 260 **/\r
a29c47e0 261 String[] getLibClassIncluder(String libName) {\r
878ddf1f 262 return libClassHeaderList.get(libName);\r
263 }\r
264\r
265 /**\r
266 getModuleTypeIncluder\r
a29c47e0 267 \r
878ddf1f 268 This function is to get the header file name from module info map \r
269 according to module type.\r
a29c47e0 270 \r
878ddf1f 271 @param moduleType Module type.\r
272 @return Name of header file.\r
273 **/\r
a29c47e0 274 String getPackageIncluder(String moduleType) {\r
275 return packageHeaderInfo.get(moduleType);\r
878ddf1f 276 }\r
a29c47e0 277 \r
878ddf1f 278\r
878ddf1f 279}\r