]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
first step for MsaOwner in ModuleInfo
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
1 /** @file
2
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
8
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.
11
12 **/
13 package org.tianocore.migration;
14
15 import java.io.*;
16 import java.util.*;
17 import java.util.regex.*;
18
19 public final class Database {
20 private static final Database INSTANCE = Database.init();
21
22 Database(String path) {
23 DatabasePath = path;
24
25 try {
26 importDBLib("Library.csv");
27 importDBGuid("Guid.csv", "Guid");
28 importDBGuid("Ppi.csv", "Ppi");
29 importDBGuid("Protocol.csv", "Protocol");
30 importDBMacro("Macro.csv");
31 importListR8Only();
32 } catch (Exception e) {
33 System.out.println(e.getMessage());
34 }
35 }
36
37 public String DatabasePath;
38 public Set<String> error = new HashSet<String>();
39 public Set<String> r8only = new HashSet<String>();
40
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>();
44
45 //-------------------------------------import------------------------------------------//
46
47 private void importDBLib(String filename) throws Exception {
48 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
49 String line;
50 String[] linecontext;
51 Func lf;
52
53 if (rd.ready()) {
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);
60 }
61 }
62 }
63 }
64
65 private void importDBGuid(String filename, String type) throws Exception {
66 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
67 String line;
68 String[] linecontext;
69 Guid gu;
70
71 if (rd.ready()) {
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);
78 }
79 }
80 }
81 }
82
83 private void importDBMacro(String filename) throws Exception {
84 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
85 String line;
86 String[] linecontext;
87 Macro mc;
88
89 if (rd.ready()) {
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);
96 }
97 }
98 }
99 }
100
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));
108 }
109 }
110
111 //-------------------------------------import------------------------------------------//
112
113 //-------------------------------------get------------------------------------------//
114
115 public String getR9Lib(String r8funcname) {
116 String temp = null;
117 if (hashfunc.containsKey(r8funcname)) {
118 temp = hashfunc.get(r8funcname).r9libname;
119 }
120 return temp;
121 }
122
123 public String getR9Func(String r8funcname) {
124 String temp = null;
125 if (hashfunc.containsKey(r8funcname)) {
126 temp = hashfunc.get(r8funcname).r9funcname;
127 }
128 return temp;
129 }
130
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
133 }
134
135 public String getR9Guidname(String r8Guid) {
136 String temp = null;
137 try {
138 temp = hashguid.get(r8Guid).r9name;
139 } catch (NullPointerException e) {
140 error.add("getR9Guidname :" + r8Guid);
141 }
142 return temp;
143 }
144
145 public String getGuidType(String r8Guid) {
146 String temp = null;
147 try {
148 temp = hashguid.get(r8Guid).type;
149 } catch (NullPointerException e) {
150 error.add("getR9Guidname :" + r8Guid);
151 }
152 return temp;
153 }
154
155 //-------------------------------------get------------------------------------------//
156
157 //-------------------------------------has------------------------------------------//
158
159 public boolean hasFunc(String r8lib) {
160 return hashfunc.containsKey(r8lib);
161 }
162
163 public boolean hasGuid(String r8guid) {
164 return hashguid.containsKey(r8guid);
165 }
166
167 public boolean hasMacro(String r8macro) {
168 return hashmacro.containsKey(r8macro);
169 }
170
171 //-------------------------------------has------------------------------------------//
172
173 //-------------------------------------init------------------------------------------//
174
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");
178 } else {
179 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
180 }
181 }
182
183 public static final Database getInstance() {
184 return INSTANCE;
185 }
186 }