68ddf40b3060a77380445cc722bddfa8854ce321
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
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.
13 package org
.tianocore
.migration
;
17 import java
.util
.regex
.*;
19 public final class Database
{
20 private static final Database INSTANCE
= Database
.init();
22 Database(String path
) {
26 importDBLib("Library.csv");
27 importDBGuid("Guid.csv", "Guid");
28 importDBGuid("Ppi.csv", "Ppi");
29 importDBGuid("Protocol.csv", "Protocol");
30 importDBMacro("Macro.csv");
32 } catch (Exception e
) {
33 System
.out
.println(e
.getMessage());
37 public String DatabasePath
;
38 public Set
<String
> error
= new HashSet
<String
>();
39 public Set
<String
> r8only
= new HashSet
<String
>();
41 private Map
<String
,Guid
> hashguid
= new HashMap
<String
,Guid
>();
42 private Map
<String
,Func
> hashfunc
= new HashMap
<String
,Func
>();
43 private Map
<String
,Macro
> hashmacro
= new HashMap
<String
,Macro
>();
45 //-------------------------------------import------------------------------------------//
47 private void importDBLib(String filename
) throws Exception
{
48 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
54 System
.out
.println("Found " + filename
+ ", Importing Library Database.");
55 while ((line
= rd
.readLine()) != null) {
56 if (line
.length() != 0) {
57 linecontext
= line
.split(",");
58 lf
= new Func(linecontext
);
59 hashfunc
.put(lf
.r8funcname
,lf
);
65 private void importDBGuid(String filename
, String type
) throws Exception
{
66 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
72 System
.out
.println("Found " + filename
+ ", Importing " + type
+ " Database.");
73 while ((line
= rd
.readLine()) != null) {
74 if (line
.length() != 0) {
75 linecontext
= line
.split(",");
76 gu
= new Guid(linecontext
, type
);
77 hashguid
.put(gu
.r8name
,gu
);
83 private void importDBMacro(String filename
) throws Exception
{
84 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
90 System
.out
.println("Found " + filename
+ ", Importing Macro Database.");
91 while ((line
= rd
.readLine()) != null) {
92 if (line
.length() != 0) {
93 linecontext
= line
.split(",");
94 mc
= new Macro(linecontext
);
95 hashmacro
.put(mc
.r8name
,mc
);
101 private void importListR8Only() throws Exception
{
102 Pattern ptnr8only
= Pattern
.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern
.DOTALL
);
103 String wholeline
= Common
.file2string(DatabasePath
+ File
.separator
+ "R8Lib.c");
104 System
.out
.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
105 Matcher mtrr8only
= ptnr8only
.matcher(wholeline
);
106 while (mtrr8only
.find()) {
107 r8only
.add(mtrr8only
.group(2));
111 //-------------------------------------import------------------------------------------//
113 //-------------------------------------get------------------------------------------//
115 public String
getR9Lib(String r8funcname
) {
117 if (hashfunc
.containsKey(r8funcname
)) {
118 temp
= hashfunc
.get(r8funcname
).r9libname
;
123 public String
getR9Func(String r8funcname
) {
125 if (hashfunc
.containsKey(r8funcname
)) {
126 temp
= hashfunc
.get(r8funcname
).r9funcname
;
131 public String
getR9Macro(String r8macro
) {
132 return hashmacro
.get(r8macro
).r9name
; // the verification job of if the macro exists in the database is done when registering it
135 public String
getR9Guidname(String r8Guid
) {
138 temp
= hashguid
.get(r8Guid
).r9name
;
139 } catch (NullPointerException e
) {
140 error
.add("getR9Guidname :" + r8Guid
);
145 public String
getGuidType(String r8Guid
) {
148 temp
= hashguid
.get(r8Guid
).type
;
149 } catch (NullPointerException e
) {
150 error
.add("getR9Guidname :" + r8Guid
);
155 //-------------------------------------get------------------------------------------//
157 //-------------------------------------has------------------------------------------//
159 public boolean hasFunc(String r8lib
) {
160 return hashfunc
.containsKey(r8lib
);
163 public boolean hasGuid(String r8guid
) {
164 return hashguid
.containsKey(r8guid
);
167 public boolean hasMacro(String r8macro
) {
168 return hashmacro
.containsKey(r8macro
);
171 //-------------------------------------has------------------------------------------//
173 //-------------------------------------init------------------------------------------//
175 private static final Database
init() {
176 if (System
.getenv("WORKSPACE") == null) {
177 return new Database("C:" + File
.separator
+ "tianocore" + File
.separator
+ "edk2" + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
179 return new Database(System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
183 public static final Database
getInstance() {