import java.util.*;\r
import java.util.regex.*;\r
\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.apache.xmlbeans.XmlObject.Factory;\r
+import org.tianocore.DbPathAndFilename;\r
+import org.tianocore.FrameworkDatabaseDocument;\r
+import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r
+import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r
+import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;\r
+import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;\r
+\r
+import org.tianocore.PackageListDocument.PackageList;\r
+import org.tianocore.PackageSurfaceAreaDocument;\r
+import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
+\r
public final class Database {\r
private static final Database INSTANCE = Database.init();\r
\r
DatabasePath = path;\r
\r
try {\r
+ // collectWorkSpaceDatabase();\r
importPkgGuid("PkgGuid.csv");\r
importDBLib("Library.csv");\r
importDBGuid("Guid.csv", "Guid");\r
private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
private Map<String,String> hashPkgGuid = new HashMap<String,String>();\r
+\r
\r
//-------------------------------------import------------------------------------------//\r
private void importPkgGuid(String filename) throws Exception {\r
public static final Database getInstance() {\r
return INSTANCE;\r
}\r
+\r
+ private HashMap<String, String> hashDatabaseGuids = new HashMap<String, String> ();\r
+ private HashMap<String, String> hashDatabasePpis = new HashMap<String, String> ();\r
+ private HashMap<String, String> hashDatabaseProtocols = new HashMap<String, String> ();\r
+\r
+ private final void collectGuidDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
+ String pkgGuid;\r
+ Iterator<GuidDeclarations.Entry> itGuids;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+\r
+ itGuids = spdDatabase.getGuidDeclarations().getEntryList().iterator();\r
+ while (itGuids.hasNext()) {\r
+ hashDatabaseGuids.put(itGuids.next().getCName(), pkgGuid); \r
+ }\r
+ }\r
+\r
+ private final void collectPpiDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
+ String pkgGuid;\r
+ Iterator<PpiDeclarations.Entry> itPpis;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+\r
+ itPpis = spdDatabase.getPpiDeclarations().getEntryList().iterator();\r
+ while (itPpis.hasNext()) {\r
+ hashDatabasePpis.put(itPpis.next().getCName(), pkgGuid); \r
+ }\r
+ }\r
+\r
+ private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase) throws Exception {\r
+ String pkgGuid;\r
+ Iterator<ProtocolDeclarations.Entry> itProtocols;\r
+\r
+ pkgGuid = spdDatabase.getSpdHeader().getGuidValue();\r
+\r
+ itProtocols = spdDatabase.getProtocolDeclarations().getEntryList().iterator();\r
+ while (itProtocols.hasNext()) {\r
+ hashDatabaseGuids.put(itProtocols.next().getCName(), pkgGuid); \r
+ }\r
+ }\r
+\r
+ private final void collectPackageDatabase(String packageFileName) throws Exception {\r
+ XmlObject xmlPackage;\r
+ PackageSurfaceArea spdDatabase;\r
+\r
+ xmlPackage = XmlObject.Factory.parse(new File(packageFileName));\r
+ spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage).getPackageSurfaceArea();\r
+\r
+ collectGuidDatabase(spdDatabase);\r
+ collectProtocolDatabase(spdDatabase);\r
+ collectPpiDatabase(spdDatabase);\r
+\r
+\r
+ }\r
+ public final void collectWorkSpaceDatabase() throws Exception {\r
+ String workspacePath;\r
+ String databaseFileName;\r
+ File databaseFile;\r
+ XmlObject xmlDatabase;\r
+ FrameworkDatabase frameworkDatabase;\r
+ Iterator<DbPathAndFilename> packageFile;\r
+ \r
+ workspacePath = System.getenv("WORKSPACE");\r
+ \r
+ if (workspacePath == null) {\r
+ String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";\r
+ throw new Exception(errorMessage);\r
+ }\r
+ databaseFileName = workspacePath + File.separator + \r
+ "Tools" + File.separator +\r
+ "Conf" + File.separator + \r
+ "FrameworkDatabase.db";\r
+ System.out.println("Open " + databaseFileName);\r
+ databaseFile = new File(databaseFileName);\r
+ xmlDatabase = XmlObject.Factory.parse(databaseFile);\r
+ frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase).getFrameworkDatabase();\r
+ packageFile = frameworkDatabase.getPackageList().getFilenameList().iterator();\r
+\r
+ while (packageFile.hasNext()) {\r
+ String packageFileName = packageFile.next().getStringValue();\r
+ packageFileName = workspacePath + File.separator + packageFileName;\r
+ packageFileName = packageFileName.replace("/", File.separator);\r
+\r
+ System.out.println("Parse: " + packageFileName);\r
+ try {\r
+ collectPackageDatabase(packageFileName);\r
+ } catch (Exception e) {\r
+ System.out.println("Error occured when opening " + packageFileName + e.getMessage());\r
+ }\r
+ }\r
+ return;\r
+ }\r
+ \r
}\r