]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java
Add Package-Guid Map.
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / Database.java
... / ...
CommitLineData
1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17import java.util.regex.*;\r
18\r
19public final class Database {\r
20 private static final Database INSTANCE = Database.init();\r
21 \r
22 Database(String path) {\r
23 DatabasePath = path;\r
24\r
25 try {\r
26 importPkgGuid("PkgGuid.csv");\r
27 importDBLib("Library.csv");\r
28 importDBGuid("Guid.csv", "Guid");\r
29 importDBGuid("Ppi.csv", "Ppi");\r
30 importDBGuid("Protocol.csv", "Protocol");\r
31 importDBMacro("Macro.csv");\r
32 importListR8Only();\r
33 } catch (Exception e) {\r
34 System.out.println(e.getMessage());\r
35 }\r
36 }\r
37 \r
38 public String DatabasePath;\r
39 public Set<String> error = new HashSet<String>();\r
40 public Set<String> r8only = new HashSet<String>();\r
41 \r
42 private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
43 private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
44 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
45 private Map<String,String> hashPkgGuid = new HashMap<String,String>();\r
46 \r
47 //-------------------------------------import------------------------------------------//\r
48 private void importPkgGuid(String filename) throws Exception {\r
49 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
50 String line;\r
51 String[] linecontext;\r
52 Func lf;\r
53 \r
54 if (rd.ready()) {\r
55 System.out.println("Found " + filename + ", Importing Package Guid Database.");\r
56 //\r
57 // Skip the title row.\r
58 // \r
59 line = rd.readLine();\r
60 while ((line = rd.readLine()) != null) {\r
61 if (line.length() != 0) {\r
62 linecontext = line.split(",");\r
63 hashPkgGuid.put(linecontext[0], linecontext[1]);\r
64 }\r
65 }\r
66 }\r
67 }\r
68 public Iterator<String> dumpAllPkgGuid() {\r
69 return hashPkgGuid.values().iterator();\r
70 }\r
71 private void importDBLib(String filename) throws Exception {\r
72 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
73 String line;\r
74 String[] linecontext;\r
75 Func lf;\r
76 \r
77 if (rd.ready()) {\r
78 System.out.println("Found " + filename + ", Importing Library Database.");\r
79 while ((line = rd.readLine()) != null) {\r
80 if (line.length() != 0) {\r
81 linecontext = line.split(",");\r
82 lf = new Func(linecontext);\r
83 hashfunc.put(lf.r8funcname,lf);\r
84 }\r
85 }\r
86 }\r
87 }\r
88 \r
89 private void importDBGuid(String filename, String type) throws Exception {\r
90 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
91 String line;\r
92 String[] linecontext;\r
93 Guid gu;\r
94 \r
95 if (rd.ready()) {\r
96 System.out.println("Found " + filename + ", Importing " + type + " Database.");\r
97 while ((line = rd.readLine()) != null) {\r
98 if (line.length() != 0) {\r
99 linecontext = line.split(",");\r
100 gu = new Guid(linecontext, type);\r
101 hashguid.put(gu.r8name,gu);\r
102 }\r
103 }\r
104 }\r
105 }\r
106 \r
107 private void importDBMacro(String filename) throws Exception {\r
108 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
109 String line;\r
110 String[] linecontext;\r
111 Macro mc;\r
112 \r
113 if (rd.ready()) {\r
114 System.out.println("Found " + filename + ", Importing Macro Database.");\r
115 while ((line = rd.readLine()) != null) {\r
116 if (line.length() != 0) {\r
117 linecontext = line.split(",");\r
118 mc = new Macro(linecontext);\r
119 hashmacro.put(mc.r8name,mc);\r
120 }\r
121 }\r
122 }\r
123 }\r
124\r
125 private void importListR8Only() throws Exception {\r
126 Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
127 String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");\r
128 System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
129 Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
130 while (mtrr8only.find()) {\r
131 r8only.add(mtrr8only.group(2));\r
132 }\r
133 }\r
134 \r
135 //-------------------------------------import------------------------------------------//\r
136\r
137 //-------------------------------------get------------------------------------------//\r
138\r
139 public String getR9Lib(String r8funcname) {\r
140 String temp = null;\r
141 if (hashfunc.containsKey(r8funcname)) {\r
142 temp = hashfunc.get(r8funcname).r9libname;\r
143 }\r
144 return temp;\r
145 }\r
146 \r
147 public String getR9Func(String r8funcname) {\r
148 String temp = null;\r
149 if (hashfunc.containsKey(r8funcname)) {\r
150 temp = hashfunc.get(r8funcname).r9funcname;\r
151 }\r
152 return temp;\r
153 }\r
154 \r
155 public String getR9Macro(String r8macro) {\r
156 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
157 }\r
158\r
159 public String getR9Guidname(String r8Guid) {\r
160 String temp = null;\r
161 try {\r
162 temp = hashguid.get(r8Guid).r9name;\r
163 } catch (NullPointerException e) {\r
164 error.add("getR9Guidname :" + r8Guid);\r
165 }\r
166 return temp;\r
167 }\r
168\r
169 public String getGuidType(String r8Guid) {\r
170 String temp = null;\r
171 try {\r
172 temp = hashguid.get(r8Guid).type;\r
173 } catch (NullPointerException e) {\r
174 error.add("getR9Guidname :" + r8Guid);\r
175 }\r
176 return temp;\r
177 }\r
178\r
179 //-------------------------------------get------------------------------------------//\r
180\r
181 //-------------------------------------has------------------------------------------//\r
182\r
183 public boolean hasFunc(String r8lib) {\r
184 return hashfunc.containsKey(r8lib);\r
185 }\r
186\r
187 public boolean hasGuid(String r8guid) {\r
188 return hashguid.containsKey(r8guid);\r
189 }\r
190\r
191 public boolean hasMacro(String r8macro) {\r
192 return hashmacro.containsKey(r8macro);\r
193 }\r
194 \r
195 //-------------------------------------has------------------------------------------//\r
196 \r
197 //-------------------------------------init------------------------------------------//\r
198\r
199 private static final Database init() {\r
200 if (System.getenv("WORKSPACE") == null) {\r
201 return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
202 } else {\r
203 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
204 }\r
205 }\r
206 \r
207 public static final Database getInstance() {\r
208 return INSTANCE;\r
209 }\r
210}\r