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