]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/Database.java
f14184ab61c4b498daad620f85ba60ac4822b395
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
));
55 System
.out
.println("Found " + filename
+ ", Importing Package Guid Database.");
57 // Skip the title row.
60 while ((line
= rd
.readLine()) != null) {
61 if (line
.length() != 0) {
62 linecontext
= line
.split(",");
63 hashPkgGuid
.put(linecontext
[0], linecontext
[1]);
68 public Iterator
<String
> dumpAllPkgGuid() {
69 return hashPkgGuid
.values().iterator();
71 private void importDBLib(String filename
) throws Exception
{
72 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
78 System
.out
.println("Found " + filename
+ ", Importing Library Database.");
79 while ((line
= rd
.readLine()) != null) {
80 if (line
.length() != 0) {
81 linecontext
= line
.split(",");
82 lf
= new Func(linecontext
);
83 hashfunc
.put(lf
.r8funcname
,lf
);
89 private void importDBGuid(String filename
, String type
) throws Exception
{
90 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
96 System
.out
.println("Found " + filename
+ ", Importing " + type
+ " Database.");
97 while ((line
= rd
.readLine()) != null) {
98 if (line
.length() != 0) {
99 linecontext
= line
.split(",");
100 gu
= new Guid(linecontext
, type
);
101 hashguid
.put(gu
.r8name
,gu
);
107 private void importDBMacro(String filename
) throws Exception
{
108 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
110 String
[] linecontext
;
114 System
.out
.println("Found " + filename
+ ", Importing Macro Database.");
115 while ((line
= rd
.readLine()) != null) {
116 if (line
.length() != 0) {
117 linecontext
= line
.split(",");
118 mc
= new Macro(linecontext
);
119 hashmacro
.put(mc
.r8name
,mc
);
125 private void importListR8Only() throws Exception
{
126 Pattern ptnr8only
= Pattern
.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern
.DOTALL
);
127 String wholeline
= Common
.file2string(DatabasePath
+ File
.separator
+ "R8Lib.c");
128 System
.out
.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
129 Matcher mtrr8only
= ptnr8only
.matcher(wholeline
);
130 while (mtrr8only
.find()) {
131 r8only
.add(mtrr8only
.group(2));
135 //-------------------------------------import------------------------------------------//
137 //-------------------------------------get------------------------------------------//
139 public String
getR9Lib(String r8funcname
) {
141 if (hashfunc
.containsKey(r8funcname
)) {
142 temp
= hashfunc
.get(r8funcname
).r9libname
;
147 public String
getR9Func(String r8funcname
) {
149 if (hashfunc
.containsKey(r8funcname
)) {
150 temp
= hashfunc
.get(r8funcname
).r9funcname
;
155 public String
getR9Macro(String r8macro
) {
156 return hashmacro
.get(r8macro
).r9name
; // the verification job of if the macro exists in the database is done when registering it
159 public String
getR9Guidname(String r8Guid
) {
162 temp
= hashguid
.get(r8Guid
).r9name
;
163 } catch (NullPointerException e
) {
164 error
.add("getR9Guidname :" + r8Guid
);
169 public String
getGuidType(String r8Guid
) {
172 temp
= hashguid
.get(r8Guid
).type
;
173 } catch (NullPointerException e
) {
174 error
.add("getR9Guidname :" + r8Guid
);
179 //-------------------------------------get------------------------------------------//
181 //-------------------------------------has------------------------------------------//
183 public boolean hasFunc(String r8lib
) {
184 return hashfunc
.containsKey(r8lib
);
187 public boolean hasGuid(String r8guid
) {
188 return hashguid
.containsKey(r8guid
);
191 public boolean hasMacro(String r8macro
) {
192 return hashmacro
.containsKey(r8macro
);
195 //-------------------------------------has------------------------------------------//
197 //-------------------------------------init------------------------------------------//
199 private static final Database
init() {
200 if (System
.getenv("WORKSPACE") == null) {
201 return new Database("C:" + File
.separator
+ "tianocore" + File
.separator
+ "edk2" + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
203 return new Database(System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
207 public static final Database
getInstance() {