+++ /dev/null
-/** @file\r
- Spd class.\r
-\r
- This class is to generate a global table for the content of spd file.\r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- **/\r
-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.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
-public class Spd {\r
- ///\r
- ///\r
- ///\r
- Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();\r
-\r
- ///\r
- /// Map of module info. \r
- /// Key : moduletype\r
- /// Value: moduletype related include file\r
- ///\r
- Map<String, String> packageHeaderInfo = new HashMap<String, String>();\r
-\r
- ///\r
- /// Map of PPI info.\r
- /// Key : PPI name\r
- /// value: String[] a. PPI C_NAME; b. PPI GUID;\r
- ///\r
- Map<String, String[]> ppiInfo = new HashMap<String, String[]>();\r
-\r
- ///\r
- /// Map of Protocol info.\r
- /// Key : Protocol name\r
- /// value: String[] a. Protocol C_NAME; b. Protocol GUID;\r
- ///\r
- Map<String, String[]> protocolInfo = new HashMap<String, String[]>();\r
-\r
- ///\r
- /// Map of Guid info.\r
- /// Key : Guid name\r
- /// value: String[] a. Guid C_NAME; b. Guid's GUID;\r
- ///\r
- Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
-\r
- ///\r
- /// Map of Guid info\r
- /// Key: GuidCName\r
- /// value: String Guid's GUID\r
- ///\r
- Map<String, String> guidCnameInfo = new HashMap<String, String>();\r
- \r
- /// Map of library class and its exposed header file.\r
- /// Key : library class name\r
- /// value : library class corresponding header file\r
- ///\r
- Map<String, String[]> libClassHeaderList = new HashMap<String, String[]>();\r
-\r
- ///\r
- /// Package path.\r
- ///\r
- PackageIdentification packageId;\r
-\r
- /**\r
- Constructor function\r
- \r
- This function mainly initialize some member variables. \r
- **/\r
- Spd(File packageFile) throws EdkException {\r
- //\r
- // If specified package file not exists\r
- //\r
- if ( ! packageFile.exists()) {\r
- throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");\r
- }\r
- try {\r
- XmlObject spdDoc = GlobalData.parseXmlFile(packageFile);\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 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 = 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
- 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 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
- //\r
- // initialize Package header files\r
- //\r
- Map<String, String> packageHeaders = saq.getSpdPackageHeaderFiles();\r
- Set keys = packageHeaders.keySet();\r
- Iterator iter = keys.iterator();\r
- while (iter.hasNext()){\r
- String moduleType = (String)iter.next();\r
- String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);\r
- \r
- //\r
- // Change path seperator to system-dependent path separator\r
- //\r
- File file = new File (header);\r
- header = file.getPath();\r
- packageHeaderInfo.put(moduleType, header);\r
- }\r
- \r
- //\r
- // initialize Guid Info\r
- //\r
- guidInfo.putAll(saq.getSpdGuid());\r
- \r
- //\r
- // For Pcd get TokenSpaceGuid\r
- //\r
- Set<String> key = guidInfo.keySet();\r
- Iterator item = key.iterator();\r
- String [] nameValue = new String[2];\r
- while(item.hasNext()){\r
- nameValue = guidInfo.get(item.next());\r
- guidCnameInfo.put(nameValue[0], nameValue[1]);\r
- }\r
- \r
- //\r
- // initialize PPI info\r
- //\r
- ppiInfo.putAll(saq.getSpdPpi());\r
- \r
- //\r
- // initialize Protocol info\r
- //\r
- protocolInfo.putAll(saq.getSpdProtocol());\r
- \r
- //\r
- // initialize library class declaration\r
- //\r
- Map<String, String[]> libraryClassHeaders = saq.getSpdLibraryClasses();\r
- keys = libraryClassHeaders.keySet();\r
- iter = keys.iterator();\r
- while (iter.hasNext()){\r
- String libraryClassName = (String)iter.next();\r
- String[] headerFiles = libraryClassHeaders.get(libraryClassName);\r
- for (int i = 0; i < headerFiles.length; i++){\r
- headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i];\r
- \r
- //\r
- // Change path separator to system system-dependent path separator. \r
- //\r
- File file = new File (headerFiles[i]);\r
- headerFiles[i] = file.getPath();\r
- }\r
- libClassHeaderList.put(libraryClassName, headerFiles);\r
- }\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
- public PackageIdentification getPackageId() {\r
- return packageId;\r
- }\r
-\r
- public File getModuleFile(ModuleIdentification moduleId) {\r
- return msaInfo.get(moduleId);\r
- }\r
- \r
- public Set<ModuleIdentification> getModules(){\r
- return msaInfo.keySet();\r
- }\r
-\r
- /**\r
- return two value {CName, Guid}. If not found, return null.\r
- **/\r
- public String[] getPpi(String ppiName) {\r
- return ppiInfo.get(ppiName);\r
- }\r
-\r
- /**\r
- return two value {CName, Guid}. If not found, return null.\r
- **/\r
- public String[] getProtocol(String protocolName) {\r
- return protocolInfo.get(protocolName);\r
- }\r
-\r
- /**\r
- return two value {CName, Guid}. If not found, return null.\r
- **/\r
- public String[] getGuid(String guidName) {\r
- return guidInfo.get(guidName);\r
- }\r
-\r
- /**\r
- * return Guid Value. \r
- */\r
- public String getGuidFromCname(String cName){\r
- return guidCnameInfo.get(cName);\r
- }\r
- \r
- /**\r
- getLibClassInclude \r
- \r
- This function is to get the library exposed header file name according \r
- library class name.\r
- \r
- @param libName Name of library class \r
- @return Name of header file\r
- **/\r
- String[] getLibClassIncluder(String libName) {\r
- return libClassHeaderList.get(libName);\r
- }\r
-\r
- /**\r
- getModuleTypeIncluder\r
- \r
- This function is to get the header file name from module info map \r
- according to module type.\r
- \r
- @param moduleType Module type.\r
- @return Name of header file.\r
- **/\r
- String getPackageIncluder(String moduleType) {\r
- return packageHeaderInfo.get(moduleType);\r
- }\r
- \r
-\r
-}\r