]>
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 | |
111 | String path = project.getProperty("env.Framework_Tools_Path"); \r | |
112 | String command;\r | |
113 | if (path == null) {\r | |
dc13f95d | 114 | command = "StrGather";\r |
878ddf1f | 115 | } else {\r |
dc13f95d | 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 | |
151 | System.out.println(Commandline.toString(cmdline.getCommandline()));\r | |
152 | \r | |
153 | revl = runner.execute();\r | |
154 | if (EFI_SUCCESS == revl) {\r | |
155 | ///\r | |
156 | /// command execution success\r | |
157 | ///\r | |
158 | System.out.println("strgather succeeded!");\r | |
159 | } else {\r | |
160 | ///\r | |
161 | /// command execution fail\r | |
162 | ///\r | |
163 | System.out.println("strgather failed. (error="\r | |
164 | + Integer.toHexString(revl) + ")");\r | |
165 | throw new BuildException("strgather failed. (error="\r | |
166 | + Integer.toHexString(revl) + ")");\r | |
167 | }\r | |
168 | } catch (Exception e) {\r | |
169 | throw new BuildException(e.getMessage());\r | |
170 | }\r | |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | get class member "commandType"\r | |
175 | \r | |
176 | @returns commandType parameter\r | |
177 | **/\r | |
178 | public String getCommandType() {\r | |
179 | return this.commandType;\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | set class member ""\r | |
184 | \r | |
185 | @param commandType type of strgather command [parse/scan/dump]\r | |
186 | **/\r | |
187 | public void setCommandType(String commandType) {\r | |
188 | this.commandType = " -" + commandType;\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
192 | get class member "verbose"\r | |
193 | \r | |
194 | @returns verbose parameter\r | |
195 | **/\r | |
196 | public String getVerbose() {\r | |
197 | return this.verbose;\r | |
198 | }\r | |
199 | \r | |
200 | /**\r | |
201 | set class member "verbose"\r | |
202 | \r | |
203 | @param verbose verbose level [all/read/write]\r | |
204 | **/\r | |
205 | public void setVerbose(String verbose) {\r | |
206 | if (verbose.equals("all")) {\r | |
207 | ///\r | |
208 | /// for verbose output\r | |
209 | ///\r | |
210 | this.verbose = " -v ";\r | |
211 | } else if (verbose.equals("read")) {\r | |
212 | ///\r | |
213 | /// for verbose output when reading database\r | |
214 | ///\r | |
215 | this.verbose = " -vdbr ";\r | |
216 | } else if (verbose.equals("write")) {\r | |
217 | ///\r | |
218 | /// for verbose output when writing database\r | |
219 | ///\r | |
220 | this.verbose = " -vdbw ";\r | |
221 | }\r | |
222 | }\r | |
223 | \r | |
224 | /**\r | |
225 | get class member baseName\r | |
226 | \r | |
227 | @returns baseName parameter\r | |
228 | **/\r | |
229 | public String getBaseName() {\r | |
230 | return this.baseName;\r | |
231 | }\r | |
232 | \r | |
233 | /**\r | |
234 | set class member baseName\r | |
235 | \r | |
236 | @param baseName name of the output files of .c and .h\r | |
237 | **/\r | |
238 | public void setBaseName(String baseName) {\r | |
239 | this.baseName = " -bn " + baseName;\r | |
240 | }\r | |
241 | \r | |
242 | /**\r | |
243 | get class member "outputDatabase"\r | |
244 | \r | |
245 | @returns outputDatabase parameter\r | |
246 | **/\r | |
247 | public String getOutputDatabase() {\r | |
248 | return this.outputDatabase;\r | |
249 | }\r | |
250 | \r | |
251 | /**\r | |
252 | set class member "outputDatabase"\r | |
253 | \r | |
254 | @param outputDatabase filename of output database file\r | |
255 | **/\r | |
256 | public void setOutputDatabase(String outputDatabase) {\r | |
257 | this.outputDatabase = " -od " + outputDatabase;\r | |
258 | }\r | |
259 | \r | |
260 | /**\r | |
261 | get class member "newDatabase"\r | |
262 | \r | |
263 | @returns newDatabase parameter\r | |
264 | **/\r | |
265 | public String getNewDatabse() {\r | |
266 | return this.newDatabase;\r | |
267 | }\r | |
268 | \r | |
269 | /**\r | |
270 | set class member "newDatabase"\r | |
271 | \r | |
272 | @param newDatabase whether to not read in existing database file\r | |
273 | **/\r | |
274 | public void setNewDatabase(String newDatabase) {\r | |
275 | if (newDatabase.equals("true")) {\r | |
276 | this.newDatabase = " -newdb ";\r | |
277 | }\r | |
278 | }\r | |
279 | \r | |
280 | /**\r | |
281 | get class member "unquotedString"\r | |
282 | \r | |
283 | @returns unquotedString parameter\r | |
284 | **/\r | |
285 | public String getUnquotedString() {\r | |
286 | return this.unquotedString;\r | |
287 | }\r | |
288 | \r | |
289 | /**\r | |
290 | set class member "unquotedString"\r | |
291 | \r | |
292 | @param unquotedString :\r | |
293 | whether to indicate that unquoted strings are used\r | |
294 | **/\r | |
295 | public void setUnquotedString(String unquotedString) {\r | |
296 | if (unquotedString.equals("true")) {\r | |
297 | this.unquotedString = " -uqs ";\r | |
298 | }\r | |
299 | }\r | |
300 | \r | |
301 | /**\r | |
302 | get class member "ignoreNotFound"\r | |
303 | \r | |
304 | @returns ignoreNotFound parameter\r | |
305 | **/\r | |
306 | public String getIgnoreNotFound() {\r | |
307 | return this.ignoreNotFound;\r | |
308 | }\r | |
309 | \r | |
310 | /**\r | |
311 | set class member "ignoreNotFound"\r | |
312 | \r | |
313 | @param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR) \r | |
314 | is not found in the database\r | |
315 | **/\r | |
316 | public void setIgnoreNotFound(String ignoreNotFound) {\r | |
317 | if (ignoreNotFound.equals("true")) {\r | |
318 | this.ignoreNotFound = " -ignorenotfound ";\r | |
319 | }\r | |
320 | }\r | |
321 | \r | |
322 | /**\r | |
323 | get class member "outputString"\r | |
324 | \r | |
325 | @returns outputString parameter\r | |
326 | **/\r | |
327 | public String getOutputString() {\r | |
328 | return this.outputString;\r | |
329 | }\r | |
330 | \r | |
331 | /**\r | |
332 | set class member "outputString"\r | |
333 | \r | |
334 | @param outputString filename of string data file\r | |
335 | **/\r | |
336 | public void setOutputString(String outputString) {\r | |
337 | this.outputString = " -oc " + outputString;\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | get class member "outputDefines"\r | |
342 | \r | |
343 | @returns outputDefines parameter\r | |
344 | **/\r | |
345 | public String getOutputDefines() {\r | |
346 | return this.outputDefines;\r | |
347 | }\r | |
348 | \r | |
349 | /**\r | |
350 | set class member "outputDefines"\r | |
351 | \r | |
352 | @param outputDefines filename of string defines file\r | |
353 | **/\r | |
354 | public void setOutputDefines(String outputDefines) {\r | |
355 | this.outputDefines = " -oh " + outputDefines;\r | |
356 | }\r | |
357 | \r | |
358 | /**\r | |
359 | get class member "outputUnicode"\r | |
360 | \r | |
361 | @returns outputUnicode parameter\r | |
362 | **/\r | |
363 | public String getOutputUnicode() {\r | |
364 | return this.outputUnicode;\r | |
365 | }\r | |
366 | \r | |
367 | /**\r | |
368 | set class member "outputUnicode"\r | |
369 | \r | |
370 | @param outputUnicode filename of unicode file to be dumped database\r | |
371 | **/\r | |
372 | public void setOutputUnicode(String outputUnicode) {\r | |
373 | this.outputUnicode = " -ou " + outputUnicode;\r | |
374 | }\r | |
375 | \r | |
376 | /**\r | |
377 | get class member "lang"\r | |
378 | \r | |
379 | @returns lang parameter\r | |
380 | **/\r | |
381 | public String getLang() {\r | |
382 | return this.lang;\r | |
383 | }\r | |
384 | \r | |
385 | /**\r | |
386 | set class member "lang"\r | |
387 | \r | |
388 | @param lang language of dump\r | |
389 | **/\r | |
390 | public void setLang(String lang) {\r | |
391 | this.lang = " -lang " + lang;\r | |
392 | }\r | |
393 | \r | |
394 | /**\r | |
395 | get class member "indirectionFile"\r | |
396 | \r | |
397 | @returns indirectionFile parameter\r | |
398 | **/\r | |
399 | public String getIndirectionFile() {\r | |
400 | return this.indirectionFile;\r | |
401 | }\r | |
402 | \r | |
403 | /**\r | |
404 | set class member "indirectionFile"\r | |
405 | \r | |
406 | @param indirectionFile filename of indirection file\r | |
407 | **/\r | |
408 | public void setIndirectionFile(String indirectionFile) {\r | |
409 | this.indirectionFile = " -if " + indirectionFile;\r | |
410 | }\r | |
411 | \r | |
412 | /**\r | |
413 | get class member "outputHpk"\r | |
414 | \r | |
415 | @returns outputHpk parameter\r | |
416 | **/\r | |
417 | public String getOutputHpk() {\r | |
418 | return this.outputHpk;\r | |
419 | }\r | |
420 | \r | |
421 | /**\r | |
422 | set class member "outputHpk"\r | |
423 | \r | |
424 | @param outputHpk filename of output HII export pack of the strings\r | |
425 | **/\r | |
426 | public void setOutputHpk(String outputHpk) {\r | |
427 | this.outputHpk = " -hpk " + outputHpk;\r | |
428 | }\r | |
429 | \r | |
430 | /**\r | |
431 | add a skipExt element into list\r | |
432 | \r | |
433 | @param skipExt skipExt element\r | |
434 | **/\r | |
435 | public void addSkipext(SkipExt skipExt) {\r | |
436 | skipExtList.add(skipExt);\r | |
437 | };\r | |
438 | \r | |
439 | /**\r | |
440 | add a includePath element into list\r | |
441 | \r | |
442 | @param includePath includePath element\r | |
443 | **/\r | |
444 | public void addIncludepath(IncludePath includePath) {\r | |
445 | includePathList.add(includePath);\r | |
446 | };\r | |
447 | \r | |
448 | /**\r | |
449 | add a inputFile element into list\r | |
450 | \r | |
451 | @param inputFile inputFile element\r | |
452 | **/\r | |
453 | public void addInputfile(InputFile inputFile) {\r | |
454 | inputFileList.add(inputFile);\r | |
455 | };\r | |
456 | \r | |
457 | /**\r | |
458 | add a database element into list\r | |
459 | \r | |
460 | @param database :\r | |
461 | database element\r | |
462 | **/\r | |
463 | public void addDatabase(Database database) {\r | |
464 | databaseList.add(database);\r | |
465 | }\r | |
466 | \r | |
467 | /**\r | |
468 | transfer List to String\r | |
469 | \r | |
470 | @param list nested element list\r | |
471 | @param tag interval tag of parameter\r | |
472 | \r | |
473 | @returns string line of parameters\r | |
474 | **/\r | |
475 | private String list2Str(List list, String tag) {\r | |
476 | ///\r | |
477 | /// string line for return\r | |
478 | ///\r | |
479 | String paraStr = "";\r | |
480 | ///\r | |
481 | /// nested element in list\r | |
482 | ///\r | |
483 | NestElement element;\r | |
484 | ///\r | |
485 | /// iterator of nested element list\r | |
486 | ///\r | |
487 | Iterator elementIter = list.iterator();\r | |
488 | ///\r | |
489 | /// string parameter list\r | |
490 | ///\r | |
491 | List<Object> strList = new ArrayList<Object>();\r | |
492 | \r | |
493 | while (elementIter.hasNext()) {\r | |
494 | element = (NestElement) elementIter.next();\r | |
495 | if (null != element.getFile()) {\r | |
496 | ///\r | |
497 | /// nested element include file\r | |
498 | ///\r | |
499 | FileParser.loadFile(project, strList, element.getFile(), tag);\r | |
500 | } \r | |
501 | \r | |
502 | if (element.getName().length() > 0) {\r | |
503 | ///\r | |
504 | /// nested element include name \r | |
505 | ///\r | |
506 | paraStr = paraStr + " " + element.getName();\r | |
507 | }\r | |
508 | \r | |
509 | List<String> nameList = element.getList();\r | |
510 | if (nameList.size() > 0) {\r | |
511 | Iterator nameIter = nameList.iterator();\r | |
512 | while (nameIter.hasNext()) {\r | |
513 | paraStr = paraStr + " " + tag + " " + (String)nameIter.next();\r | |
514 | }\r | |
515 | }\r | |
516 | }\r | |
517 | ///\r | |
518 | /// iterator of string parameter list\r | |
519 | ///\r | |
520 | Iterator strIter = strList.iterator();\r | |
521 | while (strIter.hasNext()) {\r | |
522 | paraStr = paraStr + " " + strIter.next();\r | |
523 | }\r | |
524 | return paraStr;\r | |
525 | }\r | |
526 | \r | |
527 | }\r |