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