]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java
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 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");
33 } catch (Exception e
) {
34 System
.out
.println(e
.getMessage());
38 public String DatabasePath
;
39 public Set
<String
> error
= new HashSet
<String
>();
40 public Set
<String
> r8only
= new HashSet
<String
>();
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
>();
47 //-------------------------------------import------------------------------------------//
48 private void importPkgGuid(String filename
) throws Exception
{
49 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
54 System
.out
.println("Found " + filename
+ ", Importing Package Guid Database.");
56 // Skip the title row.
59 while ((line
= rd
.readLine()) != null) {
60 if (line
.length() != 0) {
61 linecontext
= line
.split(",");
62 hashPkgGuid
.put(linecontext
[0], linecontext
[1]);
67 public Iterator
<String
> dumpAllPkgGuid() {
68 return hashPkgGuid
.values().iterator();
70 private void importDBLib(String filename
) throws Exception
{
71 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
88 private void importDBGuid(String filename
, String type
) throws Exception
{
89 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
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
);
106 private void importDBMacro(String filename
) throws Exception
{
107 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
109 String
[] linecontext
;
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
);
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));
134 //-------------------------------------import------------------------------------------//
136 //-------------------------------------get------------------------------------------//
138 public String
getR9Lib(String r8funcname
) {
140 if (hashfunc
.containsKey(r8funcname
)) {
141 temp
= hashfunc
.get(r8funcname
).r9libname
;
146 public String
getR9Func(String r8funcname
) {
148 if (hashfunc
.containsKey(r8funcname
)) {
149 temp
= hashfunc
.get(r8funcname
).r9funcname
;
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
158 public String
getR9Guidname(String r8Guid
) {
161 temp
= hashguid
.get(r8Guid
).r9name
;
162 } catch (NullPointerException e
) {
163 error
.add("getR9Guidname :" + r8Guid
);
168 public String
getGuidType(String r8Guid
) {
171 temp
= hashguid
.get(r8Guid
).type
;
172 } catch (NullPointerException e
) {
173 error
.add("getR9Guidname :" + r8Guid
);
178 //-------------------------------------get------------------------------------------//
180 //-------------------------------------has------------------------------------------//
182 public boolean hasFunc(String r8lib
) {
183 return hashfunc
.containsKey(r8lib
);
186 public boolean hasGuid(String r8guid
) {
187 return hashguid
.containsKey(r8guid
);
190 public boolean hasMacro(String r8macro
) {
191 return hashmacro
.containsKey(r8macro
);
194 //-------------------------------------has------------------------------------------//
196 //-------------------------------------init------------------------------------------//
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");
202 return new Database(System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
206 public static final Database
getInstance() {