]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/global/Spd.java
Added code to fetch more detailed error message from XMLBeans when there's error...
[mirror_edk2.git] / Tools / Java / 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
fe6d0f74 101 XmlObject spdDoc = GlobalData.parseXmlFile(packageFile);\r
892b0e7a 102 //\r
a29c47e0 103 // We can change Map to XmlObject\r
892b0e7a 104 //\r
a29c47e0 105 Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();\r
106 spdDocMap.put("PackageSurfaceArea", spdDoc);\r
83fba802 107 SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap);\r
892b0e7a 108\r
83fba802 109 packageId = saq.getSpdHeader();\r
a29c47e0 110 packageId.setSpdFile(packageFile);\r
111 \r
112 //\r
113 // initialize Msa Files\r
114 // MSA file is absolute file path\r
115 //\r
83fba802 116 String[] msaFilenames = saq.getSpdMsaFile();\r
a29c47e0 117 for (int i = 0; i < msaFilenames.length; i++){\r
118 File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);\r
119 Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );\r
83fba802 120 saq.push(msaDoc);\r
121 ModuleIdentification moduleId = saq.getMsaHeader();\r
122 saq.pop();\r
a29c47e0 123 moduleId.setPackage(packageId);\r
124 moduleId.setMsaFile(msaFile);\r
125 if (msaInfo.containsKey(moduleId)) {\r
892b0e7a 126 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 127 }\r
a29c47e0 128 msaInfo.put(moduleId, msaFile);\r
878ddf1f 129 }\r
878ddf1f 130 \r
a29c47e0 131 //\r
132 // initialize Package header files\r
133 //\r
83fba802 134 Map<String, String> packageHeaders = saq.getSpdPackageHeaderFiles();\r
a29c47e0 135 Set keys = packageHeaders.keySet();\r
136 Iterator iter = keys.iterator();\r
137 while (iter.hasNext()){\r
138 String moduleType = (String)iter.next();\r
139 String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);\r
140 \r
141 //\r
142 // Change path seperator to system-dependent path separator\r
143 //\r
144 File file = new File (header);\r
136adffc 145 header = file.getPath();\r
a29c47e0 146 packageHeaderInfo.put(moduleType, header);\r
878ddf1f 147 }\r
a29c47e0 148 \r
149 //\r
150 // initialize Guid Info\r
151 //\r
83fba802 152 guidInfo.putAll(saq.getSpdGuid());\r
a29c47e0 153 \r
136adffc 154 //\r
155 // For Pcd get TokenSpaceGuid\r
156 //\r
157 Set<String> key = guidInfo.keySet();\r
158 Iterator item = key.iterator();\r
159 String [] nameValue = new String[2];\r
160 while(item.hasNext()){\r
161 nameValue = guidInfo.get(item.next());\r
162 guidCnameInfo.put(nameValue[0], nameValue[1]);\r
163 }\r
164 \r
a29c47e0 165 //\r
166 // initialize PPI info\r
167 //\r
83fba802 168 ppiInfo.putAll(saq.getSpdPpi());\r
a29c47e0 169 \r
170 //\r
171 // initialize Protocol info\r
172 //\r
83fba802 173 protocolInfo.putAll(saq.getSpdProtocol());\r
a29c47e0 174 \r
175 //\r
176 // initialize library class declaration\r
177 //\r
83fba802 178 Map<String, String[]> libraryClassHeaders = saq.getSpdLibraryClasses();\r
a29c47e0 179 keys = libraryClassHeaders.keySet();\r
180 iter = keys.iterator();\r
181 while (iter.hasNext()){\r
182 String libraryClassName = (String)iter.next();\r
183 String[] headerFiles = libraryClassHeaders.get(libraryClassName);\r
184 for (int i = 0; i < headerFiles.length; i++){\r
185 headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i];\r
186 \r
187 //\r
188 // Change path separator to system system-dependent path separator. \r
189 //\r
190 File file = new File (headerFiles[i]);\r
191 headerFiles[i] = file.getPath();\r
878ddf1f 192 }\r
a29c47e0 193 libClassHeaderList.put(libraryClassName, headerFiles);\r
878ddf1f 194 }\r
892b0e7a 195 } catch (IOException ex) {\r
196 EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
197 edkException.setStackTrace(ex.getStackTrace());\r
198 throw edkException;\r
199 } catch (XmlException ex) {\r
200 EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
201 edkException.setStackTrace(ex.getStackTrace());\r
202 throw edkException;\r
878ddf1f 203 }\r
878ddf1f 204 }\r
205\r
a29c47e0 206 public PackageIdentification getPackageId() {\r
207 return packageId;\r
878ddf1f 208 }\r
209\r
a29c47e0 210 public File getModuleFile(ModuleIdentification moduleId) {\r
211 return msaInfo.get(moduleId);\r
212 }\r
213 \r
214 public Set<ModuleIdentification> getModules(){\r
215 return msaInfo.keySet();\r
878ddf1f 216 }\r
217\r
218 /**\r
a29c47e0 219 return two value {CName, Guid}. If not found, return null.\r
220 **/\r
221 public String[] getPpi(String ppiName) {\r
222 return ppiInfo.get(ppiName);\r
878ddf1f 223 }\r
224\r
225 /**\r
a29c47e0 226 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 227 **/\r
a29c47e0 228 public String[] getProtocol(String protocolName) {\r
229 return protocolInfo.get(protocolName);\r
878ddf1f 230 }\r
231\r
232 /**\r
a29c47e0 233 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 234 **/\r
a29c47e0 235 public String[] getGuid(String guidName) {\r
236 return guidInfo.get(guidName);\r
878ddf1f 237 }\r
238\r
136adffc 239 /**\r
240 * return Guid Value. \r
241 */\r
242 public String getGuidFromCname(String cName){\r
243 return guidCnameInfo.get(cName);\r
244 }\r
245 \r
878ddf1f 246 /**\r
a29c47e0 247 getLibClassInclude \r
248 \r
249 This function is to get the library exposed header file name according \r
250 library class name.\r
251 \r
252 @param libName Name of library class \r
253 @return Name of header file\r
878ddf1f 254 **/\r
a29c47e0 255 String[] getLibClassIncluder(String libName) {\r
878ddf1f 256 return libClassHeaderList.get(libName);\r
257 }\r
258\r
259 /**\r
260 getModuleTypeIncluder\r
a29c47e0 261 \r
878ddf1f 262 This function is to get the header file name from module info map \r
263 according to module type.\r
a29c47e0 264 \r
878ddf1f 265 @param moduleType Module type.\r
266 @return Name of header file.\r
267 **/\r
a29c47e0 268 String getPackageIncluder(String moduleType) {\r
269 return packageHeaderInfo.get(moduleType);\r
878ddf1f 270 }\r
a29c47e0 271 \r
878ddf1f 272\r
878ddf1f 273}\r