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