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
;
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
;
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
48 public class StrGatherTask
extends Task
implements EfiDefine
{
52 private ToolArg commandType
= new ToolArg();
54 private ToolArg baseName
= new ToolArg();
59 private ToolArg verbose
= new ToolArg();
61 private FileArg outputDatabase
= new FileArg();
63 private Database databaseList
= new Database();
65 private InputFile inputFileList
= new InputFile();
68 /// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
70 private ToolArg newDatabase
= new ToolArg();
72 private ToolArg unquotedString
= new ToolArg();
74 private IncludePath includePathList
= new IncludePath();
77 /// scan options ignoreNotFound -- "ture/false"
79 private ToolArg ignoreNotFound
= new ToolArg();
81 private SkipExt skipExtList
= new SkipExt();
86 private ToolArg outputString
= new ToolArg();
88 private ToolArg outputDefines
= new ToolArg();
90 private ToolArg outputUnicode
= new ToolArg();
92 private ToolArg lang
= new ToolArg();
94 private FileArg indirectionFile
= new FileArg();
96 private FileArg outputHpk
= new FileArg();
101 static private Project project
;
104 assemble tool command line & execute tool command line
106 @throws BuildException
108 public void execute() throws BuildException
{
110 project
= this.getOwningTarget().getProject();
112 /// absolute path of efi tools
114 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
117 command
= "StrGather";
119 command
= path
+ File
.separator
+ "StrGather";
123 /// assemble argument
125 String argument
= "" + commandType
+ verbose
+ databaseList
+ baseName
126 + outputDatabase
+ includePathList
+ newDatabase
+ unquotedString
127 + skipExtList
+ ignoreNotFound
+ outputString
+ outputDefines
128 + outputUnicode
+ lang
+ indirectionFile
+ outputHpk
131 /// return value of fwimage execution
136 Commandline cmdline
= new Commandline();
137 cmdline
.setExecutable(command
);
138 cmdline
.createArgument().setLine(argument
);
140 LogStreamHandler streamHandler
= new LogStreamHandler(this,
141 Project
.MSG_INFO
, Project
.MSG_WARN
);
142 Execute runner
= new Execute(streamHandler
, null);
144 runner
.setAntRun(project
);
145 runner
.setCommandline(cmdline
.getCommandline());
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());
155 EdkLog
.log(this, "(dump) " + databaseList
.toFileList() + " => "
156 + outputDefines
.toFileList() + outputString
.toFileList() + outputHpk
.toFileList());
158 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, Commandline
.toString(cmdline
.getCommandline()));
160 revl
= runner
.execute();
161 if (EFI_SUCCESS
== revl
) {
162 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "StrGather succeeded!");
165 /// command execution fail
167 EdkLog
.log(this, "ERROR = " + Integer
.toHexString(revl
));
168 throw new BuildException("StrGather failed!");
170 } catch (Exception e
) {
171 throw new BuildException(e
.getMessage());
176 get class member "commandType"
178 @returns commandType parameter
180 public String
getCommandType() {
181 return this.commandType
.getValue();
187 @param commandType type of strgather command [parse/scan/dump]
189 public void setCommandType(String commandType
) {
190 this.commandType
.setArg(" -", commandType
);
194 get class member "verbose"
196 @returns verbose parameter
198 public String
getVerbose() {
199 return this.verbose
.getValue();
203 set class member "verbose"
205 @param verbose verbose level [all/read/write]
207 public void setVerbose(String verbose
) {
208 if (verbose
.equals("all")) {
210 /// for verbose output
212 this.verbose
.setArg(" -", "v");
213 } else if (verbose
.equals("read")) {
215 /// for verbose output when reading database
217 this.verbose
.setArg(" -", "vdbr");
218 } else if (verbose
.equals("write")) {
220 /// for verbose output when writing database
222 this.verbose
.setArg(" -", "vdbw");
227 get class member baseName
229 @returns baseName parameter
231 public String
getBaseName() {
232 return this.baseName
.getValue();
236 set class member baseName
238 @param baseName name of the output files of .c and .h
240 public void setBaseName(String baseName
) {
241 this.baseName
.setArg(" -bn ", baseName
);
245 get class member "outputDatabase"
247 @returns outputDatabase parameter
249 public String
getOutputDatabase() {
250 return this.outputDatabase
.getValue();
254 set class member "outputDatabase"
256 @param outputDatabase filename of output database file
258 public void setOutputDatabase(String outputDatabase
) {
259 this.outputDatabase
.setArg(" -od ", outputDatabase
);
263 get class member "newDatabase"
265 @returns newDatabase parameter
267 public boolean getNewDatabse() {
268 return this.newDatabase
.getPrefix().length() > 0;
272 set class member "newDatabase"
274 @param newDatabase whether to not read in existing database file
276 public void setNewDatabase(boolean newDatabase
) {
278 this.newDatabase
.setArg(" -", "newdb");
283 get class member "unquotedString"
285 @returns unquotedString parameter
287 public boolean getUnquotedString() {
288 return this.unquotedString
.getValue().length() > 0;
292 set class member "unquotedString"
294 @param unquotedString :
295 whether to indicate that unquoted strings are used
297 public void setUnquotedString(boolean unquotedString
) {
298 if (unquotedString
) {
299 this.unquotedString
.setArg(" -", "uqs");
304 get class member "ignoreNotFound"
306 @returns ignoreNotFound parameter
308 public boolean getIgnoreNotFound() {
309 return this.ignoreNotFound
.getValue().length() > 0;
313 set class member "ignoreNotFound"
315 @param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
316 is not found in the database
318 public void setIgnoreNotFound(boolean ignoreNotFound
) {
319 if (ignoreNotFound
) {
320 this.ignoreNotFound
.setArg(" -", "ignorenotfound");
325 get class member "outputString"
327 @returns outputString parameter
329 public String
getOutputString() {
330 return this.outputString
.getValue();
334 set class member "outputString"
336 @param outputString filename of string data file
338 public void setOutputString(String outputString
) {
339 this.outputString
.setArg(" -oc ", outputString
);
343 get class member "outputDefines"
345 @returns outputDefines parameter
347 public String
getOutputDefines() {
348 return this.outputDefines
.getValue();
352 set class member "outputDefines"
354 @param outputDefines filename of string defines file
356 public void setOutputDefines(String outputDefines
) {
357 this.outputDefines
.setArg(" -oh ", outputDefines
);
361 get class member "outputUnicode"
363 @returns outputUnicode parameter
365 public String
getOutputUnicode() {
366 return this.outputUnicode
.getValue();
370 set class member "outputUnicode"
372 @param outputUnicode filename of unicode file to be dumped database
374 public void setOutputUnicode(String outputUnicode
) {
375 this.outputUnicode
.setArg(" -ou ", outputUnicode
);
379 get class member "lang"
381 @returns lang parameter
383 public String
getLang() {
384 return this.lang
.getValue();
388 set class member "lang"
390 @param lang language of dump
392 public void setLang(String lang
) {
393 this.lang
.setArg(" -lang ", lang
);
397 get class member "indirectionFile"
399 @returns indirectionFile parameter
401 public String
getIndirectionFile() {
402 return this.indirectionFile
.getValue();
406 set class member "indirectionFile"
408 @param indirectionFile filename of indirection file
410 public void setIndirectionFile(String indirectionFile
) {
411 this.indirectionFile
.setArg(" -if ", indirectionFile
);
415 get class member "outputHpk"
417 @returns outputHpk parameter
419 public String
getOutputHpk() {
420 return this.outputHpk
.getValue();
424 set class member "outputHpk"
426 @param outputHpk filename of output HII export pack of the strings
428 public void setOutputHpk(String outputHpk
) {
429 this.outputHpk
.setArg(" -hpk ", outputHpk
);
433 add a skipExt element into list
435 @param skipExt skipExt element
437 public void addConfiguredSkipext(SkipExt skipExt
) {
438 this.skipExtList
.insert(skipExt
);
442 add a includePath element into list
444 @param includePath includePath element
446 public void addConfiguredIncludepath(IncludePath includePath
) {
447 this.includePathList
.insert(includePath
);
451 add a inputFile element into list
453 @param inputFile inputFile element
455 public void addConfiguredInputfile(InputFile inputFile
) {
456 this.inputFileList
.insert(inputFile
);
460 add a database element into list
465 public void addConfiguredDatabase(Database database
) {
466 this.databaseList
.insert(database
);