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
[]>();
69 /// Map of library class and its exposed header file.
70 /// Key : library class name
71 /// value : library class corresponding header file
73 Map
<String
, String
[]> libClassHeaderList
= new HashMap
<String
, String
[]>();
78 PackageIdentification packageId
;
83 This function mainly initialize some member variables.
85 Spd(File packageFile
) throws BuildException
{
87 // If specified package file not exists
89 if ( ! packageFile
.exists()) {
90 throw new BuildException("Package file [" + packageFile
.getPath() + "] not exists. ");
93 XmlObject spdDoc
= XmlObject
.Factory
.parse(packageFile
);
95 // Verify SPD file, if is invalid, throw Exception
97 if (! spdDoc
.validate()) {
98 throw new BuildException("Package Surface Area file [" + packageFile
.getPath() + "] is invalid. ");
100 // We can change Map to XmlObject
101 Map
<String
, XmlObject
> spdDocMap
= new HashMap
<String
, XmlObject
>();
102 spdDocMap
.put("PackageSurfaceArea", spdDoc
);
103 SurfaceAreaQuery
.setDoc(spdDocMap
);
107 packageId
= SurfaceAreaQuery
.getSpdHeader();
108 packageId
.setSpdFile(packageFile
);
111 // initialize Msa Files
112 // MSA file is absolute file path
114 String
[] msaFilenames
= SurfaceAreaQuery
.getSpdMsaFile();
115 for (int i
= 0; i
< msaFilenames
.length
; i
++){
116 File msaFile
= new File(packageId
.getPackageDir() + File
.separatorChar
+ msaFilenames
[i
]);
117 Map
<String
, XmlObject
> msaDoc
= GlobalData
.getNativeMsa( msaFile
);
118 SurfaceAreaQuery
.push(msaDoc
);
119 ModuleIdentification moduleId
= SurfaceAreaQuery
.getMsaHeader();
120 SurfaceAreaQuery
.pop();
121 moduleId
.setPackage(packageId
);
122 moduleId
.setMsaFile(msaFile
);
123 if (msaInfo
.containsKey(moduleId
)) {
124 throw new BuildException("Find two modules with the same GUID and Version in " + packageId
+ ". They are [" + msaInfo
.get(moduleId
) + "] and [" + msaFile
+ "] ");
126 msaInfo
.put(moduleId
, msaFile
);
130 // initialize Package header files
132 Map
<String
, String
> packageHeaders
= SurfaceAreaQuery
.getSpdPackageHeaderFiles();
133 Set keys
= packageHeaders
.keySet();
134 Iterator iter
= keys
.iterator();
135 while (iter
.hasNext()){
136 String moduleType
= (String
)iter
.next();
137 String header
= packageId
.getPackageRelativeDir() + File
.separatorChar
+ packageHeaders
.get(moduleType
);
140 // Change path seperator to system-dependent path separator
142 File file
= new File (header
);
143 header
= file
.getParent();
144 packageHeaderInfo
.put(moduleType
, header
);
148 // initialize Guid Info
150 guidInfo
.putAll(SurfaceAreaQuery
.getSpdGuid());
153 // initialize PPI info
155 ppiInfo
.putAll(SurfaceAreaQuery
.getSpdPpi());
158 // initialize Protocol info
160 protocolInfo
.putAll(SurfaceAreaQuery
.getSpdProtocol());
163 // initialize library class declaration
165 Map
<String
, String
[]> libraryClassHeaders
= SurfaceAreaQuery
.getSpdLibraryClasses();
166 keys
= libraryClassHeaders
.keySet();
167 iter
= keys
.iterator();
168 while (iter
.hasNext()){
169 String libraryClassName
= (String
)iter
.next();
170 String
[] headerFiles
= libraryClassHeaders
.get(libraryClassName
);
171 for (int i
= 0; i
< headerFiles
.length
; i
++){
172 headerFiles
[i
] = packageId
.getPackageRelativeDir() + File
.separatorChar
+ headerFiles
[i
];
175 // Change path separator to system system-dependent path separator.
177 File file
= new File (headerFiles
[i
]);
178 headerFiles
[i
] = file
.getPath();
180 libClassHeaderList
.put(libraryClassName
, headerFiles
);
183 catch (Exception e
) {
184 e
.setStackTrace(e
.getStackTrace());
185 throw new BuildException("Parse package description file [" + packageId
.getSpdFile() + "] Error.\n"
190 public PackageIdentification
getPackageId() {
194 public File
getModuleFile(ModuleIdentification moduleId
) {
195 return msaInfo
.get(moduleId
);
198 public Set
<ModuleIdentification
> getModules(){
199 return msaInfo
.keySet();
203 return two value {CName, Guid}. If not found, return null.
205 public String
[] getPpi(String ppiName
) {
206 return ppiInfo
.get(ppiName
);
210 return two value {CName, Guid}. If not found, return null.
212 public String
[] getProtocol(String protocolName
) {
213 return protocolInfo
.get(protocolName
);
217 return two value {CName, Guid}. If not found, return null.
219 public String
[] getGuid(String guidName
) {
220 return guidInfo
.get(guidName
);
226 This function is to get the library exposed header file name according
229 @param libName Name of library class
230 @return Name of header file
232 String
[] getLibClassIncluder(String libName
) {
233 return libClassHeaderList
.get(libName
);
237 getModuleTypeIncluder
239 This function is to get the header file name from module info map
240 according to module type.
242 @param moduleType Module type.
243 @return Name of header file.
245 String
getPackageIncluder(String moduleType
) {
246 return packageHeaderInfo
.get(moduleType
);
252 This function is to get the GUID's CName and it's GUID according to
255 @param guidName Name of GUID
256 @return CName and GUID.
258 public String
[] getGuidNameArray(String guidName
) {
259 return this.guidInfo
.get(guidName
);