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() + "] does not exist!");
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() + "] format 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("Found two modules with the same GUID and Version in package " + packageId
+ ".\nThey are module [" + msaInfo
.get(moduleId
) + "] and MSA file [" + 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 throw new BuildException("Parse of the package description file [" + packageFile
.getPath() + "] failed!\n"
206 public PackageIdentification
getPackageId() {
210 public File
getModuleFile(ModuleIdentification moduleId
) {
211 return msaInfo
.get(moduleId
);
214 public Set
<ModuleIdentification
> getModules(){
215 return msaInfo
.keySet();
219 return two value {CName, Guid}. If not found, return null.
221 public String
[] getPpi(String ppiName
) {
222 return ppiInfo
.get(ppiName
);
226 return two value {CName, Guid}. If not found, return null.
228 public String
[] getProtocol(String protocolName
) {
229 return protocolInfo
.get(protocolName
);
233 return two value {CName, Guid}. If not found, return null.
235 public String
[] getGuid(String guidName
) {
236 return guidInfo
.get(guidName
);
242 public String
getGuidFromCname(String cName
){
243 return guidCnameInfo
.get(cName
);
249 This function is to get the library exposed header file name according
252 @param libName Name of library class
253 @return Name of header file
255 String
[] getLibClassIncluder(String libName
) {
256 return libClassHeaderList
.get(libName
);
260 getModuleTypeIncluder
262 This function is to get the header file name from module info map
263 according to module type.
265 @param moduleType Module type.
266 @return Name of header file.
268 String
getPackageIncluder(String moduleType
) {
269 return packageHeaderInfo
.get(moduleType
);