]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | GenCRC32SectionTask class.\r | |
3 | \r | |
4 | GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import java.util.*;\r | |
20 | import org.apache.tools.ant.Project;\r | |
21 | import org.apache.tools.ant.Task;\r | |
22 | import org.apache.tools.ant.BuildException;\r | |
23 | import org.apache.tools.ant.taskdefs.Execute;\r | |
24 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
25 | import org.apache.tools.ant.types.Commandline;\r | |
26 | \r | |
27 | /**\r | |
28 | GenCRC32SectionTask\r | |
29 | \r | |
30 | GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section. \r | |
31 | \r | |
32 | **/\r | |
33 | public class GenCRC32SectionTask extends Task implements EfiDefine{\r | |
34 | ///\r | |
35 | /// output file\r | |
36 | ///\r | |
37 | private String outputFile;\r | |
38 | ///\r | |
39 | /// inputFile list\r | |
40 | ///\r | |
41 | private List<Object> inputFileList = new ArrayList<Object>();\r | |
42 | \r | |
43 | ///\r | |
44 | /// Project\r | |
45 | ///\r | |
46 | static private Project project;\r | |
47 | \r | |
48 | /**\r | |
49 | execute\r | |
50 | \r | |
51 | GenCRC32SectionTask execute is to assemble tool command line & execute\r | |
52 | tool command line\r | |
53 | \r | |
54 | @throws BuildException\r | |
55 | **/\r | |
56 | public void execute() throws BuildException {\r | |
57 | \r | |
58 | project = this.getOwningTarget().getProject(); \r | |
59 | ///\r | |
60 | /// absolute path of efi tools\r | |
61 | ///\r | |
2da8968b | 62 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r |
878ddf1f | 63 | String command;\r |
64 | if (path == null) {\r | |
fad77353 | 65 | command = "GenCRC32Section";\r |
878ddf1f | 66 | } else {\r |
fad77353 | 67 | command = path + "/" + "GenCRC32Section" ;\r |
878ddf1f | 68 | }\r |
69 | // \r | |
70 | // string line of input files \r | |
71 | // \r | |
72 | String inputFiles = list2Str(inputFileList, ""); \r | |
73 | // \r | |
74 | // assemble argument \r | |
75 | //\r | |
76 | String argument = inputFiles + outputFile; \r | |
77 | // \r | |
78 | // return value of fwimage execution \r | |
79 | //\r | |
80 | int revl = -1; \r | |
81 | \r | |
82 | try {\r | |
83 | Commandline cmdline = new Commandline();\r | |
84 | cmdline.setExecutable(command);\r | |
85 | cmdline.createArgument().setLine(argument);\r | |
86 | \r | |
87 | LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);\r | |
88 | Execute runner = new Execute(streamHandler, null);\r | |
89 | \r | |
90 | runner.setAntRun(project);\r | |
91 | runner.setCommandline(cmdline.getCommandline());\r | |
92 | System.out.println(Commandline.toString(cmdline.getCommandline()));\r | |
93 | \r | |
94 | revl = runner.execute();\r | |
95 | if (EFI_SUCCESS == revl){\r | |
96 | //\r | |
97 | // command execution success \r | |
98 | //\r | |
99 | System.out.println("gencrc32section succeeded!");\r | |
100 | }\r | |
101 | else\r | |
102 | {\r | |
103 | // \r | |
104 | // command execution fail\r | |
105 | //\r | |
106 | System.out.println("gencrc32section failed. (error=" + \r | |
107 | Integer.toHexString(revl) + \r | |
108 | ")"\r | |
109 | );\r | |
110 | }\r | |
111 | } catch (Exception e) {\r | |
112 | throw new BuildException(e.getMessage());\r | |
113 | }\r | |
114 | \r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | addInputFile\r | |
119 | \r | |
120 | This function is to add a inputFile element into list\r | |
121 | @param inputFile : inputFile element\r | |
122 | **/\r | |
123 | public void addInputfile(InputFile inputFile) {\r | |
124 | inputFileList.add(inputFile);\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | get class member "outputFile"\r | |
129 | * @return name of output file\r | |
130 | */\r | |
131 | public String getOutputFile() {\r | |
132 | return this.outputFile;\r | |
133 | }\r | |
134 | /**\r | |
135 | * set class member "outputFile"\r | |
136 | * @param outputFile : outputFile parameter \r | |
137 | */\r | |
138 | public void setOutputFile(String outputFile) {\r | |
139 | this.outputFile = " -o " + outputFile;\r | |
140 | };\r | |
141 | \r | |
142 | /**\r | |
143 | * transfer List to String\r | |
144 | * @param list : nested element list\r | |
145 | * @param tag : interval tag of parameter\r | |
146 | * @return string line of parameters \r | |
147 | */\r | |
148 | private String list2Str(List list, String tag) {\r | |
149 | /*\r | |
150 | * string line for return\r | |
151 | */\r | |
152 | String paraStr = " -i"; \r | |
153 | /*\r | |
154 | * nested element in list\r | |
155 | */\r | |
156 | NestElement element; \r | |
157 | /*\r | |
158 | * iterator of nested element list\r | |
159 | */\r | |
160 | Iterator elementIter = list.iterator(); \r | |
161 | /*\r | |
162 | * string parameter list\r | |
163 | */\r | |
164 | List<Object> strList = new ArrayList<Object>(); \r | |
165 | \r | |
166 | while (elementIter.hasNext()) {\r | |
167 | element = (NestElement) elementIter.next();\r | |
168 | if (null != element.getFile()) {\r | |
169 | FileParser.loadFile(project, strList, element.getFile(), tag);\r | |
170 | } else {\r | |
171 | paraStr = paraStr + element.getName();\r | |
172 | }\r | |
173 | }\r | |
174 | /*\r | |
175 | * iterator of string parameter list\r | |
176 | */\r | |
177 | Iterator strIter = strList.iterator(); \r | |
178 | while (strIter.hasNext()) {\r | |
179 | paraStr = paraStr + " " + strIter.next();\r | |
180 | }\r | |
181 | return paraStr;\r | |
182 | } \r | |
183 | }\r |