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