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