Add License Head to all files
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleReader.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17import java.util.regex.*;\r
18import org.tianocore.*;\r
19\r
20public class ModuleReader {\r
21 ModuleReader(String path, ModuleInfo moduleinfo, Database database) {\r
22 modulepath = path;\r
23 mi = moduleinfo;\r
24 db = database;\r
25 }\r
26 private String modulepath;\r
27 private ModuleInfo mi;\r
28 private Database db;\r
29 \r
30 private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)");\r
31 \r
32 public void readMsa(String name) throws Exception {\r
33 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));\r
34 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
35 MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
36 \r
37 mi.modulename = msaheader.getModuleName();\r
38 mi.guidvalue = msaheader.getGuidValue();\r
39 mi.moduletype = msaheader.getModuleType().toString(); // ???\r
40 \r
41 SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
42 \r
43 String temp;\r
44 Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();\r
45 while (li.hasNext()) {\r
46 if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
47 System.out.println("Source File Missing ! : " + temp);\r
48 }\r
49 }\r
50 }\r
51 \r
52 public void readInf(String name) throws Exception {\r
53 System.out.println("Reading From Inf : " + name);\r
54 BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
55 String line;\r
56 String[] linecontext;\r
57 boolean inSrc = false;\r
58 Matcher mtrinfequation;\r
59\r
60 while ((line = rd.readLine()) != null) {\r
61 if (line.length() != 0) {\r
62 if (inSrc) {\r
63 if (line.contains("[")) {\r
64 inSrc = false;\r
65 } else {\r
66 linecontext = line.split(" ");\r
67 if (linecontext[2].length() != 0) {\r
68 if (!mi.localmodulesources.contains(linecontext[2])) {\r
69 System.out.println("Source File Missing ! : " + linecontext[2]);\r
70 }\r
71 }\r
72 }\r
73 } else {\r
74 if ((mtrinfequation = ptninfequation.matcher(line)).find()) {\r
75 if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
76 mi.modulename = mtrinfequation.group(2);\r
77 }\r
78 if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
79 mi.guidvalue = mtrinfequation.group(2);\r
80 }\r
81 if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
82 mi.moduletype = mtrinfequation.group(2);\r
83 }\r
84 if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
85 mi.entrypoint = mtrinfequation.group(2);\r
86 }\r
87 }\r
88 if (line.contains("sources")) {\r
89 inSrc = true;\r
90 }\r
91 }\r
92 }\r
93 }\r
94 }\r
95}