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