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