]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java
Enhance MsaOwner.java
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / Database.java
CommitLineData
b0282412 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
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
eee63a7b 17import java.util.regex.*;\r
0dc8c589 18\r
7bcb8d17 19public final class Database {\r
27e0221a 20 private static final Database INSTANCE = Database.init();\r
21 \r
22 Database(String path) {\r
23 DatabasePath = path;\r
4f60c26f 24\r
27e0221a 25 try {\r
9c0e70cb 26 importPkgGuid("PkgGuid.csv");\r
27e0221a 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
9c0e70cb 45 private Map<String,String> hashPkgGuid = new HashMap<String,String>();\r
27e0221a 46 \r
47 //-------------------------------------import------------------------------------------//\r
9c0e70cb 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
9c0e70cb 52 \r
53 if (rd.ready()) {\r
54 System.out.println("Found " + filename + ", Importing Package Guid Database.");\r
55 //\r
56 // Skip the title row.\r
57 // \r
58 line = rd.readLine();\r
59 while ((line = rd.readLine()) != null) {\r
60 if (line.length() != 0) {\r
61 linecontext = line.split(",");\r
62 hashPkgGuid.put(linecontext[0], linecontext[1]);\r
63 }\r
64 }\r
65 }\r
66 }\r
67 public Iterator<String> dumpAllPkgGuid() {\r
68 return hashPkgGuid.values().iterator();\r
69 }\r
27e0221a 70 private void importDBLib(String filename) throws Exception {\r
71 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
72 String line;\r
73 String[] linecontext;\r
74 Func lf;\r
75 \r
76 if (rd.ready()) {\r
77 System.out.println("Found " + filename + ", Importing Library Database.");\r
78 while ((line = rd.readLine()) != null) {\r
79 if (line.length() != 0) {\r
80 linecontext = line.split(",");\r
81 lf = new Func(linecontext);\r
82 hashfunc.put(lf.r8funcname,lf);\r
83 }\r
84 }\r
85 }\r
86 }\r
87 \r
88 private void importDBGuid(String filename, String type) throws Exception {\r
89 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
90 String line;\r
91 String[] linecontext;\r
92 Guid gu;\r
93 \r
94 if (rd.ready()) {\r
95 System.out.println("Found " + filename + ", Importing " + type + " Database.");\r
96 while ((line = rd.readLine()) != null) {\r
97 if (line.length() != 0) {\r
98 linecontext = line.split(",");\r
99 gu = new Guid(linecontext, type);\r
100 hashguid.put(gu.r8name,gu);\r
101 }\r
102 }\r
103 }\r
104 }\r
105 \r
106 private void importDBMacro(String filename) throws Exception {\r
107 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
108 String line;\r
109 String[] linecontext;\r
110 Macro mc;\r
111 \r
112 if (rd.ready()) {\r
113 System.out.println("Found " + filename + ", Importing Macro Database.");\r
114 while ((line = rd.readLine()) != null) {\r
115 if (line.length() != 0) {\r
116 linecontext = line.split(",");\r
117 mc = new Macro(linecontext);\r
118 hashmacro.put(mc.r8name,mc);\r
119 }\r
120 }\r
121 }\r
122 }\r
eee63a7b 123\r
27e0221a 124 private void importListR8Only() throws Exception {\r
125 Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
126 String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");\r
127 System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
128 Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
129 while (mtrr8only.find()) {\r
130 r8only.add(mtrr8only.group(2));\r
131 }\r
132 }\r
133 \r
134 //-------------------------------------import------------------------------------------//\r
eee63a7b 135\r
27e0221a 136 //-------------------------------------get------------------------------------------//\r
eee63a7b 137\r
27e0221a 138 public String getR9Lib(String r8funcname) {\r
139 String temp = null;\r
140 if (hashfunc.containsKey(r8funcname)) {\r
141 temp = hashfunc.get(r8funcname).r9libname;\r
142 }\r
143 return temp;\r
144 }\r
145 \r
146 public String getR9Func(String r8funcname) {\r
147 String temp = null;\r
148 if (hashfunc.containsKey(r8funcname)) {\r
149 temp = hashfunc.get(r8funcname).r9funcname;\r
150 }\r
151 return temp;\r
152 }\r
153 \r
154 public String getR9Macro(String r8macro) {\r
155 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
156 }\r
7bcb8d17 157\r
27e0221a 158 public String getR9Guidname(String r8Guid) {\r
159 String temp = null;\r
160 try {\r
161 temp = hashguid.get(r8Guid).r9name;\r
162 } catch (NullPointerException e) {\r
163 error.add("getR9Guidname :" + r8Guid);\r
164 }\r
165 return temp;\r
166 }\r
7bcb8d17 167\r
27e0221a 168 public String getGuidType(String r8Guid) {\r
169 String temp = null;\r
170 try {\r
171 temp = hashguid.get(r8Guid).type;\r
172 } catch (NullPointerException e) {\r
173 error.add("getR9Guidname :" + r8Guid);\r
174 }\r
175 return temp;\r
176 }\r
7bcb8d17 177\r
27e0221a 178 //-------------------------------------get------------------------------------------//\r
eee63a7b 179\r
27e0221a 180 //-------------------------------------has------------------------------------------//\r
eee63a7b 181\r
27e0221a 182 public boolean hasFunc(String r8lib) {\r
183 return hashfunc.containsKey(r8lib);\r
184 }\r
eee63a7b 185\r
27e0221a 186 public boolean hasGuid(String r8guid) {\r
187 return hashguid.containsKey(r8guid);\r
188 }\r
eee63a7b 189\r
27e0221a 190 public boolean hasMacro(String r8macro) {\r
191 return hashmacro.containsKey(r8macro);\r
192 }\r
193 \r
194 //-------------------------------------has------------------------------------------//\r
195 \r
196 //-------------------------------------init------------------------------------------//\r
4f60c26f 197\r
27e0221a 198 private static final Database init() {\r
199 if (System.getenv("WORKSPACE") == null) {\r
200 return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
201 } else {\r
202 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
203 }\r
204 }\r
205 \r
206 public static final Database getInstance() {\r
207 return INSTANCE;\r
208 }\r
0dc8c589 209}\r