]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/StrGatherTask.java
1) Changed ToolArg class to abstract generic arguments of a tool
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / StrGatherTask.java
1 /** @file
2 This file is to define an ANT task which wraps StrGather.exe tool.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 package org.tianocore.framework.tasks;
15
16 import java.io.File;
17 import java.util.*;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.taskdefs.Execute;
23 import org.apache.tools.ant.taskdefs.LogStreamHandler;
24 import org.apache.tools.ant.types.Commandline;
25 import org.tianocore.common.logger.EdkLog;
26
27 /**
28 StrGather Task Class
29 class memberg
30 -commandType : command type [parse/scan/dump]
31 -baseName : base name of component
32 -verbose : level of verbose [all/read/write]
33 -outputDatabase : file name of output database file
34 -databaseList : file name list of database files
35 -inputFileList : file name list of input files
36 -newDatabase : whether to need new database [ture/false]
37 -unquotedString : whether to unquoted strings are used [ture/false]
38 -includePathList: path list of include paths
39 -ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]
40 -skipExtList : skip scan of files with extension name
41 -outputString : write string data to filename
42 -outputDefines : write string defines to filename
43 -outputUnicode : dump database to unicode file filename
44 -lang : only dump for the language
45 -indirectionFile: specify an indirection file
46 -outputHpk : create an HII export pack of the strings
47 **/
48 public class StrGatherTask extends Task implements EfiDefine {
49 ///
50 /// common options
51 ///
52 private ToolArg commandType = new ToolArg();
53
54 private ToolArg baseName = new ToolArg();
55
56 ///
57 /// "all/read/write"
58 ///
59 private ToolArg verbose = new ToolArg();
60
61 private FileArg outputDatabase = new FileArg();
62
63 private Database databaseList = new Database();
64
65 private InputFile inputFileList = new InputFile();
66
67 ///
68 /// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
69 ///
70 private ToolArg newDatabase = new ToolArg();
71
72 private ToolArg unquotedString = new ToolArg();
73
74 private IncludePath includePathList = new IncludePath();
75
76 ///
77 /// scan options ignoreNotFound -- "ture/false"
78 ///
79 private ToolArg ignoreNotFound = new ToolArg();
80
81 private SkipExt skipExtList = new SkipExt();
82
83 ///
84 /// dump options
85 ///
86 private ToolArg outputString = new ToolArg();
87
88 private ToolArg outputDefines = new ToolArg();
89
90 private ToolArg outputUnicode = new ToolArg();
91
92 private ToolArg lang = new ToolArg();
93
94 private FileArg indirectionFile = new FileArg();
95
96 private FileArg outputHpk = new FileArg();
97
98 ///
99 /// global variable
100 ///
101 static private Project project;
102
103 /**
104 assemble tool command line & execute tool command line
105
106 @throws BuildException
107 **/
108 public void execute() throws BuildException {
109
110 project = this.getOwningTarget().getProject();
111 ///
112 /// absolute path of efi tools
113 ///
114 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
115 String command;
116 if (path == null) {
117 command = "StrGather";
118 } else {
119 command = path + File.separator + "StrGather";
120 }
121
122 ///
123 /// assemble argument
124 ///
125 String argument = "" + commandType + verbose + databaseList + baseName
126 + outputDatabase + includePathList + newDatabase + unquotedString
127 + skipExtList + ignoreNotFound + outputString + outputDefines
128 + outputUnicode + lang + indirectionFile + outputHpk
129 + inputFileList;
130 ///
131 /// return value of fwimage execution
132 ///
133 int revl = -1;
134
135 try {
136 Commandline cmdline = new Commandline();
137 cmdline.setExecutable(command);
138 cmdline.createArgument().setLine(argument);
139
140 LogStreamHandler streamHandler = new LogStreamHandler(this,
141 Project.MSG_INFO, Project.MSG_WARN);
142 Execute runner = new Execute(streamHandler, null);
143
144 runner.setAntRun(project);
145 runner.setCommandline(cmdline.getCommandline());
146
147 String cmdType = getCommandType();
148 if (cmdType.equalsIgnoreCase("parse")) {
149 EdkLog.log(this, "(parse) " + inputFileList.toFileList() + " => "
150 + databaseList.toFileList());
151 } else if (cmdType.equalsIgnoreCase("scan")) {
152 EdkLog.log(this, "(scan) " + databaseList.toFileList() + " => "
153 + outputDatabase.toFileList());
154 } else {
155 EdkLog.log(this, "(dump) " + databaseList.toFileList() + " => "
156 + outputDefines.toFileList() + outputString.toFileList() + outputHpk.toFileList());
157 }
158 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
159
160 revl = runner.execute();
161 if (EFI_SUCCESS == revl) {
162 EdkLog.log(this, EdkLog.EDK_VERBOSE, "StrGather succeeded!");
163 } else {
164 ///
165 /// command execution fail
166 ///
167 EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));
168 throw new BuildException("StrGather failed!");
169 }
170 } catch (Exception e) {
171 throw new BuildException(e.getMessage());
172 }
173 }
174
175 /**
176 get class member "commandType"
177
178 @returns commandType parameter
179 **/
180 public String getCommandType() {
181 return this.commandType.getValue();
182 }
183
184 /**
185 set class member ""
186
187 @param commandType type of strgather command [parse/scan/dump]
188 **/
189 public void setCommandType(String commandType) {
190 this.commandType.setArg(" -", commandType);
191 }
192
193 /**
194 get class member "verbose"
195
196 @returns verbose parameter
197 **/
198 public String getVerbose() {
199 return this.verbose.getValue();
200 }
201
202 /**
203 set class member "verbose"
204
205 @param verbose verbose level [all/read/write]
206 **/
207 public void setVerbose(String verbose) {
208 if (verbose.equals("all")) {
209 ///
210 /// for verbose output
211 ///
212 this.verbose.setArg(" -", "v");
213 } else if (verbose.equals("read")) {
214 ///
215 /// for verbose output when reading database
216 ///
217 this.verbose.setArg(" -", "vdbr");
218 } else if (verbose.equals("write")) {
219 ///
220 /// for verbose output when writing database
221 ///
222 this.verbose.setArg(" -", "vdbw");
223 }
224 }
225
226 /**
227 get class member baseName
228
229 @returns baseName parameter
230 **/
231 public String getBaseName() {
232 return this.baseName.getValue();
233 }
234
235 /**
236 set class member baseName
237
238 @param baseName name of the output files of .c and .h
239 **/
240 public void setBaseName(String baseName) {
241 this.baseName.setArg(" -bn ", baseName);
242 }
243
244 /**
245 get class member "outputDatabase"
246
247 @returns outputDatabase parameter
248 **/
249 public String getOutputDatabase() {
250 return this.outputDatabase.getValue();
251 }
252
253 /**
254 set class member "outputDatabase"
255
256 @param outputDatabase filename of output database file
257 **/
258 public void setOutputDatabase(String outputDatabase) {
259 this.outputDatabase.setArg(" -od ", outputDatabase);
260 }
261
262 /**
263 get class member "newDatabase"
264
265 @returns newDatabase parameter
266 **/
267 public boolean getNewDatabse() {
268 return this.newDatabase.getPrefix().length() > 0;
269 }
270
271 /**
272 set class member "newDatabase"
273
274 @param newDatabase whether to not read in existing database file
275 **/
276 public void setNewDatabase(boolean newDatabase) {
277 if (newDatabase) {
278 this.newDatabase.setArg(" -", "newdb");
279 }
280 }
281
282 /**
283 get class member "unquotedString"
284
285 @returns unquotedString parameter
286 **/
287 public boolean getUnquotedString() {
288 return this.unquotedString.getValue().length() > 0;
289 }
290
291 /**
292 set class member "unquotedString"
293
294 @param unquotedString :
295 whether to indicate that unquoted strings are used
296 **/
297 public void setUnquotedString(boolean unquotedString) {
298 if (unquotedString) {
299 this.unquotedString.setArg(" -", "uqs");
300 }
301 }
302
303 /**
304 get class member "ignoreNotFound"
305
306 @returns ignoreNotFound parameter
307 **/
308 public boolean getIgnoreNotFound() {
309 return this.ignoreNotFound.getValue().length() > 0;
310 }
311
312 /**
313 set class member "ignoreNotFound"
314
315 @param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
316 is not found in the database
317 **/
318 public void setIgnoreNotFound(boolean ignoreNotFound) {
319 if (ignoreNotFound) {
320 this.ignoreNotFound.setArg(" -", "ignorenotfound");
321 }
322 }
323
324 /**
325 get class member "outputString"
326
327 @returns outputString parameter
328 **/
329 public String getOutputString() {
330 return this.outputString.getValue();
331 }
332
333 /**
334 set class member "outputString"
335
336 @param outputString filename of string data file
337 **/
338 public void setOutputString(String outputString) {
339 this.outputString.setArg(" -oc ", outputString);
340 }
341
342 /**
343 get class member "outputDefines"
344
345 @returns outputDefines parameter
346 **/
347 public String getOutputDefines() {
348 return this.outputDefines.getValue();
349 }
350
351 /**
352 set class member "outputDefines"
353
354 @param outputDefines filename of string defines file
355 **/
356 public void setOutputDefines(String outputDefines) {
357 this.outputDefines.setArg(" -oh ", outputDefines);
358 }
359
360 /**
361 get class member "outputUnicode"
362
363 @returns outputUnicode parameter
364 **/
365 public String getOutputUnicode() {
366 return this.outputUnicode.getValue();
367 }
368
369 /**
370 set class member "outputUnicode"
371
372 @param outputUnicode filename of unicode file to be dumped database
373 **/
374 public void setOutputUnicode(String outputUnicode) {
375 this.outputUnicode.setArg(" -ou ", outputUnicode);
376 }
377
378 /**
379 get class member "lang"
380
381 @returns lang parameter
382 **/
383 public String getLang() {
384 return this.lang.getValue();
385 }
386
387 /**
388 set class member "lang"
389
390 @param lang language of dump
391 **/
392 public void setLang(String lang) {
393 this.lang.setArg(" -lang ", lang);
394 }
395
396 /**
397 get class member "indirectionFile"
398
399 @returns indirectionFile parameter
400 **/
401 public String getIndirectionFile() {
402 return this.indirectionFile.getValue();
403 }
404
405 /**
406 set class member "indirectionFile"
407
408 @param indirectionFile filename of indirection file
409 **/
410 public void setIndirectionFile(String indirectionFile) {
411 this.indirectionFile.setArg(" -if ", indirectionFile);
412 }
413
414 /**
415 get class member "outputHpk"
416
417 @returns outputHpk parameter
418 **/
419 public String getOutputHpk() {
420 return this.outputHpk.getValue();
421 }
422
423 /**
424 set class member "outputHpk"
425
426 @param outputHpk filename of output HII export pack of the strings
427 **/
428 public void setOutputHpk(String outputHpk) {
429 this.outputHpk.setArg(" -hpk ", outputHpk);
430 }
431
432 /**
433 add a skipExt element into list
434
435 @param skipExt skipExt element
436 **/
437 public void addConfiguredSkipext(SkipExt skipExt) {
438 this.skipExtList.insert(skipExt);
439 };
440
441 /**
442 add a includePath element into list
443
444 @param includePath includePath element
445 **/
446 public void addConfiguredIncludepath(IncludePath includePath) {
447 this.includePathList.insert(includePath);
448 };
449
450 /**
451 add a inputFile element into list
452
453 @param inputFile inputFile element
454 **/
455 public void addConfiguredInputfile(InputFile inputFile) {
456 this.inputFileList.insert(inputFile);
457 };
458
459 /**
460 add a database element into list
461
462 @param database :
463 database element
464 **/
465 public void addConfiguredDatabase(Database database) {
466 this.databaseList.insert(database);
467 }
468 }