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