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