]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
MsaOwner usable
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
index a07fe16f038a5d3f54af0dec3d6d6b29d0c069d1..68ddf40b3060a77380445cc722bddfa8854ce321 100644 (file)
+/** @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.migration;\r
 \r
 import java.io.*;\r
 import java.util.*;\r
+import java.util.regex.*;\r
 \r
-public class Database {\r
-       Database() throws Exception {\r
-               if (System.getenv("WORKSPACE") == null) {\r
-                       DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-               } else {\r
-                       DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-               }\r
-               \r
-               importDBLib("Library.csv");\r
-               importDBGuid("Guid.csv", "Guid");\r
-               importDBGuid("Ppi.csv", "Ppi");\r
-               importDBGuid("Protocol.csv", "Protocol");\r
-               importDBMacro("Macro.csv");\r
-       }\r
-       \r
-       public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-       \r
-       public String DatabasePath;\r
-       public Set<String> error = new HashSet<String>();\r
-       \r
-       private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
-       private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
-       private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
-       \r
-       private void importDBLib(String filename) throws Exception {\r
-               BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
-               String line;\r
-               String[] linecontext;\r
-               Func lf;\r
-               \r
-               if (rd.ready()) {\r
-                       System.out.println("Found " + filename + " , Importing Library Database");\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.length() != 0) {\r
-                                       linecontext = line.split(",");\r
-                               lf = new Func(linecontext);\r
-                               hashfunc.put(lf.r8funcname,lf);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       private void importDBGuid(String filename, String type) throws Exception {\r
-               BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
-               String line;\r
-               String[] linecontext;\r
-               Guid gu;\r
-               \r
-               if (rd.ready()) {\r
-                       System.out.println("Found " + filename + " , Importing " + type + " Database");\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.length() != 0) {\r
-                                       linecontext = line.split(",");\r
-                               gu = new Guid(linecontext, type);\r
-                           hashguid.put(gu.r8name,gu);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       private void importDBMacro(String filename) throws Exception {\r
-               BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
-               String line;\r
-               String[] linecontext;\r
-               Macro mc;\r
-               \r
-               if (rd.ready()) {\r
-                       System.out.println("Found " + filename + " , Importing Macro Database");\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.length() != 0) {\r
-                                       linecontext = line.split(",");\r
-                               mc = new Macro(linecontext);\r
-                               hashmacro.put(mc.r8name,mc);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       public String getR9Lib(String r8funcname) {\r
-               String temp = null;\r
-               if (hashfunc.containsKey(r8funcname)) {\r
-                       temp = hashfunc.get(r8funcname).r9libname;\r
-               }\r
-               return temp;\r
-       }\r
-       \r
-       public String getR9Func(String r8funcname) {\r
-               String temp = null;\r
-               if (hashfunc.containsKey(r8funcname)) {\r
-                       temp = hashfunc.get(r8funcname).r9funcname;\r
-               }\r
-               return temp;\r
-       }\r
-       \r
-       public boolean hasFunc(String r8lib) {\r
-               return hashfunc.containsKey(r8lib);\r
-       }\r
+public final class Database {\r
+    private static final Database INSTANCE = Database.init();\r
+    \r
+    Database(String path) {\r
+        DatabasePath = path;\r
 \r
-       public boolean hasGuid(String r8guid) {\r
-               return hashguid.containsKey(r8guid);\r
-       }\r
+        try {\r
+            importDBLib("Library.csv");\r
+            importDBGuid("Guid.csv", "Guid");\r
+            importDBGuid("Ppi.csv", "Ppi");\r
+            importDBGuid("Protocol.csv", "Protocol");\r
+            importDBMacro("Macro.csv");\r
+            importListR8Only();\r
+        } catch (Exception e) {\r
+            System.out.println(e.getMessage());\r
+        }\r
+    }\r
+    \r
+    public String DatabasePath;\r
+    public Set<String> error = new HashSet<String>();\r
+    public Set<String> r8only = new HashSet<String>();\r
+    \r
+    private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
+    private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
+    private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
+    \r
+    //-------------------------------------import------------------------------------------//\r
+    \r
+    private void importDBLib(String filename) throws Exception {\r
+        BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+        String line;\r
+        String[] linecontext;\r
+        Func lf;\r
+        \r
+        if (rd.ready()) {\r
+            System.out.println("Found " + filename + ", Importing Library Database.");\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.length() != 0) {\r
+                    linecontext = line.split(",");\r
+                    lf = new Func(linecontext);\r
+                    hashfunc.put(lf.r8funcname,lf);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    \r
+    private void importDBGuid(String filename, String type) throws Exception {\r
+        BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+        String line;\r
+        String[] linecontext;\r
+        Guid gu;\r
+        \r
+        if (rd.ready()) {\r
+            System.out.println("Found " + filename + ", Importing " + type + " Database.");\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.length() != 0) {\r
+                    linecontext = line.split(",");\r
+                    gu = new Guid(linecontext, type);\r
+                    hashguid.put(gu.r8name,gu);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    \r
+    private void importDBMacro(String filename) throws Exception {\r
+        BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+        String line;\r
+        String[] linecontext;\r
+        Macro mc;\r
+        \r
+        if (rd.ready()) {\r
+            System.out.println("Found " + filename + ", Importing Macro Database.");\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.length() != 0) {\r
+                    linecontext = line.split(",");\r
+                    mc = new Macro(linecontext);\r
+                    hashmacro.put(mc.r8name,mc);\r
+                }\r
+            }\r
+        }\r
+    }\r
 \r
-       public boolean hasMacro(String r8macro) {\r
-               return hashmacro.containsKey(r8macro);\r
-       }\r
-       \r
-       public String getR9Macro(String r8macro) {\r
-               return hashmacro.get(r8macro).r9name;                   // the verification job of if the macro exists in the database is done when registering it\r
-       }\r
-       \r
-       public String getR9Guidname(String r8Guid) {\r
-               String temp = null;\r
-               try {\r
-                       temp = hashguid.get(r8Guid).r9name;\r
-               } catch (NullPointerException e) {\r
-                       error.add("getR9Guidname :" + r8Guid);\r
-               }\r
-               return temp;\r
-       }\r
-       \r
-       public String getGuidType(String r8Guid) {\r
-               String temp = null;\r
-               try {\r
-                       temp =  hashguid.get(r8Guid).type;\r
-               } catch (NullPointerException e) {\r
-                       error.add("getR9Guidname :" + r8Guid);\r
-               }\r
-               return temp;\r
-       }\r
+    private void importListR8Only() throws Exception {\r
+        Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
+        String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");\r
+        System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
+        Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
+        while (mtrr8only.find()) {\r
+            r8only.add(mtrr8only.group(2));\r
+        }\r
+    }\r
+    \r
+    //-------------------------------------import------------------------------------------//\r
+\r
+    //-------------------------------------get------------------------------------------//\r
+\r
+    public String getR9Lib(String r8funcname) {\r
+        String temp = null;\r
+        if (hashfunc.containsKey(r8funcname)) {\r
+            temp = hashfunc.get(r8funcname).r9libname;\r
+        }\r
+        return temp;\r
+    }\r
+    \r
+    public String getR9Func(String r8funcname) {\r
+        String temp = null;\r
+        if (hashfunc.containsKey(r8funcname)) {\r
+            temp = hashfunc.get(r8funcname).r9funcname;\r
+        }\r
+        return temp;\r
+    }\r
+    \r
+    public String getR9Macro(String r8macro) {\r
+        return hashmacro.get(r8macro).r9name;            // the verification job of if the macro exists in the database is done when registering it\r
+    }\r
+\r
+    public String getR9Guidname(String r8Guid) {\r
+        String temp = null;\r
+        try {\r
+            temp = hashguid.get(r8Guid).r9name;\r
+        } catch (NullPointerException e) {\r
+            error.add("getR9Guidname :" + r8Guid);\r
+        }\r
+        return temp;\r
+    }\r
+\r
+    public String getGuidType(String r8Guid) {\r
+        String temp = null;\r
+        try {\r
+            temp =  hashguid.get(r8Guid).type;\r
+        } catch (NullPointerException e) {\r
+            error.add("getR9Guidname :" + r8Guid);\r
+        }\r
+        return temp;\r
+    }\r
+\r
+    //-------------------------------------get------------------------------------------//\r
+\r
+    //-------------------------------------has------------------------------------------//\r
+\r
+    public boolean hasFunc(String r8lib) {\r
+        return hashfunc.containsKey(r8lib);\r
+    }\r
+\r
+    public boolean hasGuid(String r8guid) {\r
+        return hashguid.containsKey(r8guid);\r
+    }\r
+\r
+    public boolean hasMacro(String r8macro) {\r
+        return hashmacro.containsKey(r8macro);\r
+    }\r
+    \r
+    //-------------------------------------has------------------------------------------//\r
+    \r
+    //-------------------------------------init------------------------------------------//\r
+\r
+    private static final Database init() {\r
+        if (System.getenv("WORKSPACE") == null) {\r
+            return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
+        } else {\r
+            return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
+        }\r
+    }\r
+    \r
+    public static final Database getInstance() {\r
+        return INSTANCE;\r
+    }\r
 }\r