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