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