package org.tianocore.build.global;\r
\r
import java.io.File;\r
+import java.io.IOException;\r
import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.Map;\r
import java.util.Set;\r
\r
-import org.apache.tools.ant.BuildException;\r
+import org.apache.xmlbeans.XmlException;\r
import org.apache.xmlbeans.XmlObject;\r
import org.tianocore.build.id.ModuleIdentification;\r
import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.common.exception.EdkException;\r
\r
/**\r
\r
This class is to generate a global table for the content of spd file.\r
\r
- **/\r
+**/\r
public class Spd {\r
///\r
///\r
\r
This function mainly initialize some member variables. \r
**/\r
- Spd(File packageFile) throws BuildException {\r
+ Spd(File packageFile) throws EdkException {\r
//\r
// If specified package file not exists\r
//\r
if ( ! packageFile.exists()) {\r
- throw new BuildException("Package file [" + packageFile.getPath() + "] does not exist!");\r
+ throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");\r
}\r
try {\r
XmlObject spdDoc = XmlObject.Factory.parse(packageFile);\r
// Verify SPD file, if is invalid, throw Exception\r
//\r
if (! spdDoc.validate()) {\r
- throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!");\r
+ throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!");\r
}\r
+ //\r
// We can change Map to XmlObject\r
+ //\r
Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();\r
spdDocMap.put("PackageSurfaceArea", spdDoc);\r
- SurfaceAreaQuery.setDoc(spdDocMap);\r
- //\r
- //\r
- //\r
- packageId = SurfaceAreaQuery.getSpdHeader();\r
+ SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap);\r
+\r
+ packageId = saq.getSpdHeader();\r
packageId.setSpdFile(packageFile);\r
\r
//\r
// initialize Msa Files\r
// MSA file is absolute file path\r
//\r
- String[] msaFilenames = SurfaceAreaQuery.getSpdMsaFile();\r
+ String[] msaFilenames = saq.getSpdMsaFile();\r
for (int i = 0; i < msaFilenames.length; i++){\r
File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);\r
Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );\r
- SurfaceAreaQuery.push(msaDoc);\r
- ModuleIdentification moduleId = SurfaceAreaQuery.getMsaHeader();\r
- SurfaceAreaQuery.pop();\r
+ saq.push(msaDoc);\r
+ ModuleIdentification moduleId = saq.getMsaHeader();\r
+ saq.pop();\r
moduleId.setPackage(packageId);\r
moduleId.setMsaFile(msaFile);\r
if (msaInfo.containsKey(moduleId)) {\r
- 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 + "]!");\r
+ 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 + "]!");\r
}\r
msaInfo.put(moduleId, msaFile);\r
}\r
//\r
// initialize Package header files\r
//\r
- Map<String, String> packageHeaders = SurfaceAreaQuery.getSpdPackageHeaderFiles();\r
+ Map<String, String> packageHeaders = saq.getSpdPackageHeaderFiles();\r
Set keys = packageHeaders.keySet();\r
Iterator iter = keys.iterator();\r
while (iter.hasNext()){\r
//\r
// initialize Guid Info\r
//\r
- guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());\r
+ guidInfo.putAll(saq.getSpdGuid());\r
\r
//\r
// For Pcd get TokenSpaceGuid\r
//\r
// initialize PPI info\r
//\r
- ppiInfo.putAll(SurfaceAreaQuery.getSpdPpi());\r
+ ppiInfo.putAll(saq.getSpdPpi());\r
\r
//\r
// initialize Protocol info\r
//\r
- protocolInfo.putAll(SurfaceAreaQuery.getSpdProtocol());\r
+ protocolInfo.putAll(saq.getSpdProtocol());\r
\r
//\r
// initialize library class declaration\r
//\r
- Map<String, String[]> libraryClassHeaders = SurfaceAreaQuery.getSpdLibraryClasses();\r
+ Map<String, String[]> libraryClassHeaders = saq.getSpdLibraryClasses();\r
keys = libraryClassHeaders.keySet();\r
iter = keys.iterator();\r
while (iter.hasNext()){\r
}\r
libClassHeaderList.put(libraryClassName, headerFiles);\r
}\r
- }\r
- catch (Exception e) {\r
- e.setStackTrace(e.getStackTrace());\r
- throw new BuildException("Parse of the package description file [" + packageId.getSpdFile() + "] failed!\n"\r
- + e.getMessage());\r
+ } catch (IOException ex) {\r
+ EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ edkException.setStackTrace(ex.getStackTrace());\r
+ throw edkException;\r
+ } catch (XmlException ex) {\r
+ EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ edkException.setStackTrace(ex.getStackTrace());\r
+ throw edkException;\r
}\r
}\r
\r