]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
Add Critic.java
[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, UI u) {
22 modulepath = path;
23 mi = moduleinfo;
24 db = database;
25 ui = u;
26 }
27 private String modulepath;
28 private ModuleInfo mi;
29 private Database db;
30 private UI ui;
31
32 private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
33 private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
34 private static Pattern ptnfilename = Pattern.compile("[^\\s]+");
35
36 public void readMsa(String name) throws Exception {
37 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));
38 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
39 MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
40
41 mi.modulename = msaheader.getModuleName();
42 mi.guidvalue = msaheader.getGuidValue();
43 mi.moduletype = msaheader.getModuleType().toString(); // ???
44
45 SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
46
47 String temp;
48 Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
49 while (li.hasNext()) {
50 if (!mi.localmodulesources.contains(temp = li.next().toString())) {
51 System.out.println("Source File Missing! : " + temp);
52 }
53 }
54 }
55
56 public void readInf(String name) throws Exception {
57 System.out.println("\nParsing INF file: " + name);
58 String wholeline;
59 Matcher mtrinfequation;
60 Matcher mtrsection;
61 Matcher mtrfilename;
62
63 wholeline = Common.file2string(modulepath + File.separator + name);
64 mtrsection = ptnsection.matcher(wholeline);
65 while (mtrsection.find()) {
66 if (mtrsection.group(1).matches("defines")) {
67 mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
68 while (mtrinfequation.find()) {
69 if (mtrinfequation.group(1).matches("BASE_NAME")) {
70 mi.modulename = mtrinfequation.group(2);
71 }
72 if (mtrinfequation.group(1).matches("FILE_GUID")) {
73 mi.guidvalue = mtrinfequation.group(2);
74 }
75 if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
76 mi.moduletype = mtrinfequation.group(2);
77 }
78 }
79 }
80 if (mtrsection.group(1).matches("nmake.common")) {
81 mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
82 while (mtrinfequation.find()) {
83 if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
84 mi.entrypoint = mtrinfequation.group(2);
85 }
86 if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
87 if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
88 ui.println("DPX File Missing! : " + mtrinfequation.group(2));
89 }
90 }
91 }
92 }
93 if (mtrsection.group(1).contains("sources.")) {
94 mtrfilename = ptnfilename.matcher(mtrsection.group(2));
95 while (mtrfilename.find()) {
96 if (!mi.localmodulesources.contains(mtrfilename.group())) {
97 ui.println("Source File Missing! : " + mtrfilename.group());
98 }
99 }
100 }
101 }
102 }
103 }