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
.Project
;
18 import org
.apache
.tools
.ant
.Task
;
19 import org
.apache
.tools
.ant
.BuildException
;
20 import org
.apache
.tools
.ant
.taskdefs
.Execute
;
21 import org
.apache
.tools
.ant
.taskdefs
.LogStreamHandler
;
22 import org
.apache
.tools
.ant
.types
.Commandline
;
27 -commandType : command type [parse/scan/dump]
28 -baseName : base name of component
29 -verbose : level of verbose [all/read/write]
30 -outputDatabase : file name of output database file
31 -databaseList : file name list of database files
32 -inputFileList : file name list of input files
33 -newDatabase : whether to need new database [ture/false]
34 -unquotedString : whether to unquoted strings are used [ture/false]
35 -includePathList: path list of include paths
36 -ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]
37 -skipExtList : skip scan of files with extension name
38 -outputString : write string data to filename
39 -outputDefines : write string defines to filename
40 -outputUnicode : dump database to unicode file filename
41 -lang : only dump for the language
42 -indirectionFile: specify an indirection file
43 -outputHpk : create an HII export pack of the strings
45 public class StrGatherTask
extends Task
implements EfiDefine
{
49 private String commandType
= "";
51 private String baseName
= "";
56 private String verbose
= "";
58 private String outputDatabase
= "";
60 private List
<Object
> databaseList
= new ArrayList
<Object
>();
62 private List
<Object
> inputFileList
= new ArrayList
<Object
>();
65 /// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
67 private String newDatabase
= "";
69 private String unquotedString
= "";
71 private List
<Object
> includePathList
= new ArrayList
<Object
>();
74 /// scan options ignoreNotFound -- "ture/false"
76 private String ignoreNotFound
= "";
78 private List
<Object
> skipExtList
= new ArrayList
<Object
>();
83 private String outputString
= "";
85 private String outputDefines
= "";
87 private String outputUnicode
= "";
89 private String lang
= "";
91 private String indirectionFile
= "";
93 private String outputHpk
= "";
98 static private Project project
;
101 assemble tool command line & execute tool command line
103 @throws BuildException
105 public void execute() throws BuildException
{
107 project
= this.getOwningTarget().getProject();
109 /// absolute path of efi tools
111 String path
= project
.getProperty("env.Framework_Tools_Path");
114 command
= "StrGather";
116 command
= path
+ "/" + "StrGather";
120 /// transfer nested elements into string
122 String databases
= list2Str(databaseList
, "-db");
123 String skipExts
= list2Str(skipExtList
, "-skipext");
124 String includePaths
= list2Str(includePathList
, "-I");
125 String inputFiles
= list2Str(inputFileList
, "");
128 /// assemble argument
130 String argument
= commandType
+ verbose
+ databases
+ baseName
131 + outputDatabase
+ includePaths
+ newDatabase
+ unquotedString
132 + skipExts
+ ignoreNotFound
+ outputString
+ outputDefines
133 + outputUnicode
+ lang
+ indirectionFile
+ outputHpk
136 /// return value of fwimage execution
141 Commandline cmdline
= new Commandline();
142 cmdline
.setExecutable(command
);
143 cmdline
.createArgument().setLine(argument
);
145 LogStreamHandler streamHandler
= new LogStreamHandler(this,
146 Project
.MSG_INFO
, Project
.MSG_WARN
);
147 Execute runner
= new Execute(streamHandler
, null);
149 runner
.setAntRun(project
);
150 runner
.setCommandline(cmdline
.getCommandline());
151 System
.out
.println(Commandline
.toString(cmdline
.getCommandline()));
153 revl
= runner
.execute();
154 if (EFI_SUCCESS
== revl
) {
156 /// command execution success
158 System
.out
.println("strgather succeeded!");
161 /// command execution fail
163 System
.out
.println("strgather failed. (error="
164 + Integer
.toHexString(revl
) + ")");
165 throw new BuildException("strgather failed. (error="
166 + Integer
.toHexString(revl
) + ")");
168 } catch (Exception e
) {
169 throw new BuildException(e
.getMessage());
174 get class member "commandType"
176 @returns commandType parameter
178 public String
getCommandType() {
179 return this.commandType
;
185 @param commandType type of strgather command [parse/scan/dump]
187 public void setCommandType(String commandType
) {
188 this.commandType
= " -" + commandType
;
192 get class member "verbose"
194 @returns verbose parameter
196 public String
getVerbose() {
201 set class member "verbose"
203 @param verbose verbose level [all/read/write]
205 public void setVerbose(String verbose
) {
206 if (verbose
.equals("all")) {
208 /// for verbose output
210 this.verbose
= " -v ";
211 } else if (verbose
.equals("read")) {
213 /// for verbose output when reading database
215 this.verbose
= " -vdbr ";
216 } else if (verbose
.equals("write")) {
218 /// for verbose output when writing database
220 this.verbose
= " -vdbw ";
225 get class member baseName
227 @returns baseName parameter
229 public String
getBaseName() {
230 return this.baseName
;
234 set class member baseName
236 @param baseName name of the output files of .c and .h
238 public void setBaseName(String baseName
) {
239 this.baseName
= " -bn " + baseName
;
243 get class member "outputDatabase"
245 @returns outputDatabase parameter
247 public String
getOutputDatabase() {
248 return this.outputDatabase
;
252 set class member "outputDatabase"
254 @param outputDatabase filename of output database file
256 public void setOutputDatabase(String outputDatabase
) {
257 this.outputDatabase
= " -od " + outputDatabase
;
261 get class member "newDatabase"
263 @returns newDatabase parameter
265 public String
getNewDatabse() {
266 return this.newDatabase
;
270 set class member "newDatabase"
272 @param newDatabase whether to not read in existing database file
274 public void setNewDatabase(String newDatabase
) {
275 if (newDatabase
.equals("true")) {
276 this.newDatabase
= " -newdb ";
281 get class member "unquotedString"
283 @returns unquotedString parameter
285 public String
getUnquotedString() {
286 return this.unquotedString
;
290 set class member "unquotedString"
292 @param unquotedString :
293 whether to indicate that unquoted strings are used
295 public void setUnquotedString(String unquotedString
) {
296 if (unquotedString
.equals("true")) {
297 this.unquotedString
= " -uqs ";
302 get class member "ignoreNotFound"
304 @returns ignoreNotFound parameter
306 public String
getIgnoreNotFound() {
307 return this.ignoreNotFound
;
311 set class member "ignoreNotFound"
313 @param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
314 is not found in the database
316 public void setIgnoreNotFound(String ignoreNotFound
) {
317 if (ignoreNotFound
.equals("true")) {
318 this.ignoreNotFound
= " -ignorenotfound ";
323 get class member "outputString"
325 @returns outputString parameter
327 public String
getOutputString() {
328 return this.outputString
;
332 set class member "outputString"
334 @param outputString filename of string data file
336 public void setOutputString(String outputString
) {
337 this.outputString
= " -oc " + outputString
;
341 get class member "outputDefines"
343 @returns outputDefines parameter
345 public String
getOutputDefines() {
346 return this.outputDefines
;
350 set class member "outputDefines"
352 @param outputDefines filename of string defines file
354 public void setOutputDefines(String outputDefines
) {
355 this.outputDefines
= " -oh " + outputDefines
;
359 get class member "outputUnicode"
361 @returns outputUnicode parameter
363 public String
getOutputUnicode() {
364 return this.outputUnicode
;
368 set class member "outputUnicode"
370 @param outputUnicode filename of unicode file to be dumped database
372 public void setOutputUnicode(String outputUnicode
) {
373 this.outputUnicode
= " -ou " + outputUnicode
;
377 get class member "lang"
379 @returns lang parameter
381 public String
getLang() {
386 set class member "lang"
388 @param lang language of dump
390 public void setLang(String lang
) {
391 this.lang
= " -lang " + lang
;
395 get class member "indirectionFile"
397 @returns indirectionFile parameter
399 public String
getIndirectionFile() {
400 return this.indirectionFile
;
404 set class member "indirectionFile"
406 @param indirectionFile filename of indirection file
408 public void setIndirectionFile(String indirectionFile
) {
409 this.indirectionFile
= " -if " + indirectionFile
;
413 get class member "outputHpk"
415 @returns outputHpk parameter
417 public String
getOutputHpk() {
418 return this.outputHpk
;
422 set class member "outputHpk"
424 @param outputHpk filename of output HII export pack of the strings
426 public void setOutputHpk(String outputHpk
) {
427 this.outputHpk
= " -hpk " + outputHpk
;
431 add a skipExt element into list
433 @param skipExt skipExt element
435 public void addSkipext(SkipExt skipExt
) {
436 skipExtList
.add(skipExt
);
440 add a includePath element into list
442 @param includePath includePath element
444 public void addIncludepath(IncludePath includePath
) {
445 includePathList
.add(includePath
);
449 add a inputFile element into list
451 @param inputFile inputFile element
453 public void addInputfile(InputFile inputFile
) {
454 inputFileList
.add(inputFile
);
458 add a database element into list
463 public void addDatabase(Database database
) {
464 databaseList
.add(database
);
468 transfer List to String
470 @param list nested element list
471 @param tag interval tag of parameter
473 @returns string line of parameters
475 private String
list2Str(List list
, String tag
) {
477 /// string line for return
481 /// nested element in list
485 /// iterator of nested element list
487 Iterator elementIter
= list
.iterator();
489 /// string parameter list
491 List
<Object
> strList
= new ArrayList
<Object
>();
493 while (elementIter
.hasNext()) {
494 element
= (NestElement
) elementIter
.next();
495 if (null != element
.getFile()) {
497 /// nested element include file
499 FileParser
.loadFile(project
, strList
, element
.getFile(), tag
);
502 if (element
.getName().length() > 0) {
504 /// nested element include name
506 paraStr
= paraStr
+ " " + element
.getName();
509 List
<String
> nameList
= element
.getList();
510 if (nameList
.size() > 0) {
511 Iterator nameIter
= nameList
.iterator();
512 while (nameIter
.hasNext()) {
513 paraStr
= paraStr
+ " " + tag
+ " " + (String
)nameIter
.next();
518 /// iterator of string parameter list
520 Iterator strIter
= strList
.iterator();
521 while (strIter
.hasNext()) {
522 paraStr
= paraStr
+ " " + strIter
.next();