2 This file is to define an ANT task which wraps StrGather.exe tool.
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
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.
14 package org
.tianocore
.framework
.tasks
;
17 import org
.apache
.tools
.ant
.BuildException
;
18 import org
.apache
.tools
.ant
.Project
;
19 import org
.apache
.tools
.ant
.Task
;
20 import org
.apache
.tools
.ant
.taskdefs
.Execute
;
21 import org
.apache
.tools
.ant
.taskdefs
.LogStreamHandler
;
22 import org
.apache
.tools
.ant
.types
.Commandline
;
23 import org
.tianocore
.common
.logger
.EdkLog
;
28 -commandType : command type [parse/scan/dump]
29 -baseName : base name of component
30 -verbose : level of verbose [all/read/write]
31 -outputDatabase : file name of output database file
32 -databaseList : file name list of database files
33 -inputFileList : file name list of input files
34 -newDatabase : whether to need new database [ture/false]
35 -unquotedString : whether to unquoted strings are used [ture/false]
36 -includePathList: path list of include paths
37 -ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]
38 -skipExtList : skip scan of files with extension name
39 -outputString : write string data to filename
40 -outputDefines : write string defines to filename
41 -outputUnicode : dump database to unicode file filename
42 -lang : only dump for the language
43 -indirectionFile: specify an indirection file
44 -outputHpk : create an HII export pack of the strings
46 public class StrGatherTask
extends Task
implements EfiDefine
{
50 private static String toolName
= "StrGather";
55 private ToolArg commandType
= new ToolArg();
57 private ToolArg baseName
= new ToolArg();
62 private ToolArg verbose
= new ToolArg();
64 private FileArg outputDatabase
= new FileArg();
66 private Database databaseList
= new Database();
68 private InputFile inputFileList
= new InputFile();
71 // parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
73 private ToolArg newDatabase
= new ToolArg();
75 private ToolArg unquotedString
= new ToolArg();
77 private IncludePath includePathList
= new IncludePath();
80 // scan options ignoreNotFound -- "ture/false"
82 private ToolArg ignoreNotFound
= new ToolArg();
84 private SkipExt skipExtList
= new SkipExt();
89 private ToolArg outputString
= new ToolArg();
91 private ToolArg outputDefines
= new ToolArg();
93 private ToolArg outputUnicode
= new ToolArg();
95 private ToolArg lang
= new ToolArg();
97 private FileArg indirectionFile
= new FileArg();
99 private FileArg outputHpk
= new FileArg();
104 static private Project project
;
107 assemble tool command line & execute tool command line
109 @throws BuildException
111 public void execute() throws BuildException
{
113 project
= this.getOwningTarget().getProject();
115 /// absolute path of efi tools
117 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
122 command
= path
+ File
.separator
+ toolName
;
126 /// assemble argument
128 String argument
= "" + commandType
+ verbose
+ databaseList
+ baseName
129 + outputDatabase
+ includePathList
+ newDatabase
+ unquotedString
130 + skipExtList
+ ignoreNotFound
+ outputString
+ outputDefines
131 + outputUnicode
+ lang
+ indirectionFile
+ outputHpk
134 /// return value of fwimage execution
139 Commandline cmdline
= new Commandline();
140 cmdline
.setExecutable(command
);
141 cmdline
.createArgument().setLine(argument
);
143 LogStreamHandler streamHandler
= new LogStreamHandler(this,
144 Project
.MSG_INFO
, Project
.MSG_WARN
);
145 Execute runner
= new Execute(streamHandler
, null);
147 runner
.setAntRun(project
);
148 runner
.setCommandline(cmdline
.getCommandline());
150 String cmdType
= getCommandType();
151 if (cmdType
.equalsIgnoreCase("parse")) {
152 EdkLog
.log(this, "(parse) " + inputFileList
.toFileList() + " => "
153 + databaseList
.toFileList());
154 } else if (cmdType
.equalsIgnoreCase("scan")) {
155 EdkLog
.log(this, "(scan) " + databaseList
.toFileList() + " => "
156 + outputDatabase
.toFileList());
158 EdkLog
.log(this, "(dump) " + databaseList
.toFileList() + " => "
159 + outputDefines
.toFileList() + outputString
.toFileList() + outputHpk
.toFileList());
161 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, Commandline
.toString(cmdline
.getCommandline()));
163 revl
= runner
.execute();
164 if (EFI_SUCCESS
== revl
) {
165 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, toolName
+ " succeeded!");
168 /// command execution fail
170 EdkLog
.log(this, "ERROR = " + Integer
.toHexString(revl
));
171 throw new BuildException(toolName
+ " failed!");
173 } catch (Exception e
) {
174 throw new BuildException(e
.getMessage());
179 get class member "commandType"
181 @returns commandType parameter
183 public String
getCommandType() {
184 return this.commandType
.getValue();
190 @param commandType type of strgather command [parse/scan/dump]
192 public void setCommandType(String commandType
) {
193 this.commandType
.setArg(" -", commandType
);
197 get class member "verbose"
199 @returns verbose parameter
201 public String
getVerbose() {
202 return this.verbose
.getValue();
206 set class member "verbose"
208 @param verbose verbose level [all/read/write]
210 public void setVerbose(String verbose
) {
211 if (verbose
.equals("all")) {
213 /// for verbose output
215 this.verbose
.setArg(" -", "v");
216 } else if (verbose
.equals("read")) {
218 /// for verbose output when reading database
220 this.verbose
.setArg(" -", "vdbr");
221 } else if (verbose
.equals("write")) {
223 /// for verbose output when writing database
225 this.verbose
.setArg(" -", "vdbw");
230 get class member baseName
232 @returns baseName parameter
234 public String
getBaseName() {
235 return this.baseName
.getValue();
239 set class member baseName
241 @param baseName name of the output files of .c and .h
243 public void setBaseName(String baseName
) {
244 this.baseName
.setArg(" -bn ", baseName
);
248 get class member "outputDatabase"
250 @returns outputDatabase parameter
252 public String
getOutputDatabase() {
253 return this.outputDatabase
.getValue();
257 set class member "outputDatabase"
259 @param outputDatabase filename of output database file
261 public void setOutputDatabase(String outputDatabase
) {
262 this.outputDatabase
.setArg(" -od ", outputDatabase
);
266 get class member "newDatabase"
268 @returns newDatabase parameter
270 public boolean getNewDatabse() {
271 return this.newDatabase
.getPrefix().length() > 0;
275 set class member "newDatabase"
277 @param newDatabase whether to not read in existing database file
279 public void setNewDatabase(boolean newDatabase
) {
281 this.newDatabase
.setArg(" -", "newdb");
286 get class member "unquotedString"
288 @returns unquotedString parameter
290 public boolean getUnquotedString() {
291 return this.unquotedString
.getValue().length() > 0;
295 set class member "unquotedString"
297 @param unquotedString :
298 whether to indicate that unquoted strings are used
300 public void setUnquotedString(boolean unquotedString
) {
301 if (unquotedString
) {
302 this.unquotedString
.setArg(" -", "uqs");
307 get class member "ignoreNotFound"
309 @returns ignoreNotFound parameter
311 public boolean getIgnoreNotFound() {
312 return this.ignoreNotFound
.getValue().length() > 0;
316 set class member "ignoreNotFound"
318 @param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
319 is not found in the database
321 public void setIgnoreNotFound(boolean ignoreNotFound
) {
322 if (ignoreNotFound
) {
323 this.ignoreNotFound
.setArg(" -", "ignorenotfound");
328 get class member "outputString"
330 @returns outputString parameter
332 public String
getOutputString() {
333 return this.outputString
.getValue();
337 set class member "outputString"
339 @param outputString filename of string data file
341 public void setOutputString(String outputString
) {
342 this.outputString
.setArg(" -oc ", outputString
);
346 get class member "outputDefines"
348 @returns outputDefines parameter
350 public String
getOutputDefines() {
351 return this.outputDefines
.getValue();
355 set class member "outputDefines"
357 @param outputDefines filename of string defines file
359 public void setOutputDefines(String outputDefines
) {
360 this.outputDefines
.setArg(" -oh ", outputDefines
);
364 get class member "outputUnicode"
366 @returns outputUnicode parameter
368 public String
getOutputUnicode() {
369 return this.outputUnicode
.getValue();
373 set class member "outputUnicode"
375 @param outputUnicode filename of unicode file to be dumped database
377 public void setOutputUnicode(String outputUnicode
) {
378 this.outputUnicode
.setArg(" -ou ", outputUnicode
);
382 get class member "lang"
384 @returns lang parameter
386 public String
getLang() {
387 return this.lang
.getValue();
391 set class member "lang"
393 @param lang language of dump
395 public void setLang(String lang
) {
396 this.lang
.setArg(" -lang ", lang
);
400 get class member "indirectionFile"
402 @returns indirectionFile parameter
404 public String
getIndirectionFile() {
405 return this.indirectionFile
.getValue();
409 set class member "indirectionFile"
411 @param indirectionFile filename of indirection file
413 public void setIndirectionFile(String indirectionFile
) {
414 this.indirectionFile
.setArg(" -if ", indirectionFile
);
418 get class member "outputHpk"
420 @returns outputHpk parameter
422 public String
getOutputHpk() {
423 return this.outputHpk
.getValue();
427 set class member "outputHpk"
429 @param outputHpk filename of output HII export pack of the strings
431 public void setOutputHpk(String outputHpk
) {
432 this.outputHpk
.setArg(" -hpk ", outputHpk
);
436 add a skipExt element into list
438 @param skipExt skipExt element
440 public void addConfiguredSkipext(SkipExt skipExt
) {
441 this.skipExtList
.insert(skipExt
);
445 add a includePath element into list
447 @param includePath includePath element
449 public void addConfiguredIncludepath(IncludePath includePath
) {
450 this.includePathList
.insert(includePath
);
454 add a inputFile element into list
456 @param inputFile inputFile element
458 public void addConfiguredInputfile(InputFile inputFile
) {
459 this.inputFileList
.insert(inputFile
);
463 add a database element into list
468 public void addConfiguredDatabase(Database database
) {
469 this.databaseList
.insert(database
);