4 This class is to generate a global table for the content of spd file.
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
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.
16 package org
.tianocore
.build
.global
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
24 import org
.apache
.tools
.ant
.BuildException
;
25 import org
.apache
.xmlbeans
.XmlObject
;
26 import org
.tianocore
.build
.id
.ModuleIdentification
;
27 import org
.tianocore
.build
.id
.PackageIdentification
;
31 This class is to generate a global table for the content of spd file.
38 Map
<ModuleIdentification
, File
> msaInfo
= new HashMap
<ModuleIdentification
, File
>();
41 /// Map of module info.
43 /// Value: moduletype related include file
45 Map
<String
, String
> packageHeaderInfo
= new HashMap
<String
, String
>();
50 /// value: String[] a. PPI C_NAME; b. PPI GUID;
52 Map
<String
, String
[]> ppiInfo
= new HashMap
<String
, String
[]>();
55 /// Map of Protocol info.
56 /// Key : Protocol name
57 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;
59 Map
<String
, String
[]> protocolInfo
= new HashMap
<String
, String
[]>();
64 /// value: String[] a. Guid C_NAME; b. Guid's GUID;
66 Map
<String
, String
[]> guidInfo
= new HashMap
<String
, String
[]>();
71 /// value: String Guid's GUID
73 Map
<String
, String
> guidCnameInfo
= new HashMap
<String
, String
>();
75 /// Map of library class and its exposed header file.
76 /// Key : library class name
77 /// value : library class corresponding header file
79 Map
<String
, String
[]> libClassHeaderList
= new HashMap
<String
, String
[]>();
84 PackageIdentification packageId
;
89 This function mainly initialize some member variables.
91 Spd(File packageFile
) throws BuildException
{
93 // If specified package file not exists
95 if ( ! packageFile
.exists()) {
96 throw new BuildException("Package file [" + packageFile
.getPath() + "] not exists. ");
99 XmlObject spdDoc
= XmlObject
.Factory
.parse(packageFile
);
101 // Verify SPD file, if is invalid, throw Exception
103 if (! spdDoc
.validate()) {
104 throw new BuildException("Package Surface Area file [" + packageFile
.getPath() + "] is invalid. ");
106 // We can change Map to XmlObject
107 Map
<String
, XmlObject
> spdDocMap
= new HashMap
<String
, XmlObject
>();
108 spdDocMap
.put("PackageSurfaceArea", spdDoc
);
109 SurfaceAreaQuery
.setDoc(spdDocMap
);
113 packageId
= SurfaceAreaQuery
.getSpdHeader();
114 packageId
.setSpdFile(packageFile
);
117 // initialize Msa Files
118 // MSA file is absolute file path
120 String
[] msaFilenames
= SurfaceAreaQuery
.getSpdMsaFile();
121 for (int i
= 0; i
< msaFilenames
.length
; i
++){
122 File msaFile
= new File(packageId
.getPackageDir() + File
.separatorChar
+ msaFilenames
[i
]);
123 Map
<String
, XmlObject
> msaDoc
= GlobalData
.getNativeMsa( msaFile
);
124 SurfaceAreaQuery
.push(msaDoc
);
125 ModuleIdentification moduleId
= SurfaceAreaQuery
.getMsaHeader();
126 SurfaceAreaQuery
.pop();
127 moduleId
.setPackage(packageId
);
128 moduleId
.setMsaFile(msaFile
);
129 if (msaInfo
.containsKey(moduleId
)) {
130 throw new BuildException("Find two modules with the same GUID and Version in " + packageId
+ ". They are [" + msaInfo
.get(moduleId
) + "] and [" + msaFile
+ "] ");
132 msaInfo
.put(moduleId
, msaFile
);
136 // initialize Package header files
138 Map
<String
, String
> packageHeaders
= SurfaceAreaQuery
.getSpdPackageHeaderFiles();
139 Set keys
= packageHeaders
.keySet();
140 Iterator iter
= keys
.iterator();
141 while (iter
.hasNext()){
142 String moduleType
= (String
)iter
.next();
143 String header
= packageId
.getPackageRelativeDir() + File
.separatorChar
+ packageHeaders
.get(moduleType
);
146 // Change path seperator to system-dependent path separator
148 File file
= new File (header
);
149 header
= file
.getPath();
150 packageHeaderInfo
.put(moduleType
, header
);
154 // initialize Guid Info
156 guidInfo
.putAll(SurfaceAreaQuery
.getSpdGuid());
159 // For Pcd get TokenSpaceGuid
161 Set
<String
> key
= guidInfo
.keySet();
162 Iterator item
= key
.iterator();
163 String
[] nameValue
= new String
[2];
164 while(item
.hasNext()){
165 nameValue
= guidInfo
.get(item
.next());
166 guidCnameInfo
.put(nameValue
[0], nameValue
[1]);
170 // initialize PPI info
172 ppiInfo
.putAll(SurfaceAreaQuery
.getSpdPpi());
175 // initialize Protocol info
177 protocolInfo
.putAll(SurfaceAreaQuery
.getSpdProtocol());
180 // initialize library class declaration
182 Map
<String
, String
[]> libraryClassHeaders
= SurfaceAreaQuery
.getSpdLibraryClasses();
183 keys
= libraryClassHeaders
.keySet();
184 iter
= keys
.iterator();
185 while (iter
.hasNext()){
186 String libraryClassName
= (String
)iter
.next();
187 String
[] headerFiles
= libraryClassHeaders
.get(libraryClassName
);
188 for (int i
= 0; i
< headerFiles
.length
; i
++){
189 headerFiles
[i
] = packageId
.getPackageRelativeDir() + File
.separatorChar
+ headerFiles
[i
];
192 // Change path separator to system system-dependent path separator.
194 File file
= new File (headerFiles
[i
]);
195 headerFiles
[i
] = file
.getPath();
197 libClassHeaderList
.put(libraryClassName
, headerFiles
);
200 catch (Exception e
) {
201 e
.setStackTrace(e
.getStackTrace());
202 throw new BuildException("Parse package description file [" + packageId
.getSpdFile() + "] Error.\n"
207 public PackageIdentification
getPackageId() {
211 public File
getModuleFile(ModuleIdentification moduleId
) {
212 return msaInfo
.get(moduleId
);
215 public Set
<ModuleIdentification
> getModules(){
216 return msaInfo
.keySet();
220 return two value {CName, Guid}. If not found, return null.
222 public String
[] getPpi(String ppiName
) {
223 return ppiInfo
.get(ppiName
);
227 return two value {CName, Guid}. If not found, return null.
229 public String
[] getProtocol(String protocolName
) {
230 return protocolInfo
.get(protocolName
);
234 return two value {CName, Guid}. If not found, return null.
236 public String
[] getGuid(String guidName
) {
237 return guidInfo
.get(guidName
);
243 public String
getGuidFromCname(String cName
){
244 return guidCnameInfo
.get(cName
);
250 This function is to get the library exposed header file name according
253 @param libName Name of library class
254 @return Name of header file
256 String
[] getLibClassIncluder(String libName
) {
257 return libClassHeaderList
.get(libName
);
261 getModuleTypeIncluder
263 This function is to get the header file name from module info map
264 according to module type.
266 @param moduleType Module type.
267 @return Name of header file.
269 String
getPackageIncluder(String moduleType
) {
270 return packageHeaderInfo
.get(moduleType
);