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