]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1239 6f19259b...
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
1 package org.tianocore.migration;
2
3 import java.io.*;
4 import java.util.*;
5
6 public class Database {
7 Database() throws Exception {
8 if (System.getenv("WORKSPACE") == null) {
9 DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";
10 } else {
11 DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";
12 }
13
14 importDBLib("Library.csv");
15 importDBGuid("Guid.csv", "Guid");
16 importDBGuid("Ppi.csv", "Ppi");
17 importDBGuid("Protocol.csv", "Protocol");
18 importDBMacro("Macro.csv");
19 }
20
21 public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";
22
23 public String DatabasePath;
24 public Set<String> error = new HashSet<String>();
25
26 private Map<String,Guid> hashguid = new HashMap<String,Guid>();
27 private Map<String,Func> hashfunc = new HashMap<String,Func>();
28 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();
29
30 private void importDBLib(String filename) throws Exception {
31 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
32 String line;
33 String[] linecontext;
34 Func lf;
35
36 if (rd.ready()) {
37 System.out.println("Found " + filename + " , Importing Library Database");
38 while ((line = rd.readLine()) != null) {
39 if (line.length() != 0) {
40 linecontext = line.split(",");
41 lf = new Func(linecontext);
42 hashfunc.put(lf.r8funcname,lf);
43 }
44 }
45 }
46 }
47
48 private void importDBGuid(String filename, String type) throws Exception {
49 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
50 String line;
51 String[] linecontext;
52 Guid gu;
53
54 if (rd.ready()) {
55 System.out.println("Found " + filename + " , Importing " + type + " Database");
56 while ((line = rd.readLine()) != null) {
57 if (line.length() != 0) {
58 linecontext = line.split(",");
59 gu = new Guid(linecontext, type);
60 hashguid.put(gu.r8name,gu);
61 }
62 }
63 }
64 }
65
66 private void importDBMacro(String filename) throws Exception {
67 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
68 String line;
69 String[] linecontext;
70 Macro mc;
71
72 if (rd.ready()) {
73 System.out.println("Found " + filename + " , Importing Macro Database");
74 while ((line = rd.readLine()) != null) {
75 if (line.length() != 0) {
76 linecontext = line.split(",");
77 mc = new Macro(linecontext);
78 hashmacro.put(mc.r8name,mc);
79 }
80 }
81 }
82 }
83
84 public String getR9Lib(String r8funcname) {
85 String temp = null;
86 if (hashfunc.containsKey(r8funcname)) {
87 temp = hashfunc.get(r8funcname).r9libname;
88 }
89 return temp;
90 }
91
92 public String getR9Func(String r8funcname) {
93 String temp = null;
94 if (hashfunc.containsKey(r8funcname)) {
95 temp = hashfunc.get(r8funcname).r9funcname;
96 }
97 return temp;
98 }
99
100 public boolean hasFunc(String r8lib) {
101 return hashfunc.containsKey(r8lib);
102 }
103
104 public boolean hasGuid(String r8guid) {
105 return hashguid.containsKey(r8guid);
106 }
107
108 public boolean hasMacro(String r8macro) {
109 return hashmacro.containsKey(r8macro);
110 }
111
112 public String getR9Macro(String r8macro) {
113 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it
114 }
115
116 public String getR9Guidname(String r8Guid) {
117 String temp = null;
118 try {
119 temp = hashguid.get(r8Guid).r9name;
120 } catch (NullPointerException e) {
121 error.add("getR9Guidname :" + r8Guid);
122 }
123 return temp;
124 }
125
126 public String getGuidType(String r8Guid) {
127 String temp = null;
128 try {
129 temp = hashguid.get(r8Guid).type;
130 } catch (NullPointerException e) {
131 error.add("getR9Guidname :" + r8Guid);
132 }
133 return temp;
134 }
135 }