1 package org
.tianocore
.migration
;
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";
11 DatabasePath
= System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration";
14 importDBLib("Library.csv");
15 importDBGuid("Guid.csv", "Guid");
16 importDBGuid("Ppi.csv", "Ppi");
17 importDBGuid("Protocol.csv", "Protocol");
18 importDBMacro("Macro.csv");
21 public static String defaultpath
= "C:" + File
.separator
+ "tianocore" + File
.separator
+ "edk2" + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration";
23 public String DatabasePath
;
24 public Set
<String
> error
= new HashSet
<String
>();
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
>();
30 private void importDBLib(String filename
) throws Exception
{
31 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
48 private void importDBGuid(String filename
, String type
) throws Exception
{
49 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
66 private void importDBMacro(String filename
) throws Exception
{
67 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
84 public String
getR9Lib(String r8funcname
) {
86 if (hashfunc
.containsKey(r8funcname
)) {
87 temp
= hashfunc
.get(r8funcname
).r9libname
;
92 public String
getR9Func(String r8funcname
) {
94 if (hashfunc
.containsKey(r8funcname
)) {
95 temp
= hashfunc
.get(r8funcname
).r9funcname
;
100 public boolean hasFunc(String r8lib
) {
101 return hashfunc
.containsKey(r8lib
);
104 public boolean hasGuid(String r8guid
) {
105 return hashguid
.containsKey(r8guid
);
108 public boolean hasMacro(String r8macro
) {
109 return hashmacro
.containsKey(r8macro
);
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
116 public String
getR9Guidname(String r8Guid
) {
119 temp
= hashguid
.get(r8Guid
).r9name
;
120 } catch (NullPointerException e
) {
121 error
.add("getR9Guidname :" + r8Guid
);
126 public String
getGuidType(String r8Guid
) {
129 temp
= hashguid
.get(r8Guid
).type
;
130 } catch (NullPointerException e
) {
131 error
.add("getR9Guidname :" + r8Guid
);