ebccca46732fd4db92e55ecd8bed89c260f3f8a1
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GuidChkTask.java
1 /** @file
2 GuidChkTask class.
3
4 GuidChkTask is to call GuidChk.exe to generate Section.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.framework.tasks;
17 import java.io.BufferedReader;
18 import java.io.InputStreamReader;
19 import java.io.PrintWriter;
20 import java.io.File;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.Task;
25
26 /**
27 GuidChkTask
28
29 GuidChkTask is to call GuidChk.exe to generate Section.
30
31 **/
32 public class GuidChkTask extends Task implements EfiDefine{
33 /**
34 * GuidChk task class
35 * class member
36 * -exDir : directory name of exclusion searching
37 * -exFile : file name of exclusion searching
38 * -exExt : extension name of exclusion searching
39 * -exSubDir: extesnion name of sub dir which excluded searching
40 * -outFile : out put file wrote internal GUID+basename list
41 * -chkGui : check for duplicate guids
42 * -chkSign : check for duplicate signatures
43 * -printGuiDef : if set will print guid+defined symbol name
44 * -printAllGuid: if set will print all GUIDS found
45 * -outPut : redirection file name
46 * -fos : out put redirect to this file
47 *
48 */
49 ///
50 /// Directory name of exclusion searching
51 ///
52 private String exDir = "";
53 ///
54 /// File name of exclusion searching.
55 ///
56 private String exFile = "";
57 ///
58 /// Extension name of exclusion searching.
59 ///
60 private String exExt = "";
61 ///
62 /// Extesnion name of sub dir which excluded searching.
63 ///
64 private String exSubDir = "";
65 ///
66 /// Out put file wrote internal GUID+basename list
67 ///
68 private String outFile = "";
69 ///
70 /// Check for duplicate guids.
71 ///
72 private String chkGui = "";
73 ///
74 /// Check for duplicate signatures
75 ///
76 private String chkSign = "";
77 ///
78 /// If set will print guid+defined symbol name
79 ///
80 private String printGuiDef = "";
81 ///
82 /// If set will print all GUIDS found
83 ///
84 private String printAllGuid = "";
85 ///
86 /// redirection file name.
87 ///
88 private String outPut = "";
89 ///
90 /// out put redirect to this file.
91 ///
92 protected PrintWriter fos = null;
93
94 //
95 // overload class execute method
96 //
97 public void execute() throws BuildException {
98 Project project = this.getOwningTarget().getProject();
99 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
100 String command;
101 if (path == null) {
102 command = "GuidChk";
103 } else {
104 command = path + File.separatorChar + "GuidChk";
105 }
106 String argument = exDir +
107 exFile +
108 exExt +
109 exSubDir +
110 outFile +
111 chkGui +
112 chkSign +
113 printGuiDef +
114 printAllGuid;
115 try {
116 System.out.println(command + " " + argument);
117 //
118 // execute command line
119 //
120 Process proc = Runtime.getRuntime().exec(command + "" + argument);
121 //
122 // if set output, redirect out put to output file, else print output to screen
123 //
124 if ( !this.outPut.equals("")) {
125 fos = new PrintWriter(this.outPut);
126 BufferedReader bin = new BufferedReader(new InputStreamReader(proc.getInputStream()));
127 String line = bin.readLine();
128 while (line != null ){
129 fos.println(line);
130 line = bin.readLine();
131 }
132 fos.close();
133 }
134 else {
135 BufferedReader bin = new BufferedReader(new InputStreamReader(proc.getInputStream()));
136 String line = bin.readLine();
137 System.out.println(line);
138 while (line != null ){
139 System.out.print(line);
140 line = bin.readLine();
141 }
142 }
143 System.out.println("GuidChkTask Success!");
144 } catch (Exception e) {
145 System.out.println("GuidChkTask failed!");
146 System.out.println(e.getMessage());
147
148 }
149 }
150 /**
151 getChkGui
152
153 This function is to get the string of flag of ChkGui
154
155 @return string of flag of ChkGui
156 **/
157 public String getChkGui() {
158 return chkGui;
159 }
160
161 /**
162 setChkGui
163
164 This function is to set chkGui
165
166 @param chkGui set class member of chkGui
167 **/
168 public void setChkGui(String chkGui) {
169 if (chkGui.equals("on")||(chkGui.equals("ON"))){
170 this.chkGui = " -g ";
171 }
172
173 }
174
175 /**
176 getChkSign
177
178 This function is to get chkSign
179
180 @return chkSign
181 **/
182 public String getChkSign() {
183 return chkSign;
184 }
185
186 /**
187 setChkSign
188
189 This function is to set class member of chkSign
190 * @param chkSign
191 */
192 public void setChkSign(String chkSign) {
193 if (chkSign.equals("on")|| chkSign.equals("ON")){
194 this.chkSign = " -s ";
195 }
196 }
197 /**
198 getExDir
199
200 This function is to get class member of exDir
201
202 @return exDir
203 **/
204 public String getExDir() {
205 return exDir;
206 }
207
208 /**
209 setExDir
210
211 This function is to set class member of exDir
212
213 @param exDir
214 **/
215 public void setExDir(String exDir) {
216 this.exDir = " -d " + exDir;
217 }
218
219 /**
220 getExExt
221
222 This function is to get class member of exExt
223
224 @return exExt
225 **/
226 public String getExExt() {
227 return exExt;
228 }
229
230 /**
231 setExExt
232
233 This function is to set class member of exExt
234 @param exExt
235 **/
236 public void setExExt(String exExt) {
237 this.exExt = " -e " + exExt;
238 }
239
240 /**
241 getExFile
242
243 This function is to get class member of exFile
244 @return exFile
245 **/
246 public String getExFile() {
247 return exFile;
248 }
249
250 /**
251 setExFile
252
253 This function is to set class member of exFile.
254
255 @param exFile
256 **/
257 public void setExFile(String exFile) {
258 this.exFile = " -f " + exFile;
259 }
260
261 /**
262 getExSubDir
263
264 This function is to get class member of exSubDir
265
266 @return exSubDir
267 **/
268 public String getExSubDir() {
269 return exSubDir;
270 }
271
272 /**
273 setExSubDir
274
275 This function is to set class member of exSubDir.
276 @param exSubDir
277 **/
278 public void setExSubDir(String exSubDir) {
279 this.exSubDir = " -u " + exSubDir;
280 }
281
282 /**
283 getOutFile
284
285 This function is to get outFile
286
287 @return outFile
288 **/
289 public String getOutFile() {
290 return outFile;
291 }
292 /**
293 * set class member of outFile
294 * @param outFile
295 */
296 public void setOutFile(String outFile) {
297 this.outFile = " -b " + outFile;
298 }
299 /**
300 getPrintGuidDef
301
302 This function is to get printGuidDef
303
304 @return flage of printing (guid+defined symbol name)
305 **/
306 public String getPrintGuiDef() {
307 return printGuiDef;
308 }
309
310
311 /**
312 setPrintGuidDef
313
314 This function is to set class member of printGuiDef.
315 @param printGuiDef
316 **/
317 public void setPrintGuiDef(String printGuiDef) {
318 if (printGuiDef.equals("on")|| printGuiDef.equals("ON")){
319 this.printGuiDef = " -x ";
320 }
321
322 }
323
324 /**
325 getOutput
326
327 This function is to get output
328
329 @return name of outPut file
330 **/
331 public String getOutPut() {
332 return outPut;
333 }
334
335 /**
336 setOutPut
337
338 This function is to set class member of outPut.
339 @param outPut
340 **/
341 public void setOutPut(String outPut) {
342 this.outPut = outPut;
343 }
344
345 /**
346 getPrintAllGuid
347
348 This function is to get printAllGuid
349 @return printAllGuid
350 **/
351 public String getPrintAllGuid() {
352 return printAllGuid;
353 }
354
355 /**
356 setPrintAllGuid
357
358 This function is to set class member of printAllGuid.
359 @param printAllGuid
360 **/
361 public void setPrintAllGuid(String printAllGuid) {
362 if (printAllGuid.equals("on")||printAllGuid.equals("ON")) {
363 this.printAllGuid = " -p ";
364 }
365 }
366 }
367