From e83a1d9ad3477b25611dbe52d2fe218944a915a5 Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Fri, 27 Oct 2006 08:57:25 +0000 Subject: Preparative work to collect Ppis, Guids & Protocols info from workspace dynamically. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1850 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/migration/Database.java | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java b/Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java index 646158557b..686dbe32b4 100644 --- a/Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java +++ b/Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java @@ -16,6 +16,19 @@ import java.io.*; import java.util.*; import java.util.regex.*; +import org.apache.xmlbeans.XmlObject; +import org.apache.xmlbeans.XmlObject.Factory; +import org.tianocore.DbPathAndFilename; +import org.tianocore.FrameworkDatabaseDocument; +import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase; +import org.tianocore.GuidDeclarationsDocument.GuidDeclarations; +import org.tianocore.PpiDeclarationsDocument.PpiDeclarations; +import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations; + +import org.tianocore.PackageListDocument.PackageList; +import org.tianocore.PackageSurfaceAreaDocument; +import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea; + public final class Database { private static final Database INSTANCE = Database.init(); @@ -23,6 +36,7 @@ public final class Database { DatabasePath = path; try { + // collectWorkSpaceDatabase(); importPkgGuid("PkgGuid.csv"); importDBLib("Library.csv"); importDBGuid("Guid.csv", "Guid"); @@ -43,6 +57,7 @@ public final class Database { private Map hashfunc = new HashMap(); private Map hashmacro = new HashMap(); private Map hashPkgGuid = new HashMap(); + //-------------------------------------import------------------------------------------// private void importPkgGuid(String filename) throws Exception { @@ -206,4 +221,97 @@ public final class Database { public static final Database getInstance() { return INSTANCE; } + + private HashMap hashDatabaseGuids = new HashMap (); + private HashMap hashDatabasePpis = new HashMap (); + private HashMap hashDatabaseProtocols = new HashMap (); + + private final void collectGuidDatabase(PackageSurfaceArea spdDatabase) throws Exception { + String pkgGuid; + Iterator itGuids; + + pkgGuid = spdDatabase.getSpdHeader().getGuidValue(); + + itGuids = spdDatabase.getGuidDeclarations().getEntryList().iterator(); + while (itGuids.hasNext()) { + hashDatabaseGuids.put(itGuids.next().getCName(), pkgGuid); + } + } + + private final void collectPpiDatabase(PackageSurfaceArea spdDatabase) throws Exception { + String pkgGuid; + Iterator itPpis; + + pkgGuid = spdDatabase.getSpdHeader().getGuidValue(); + + itPpis = spdDatabase.getPpiDeclarations().getEntryList().iterator(); + while (itPpis.hasNext()) { + hashDatabasePpis.put(itPpis.next().getCName(), pkgGuid); + } + } + + private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase) throws Exception { + String pkgGuid; + Iterator itProtocols; + + pkgGuid = spdDatabase.getSpdHeader().getGuidValue(); + + itProtocols = spdDatabase.getProtocolDeclarations().getEntryList().iterator(); + while (itProtocols.hasNext()) { + hashDatabaseGuids.put(itProtocols.next().getCName(), pkgGuid); + } + } + + private final void collectPackageDatabase(String packageFileName) throws Exception { + XmlObject xmlPackage; + PackageSurfaceArea spdDatabase; + + xmlPackage = XmlObject.Factory.parse(new File(packageFileName)); + spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage).getPackageSurfaceArea(); + + collectGuidDatabase(spdDatabase); + collectProtocolDatabase(spdDatabase); + collectPpiDatabase(spdDatabase); + + + } + public final void collectWorkSpaceDatabase() throws Exception { + String workspacePath; + String databaseFileName; + File databaseFile; + XmlObject xmlDatabase; + FrameworkDatabase frameworkDatabase; + Iterator packageFile; + + workspacePath = System.getenv("WORKSPACE"); + + if (workspacePath == null) { + String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!"; + throw new Exception(errorMessage); + } + databaseFileName = workspacePath + File.separator + + "Tools" + File.separator + + "Conf" + File.separator + + "FrameworkDatabase.db"; + System.out.println("Open " + databaseFileName); + databaseFile = new File(databaseFileName); + xmlDatabase = XmlObject.Factory.parse(databaseFile); + frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase).getFrameworkDatabase(); + packageFile = frameworkDatabase.getPackageList().getFilenameList().iterator(); + + while (packageFile.hasNext()) { + String packageFileName = packageFile.next().getStringValue(); + packageFileName = workspacePath + File.separator + packageFileName; + packageFileName = packageFileName.replace("/", File.separator); + + System.out.println("Parse: " + packageFileName); + try { + collectPackageDatabase(packageFileName); + } catch (Exception e) { + System.out.println("Error occured when opening " + packageFileName + e.getMessage()); + } + } + return; + } + } -- cgit v1.2.3