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