Add MigrationTools
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleReader.java
1 package org.tianocore.migration;
2
3 import java.io.*;
4 import java.util.*;
5 import java.util.regex.*;
6 import org.tianocore.*;
7
8 public class ModuleReader {
9 ModuleReader(String path, ModuleInfo moduleinfo, Database database) {
10 modulepath = path;
11 mi = moduleinfo;
12 db = database;
13 }
14 private String modulepath;
15 private ModuleInfo mi;
16 private Database db;
17
18 private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)");
19
20 public void readMsa(String name) throws Exception {
21 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));
22 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
23 MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
24
25 mi.modulename = msaheader.getModuleName();
26 mi.guidvalue = msaheader.getGuidValue();
27 mi.moduletype = msaheader.getModuleType().toString(); // ???
28
29 SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
30
31 String temp;
32 Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
33 while (li.hasNext()) {
34 if (!mi.localmodulesources.contains(temp = li.next().toString())) {
35 System.out.println("Source File Missing ! : " + temp);
36 }
37 }
38 }
39
40 public void readInf(String name) throws Exception {
41 System.out.println("Reading From Inf : " + name);
42 BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));
43 String line;
44 String[] linecontext;
45 boolean inSrc = false;
46 Matcher mtrinfequation;
47
48 while ((line = rd.readLine()) != null) {
49 if (line.length() != 0) {
50 if (inSrc) {
51 if (line.contains("[")) {
52 inSrc = false;
53 } else {
54 linecontext = line.split(" ");
55 if (linecontext[2].length() != 0) {
56 if (!mi.localmodulesources.contains(linecontext[2])) {
57 System.out.println("Source File Missing ! : " + linecontext[2]);
58 }
59 }
60 }
61 } else {
62 if ((mtrinfequation = ptninfequation.matcher(line)).find()) {
63 if (mtrinfequation.group(1).matches("BASE_NAME")) {
64 mi.modulename = mtrinfequation.group(2);
65 }
66 if (mtrinfequation.group(1).matches("FILE_GUID")) {
67 mi.guidvalue = mtrinfequation.group(2);
68 }
69 if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
70 mi.moduletype = mtrinfequation.group(2);
71 }
72 if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
73 mi.entrypoint = mtrinfequation.group(2);
74 }
75 }
76 if (line.contains("sources")) {
77 inSrc = true;
78 }
79 }
80 }
81 }
82 }
83 }