]>
Commit | Line | Data |
---|---|---|
a15bb0d3 | 1 | /** @file\r |
2 | GenCapsuleHdrTask class.\r | |
3 | \r | |
4 | GenCapsuleHdrTask is used to call GenCapsuleHdr.exe to generate capsule.\r | |
5 | \r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import java.io.File;\r | |
20 | \r | |
21 | import org.apache.tools.ant.Task;\r | |
22 | import org.apache.tools.ant.Project;\r | |
23 | import org.apache.tools.ant.BuildException;\r | |
24 | import org.apache.tools.ant.taskdefs.Execute;\r | |
25 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
26 | import org.apache.tools.ant.types.Commandline;\r | |
27 | import org.tianocore.logger.EdkLog;\r | |
28 | \r | |
29 | /**\r | |
30 | GenCapsuleHdrTask class.\r | |
31 | \r | |
32 | GenCapsuleHdrTask is used to call GenCapsuleHdr.exe to generate capsule.\r | |
33 | **/\r | |
34 | public class GenCapsuleHdrTask extends Task implements EfiDefine {\r | |
35 | ///\r | |
36 | /// tool name\r | |
37 | ///\r | |
38 | private String toolName = "GenCapsuleHdr";\r | |
39 | \r | |
40 | ///\r | |
41 | /// script file\r | |
42 | ///\r | |
43 | private String scriptFile = "";\r | |
44 | \r | |
45 | ///\r | |
46 | /// output file\r | |
47 | ///\r | |
48 | private String outputFile = "";\r | |
49 | \r | |
50 | ///\r | |
51 | /// output directory, this variable is added by jave wrap\r | |
52 | ///\r | |
53 | private String outputDir = "";\r | |
54 | \r | |
55 | ///\r | |
56 | /// Verbose flag\r | |
57 | ///\r | |
58 | private String verbose = "";\r | |
59 | \r | |
60 | ///\r | |
61 | /// Dump flag\r | |
62 | ///\r | |
63 | private String dump = "";\r | |
64 | \r | |
65 | ///\r | |
66 | /// Split size\r | |
67 | ///\r | |
68 | private String size = "";\r | |
69 | \r | |
70 | ///\r | |
71 | /// capsule into one image flag\r | |
72 | ///\r | |
73 | private String joinFlag = "";\r | |
74 | \r | |
75 | ///\r | |
76 | /// capsule file\r | |
77 | ///\r | |
78 | private String capsuleFile = "";\r | |
79 | \r | |
80 | \r | |
81 | /**\r | |
82 | * execute\r | |
83 | * \r | |
84 | * GenCapsuleHdrTask execute function is to assemble tool command line & execute\r | |
85 | * tool command line\r | |
86 | * \r | |
87 | * @throws BuidException\r | |
88 | */\r | |
89 | public void execute() throws BuildException {\r | |
90 | \r | |
91 | Project project = this.getOwningTarget().getProject();\r | |
92 | //\r | |
93 | // set Logger\r | |
94 | //\r | |
95 | FrameworkLogger logger = new FrameworkLogger(project, "gencapsulehdr");\r | |
96 | EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r | |
97 | EdkLog.setLogger(logger);\r | |
98 | //\r | |
99 | // absolute path of efi tools\r | |
100 | //\r | |
101 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
102 | String command;\r | |
103 | String argument;\r | |
104 | if (path == null) {\r | |
105 | command = toolName;\r | |
106 | } else {\r | |
107 | command = path + File.separatorChar + toolName;\r | |
108 | }\r | |
109 | //\r | |
110 | // argument of tools\r | |
111 | //\r | |
112 | File file = new File(outputFile);\r | |
113 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
114 | argument = this.verbose + this.dump + "-o " +this.outputDir\r | |
115 | + File.separatorChar + this.outputFile + " "\r | |
116 | + this.scriptFile + " " + this.size + " " + this.joinFlag + this.capsuleFile;\r | |
117 | } else {\r | |
118 | argument = this.verbose + this.dump + "-o " + this.outputFile\r | |
119 | + " " + this.scriptFile + " " + this.size + " " + this.joinFlag + this.capsuleFile;\r | |
120 | }\r | |
121 | //\r | |
122 | // return value of fwimage execution\r | |
123 | //\r | |
124 | int revl = -1;\r | |
125 | \r | |
126 | try {\r | |
127 | Commandline cmdline = new Commandline();\r | |
128 | cmdline.setExecutable(command);\r | |
129 | cmdline.createArgument().setLine(argument);\r | |
130 | \r | |
131 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
132 | Project.MSG_INFO, Project.MSG_WARN);\r | |
133 | Execute runner = new Execute(streamHandler, null);\r | |
134 | \r | |
135 | runner.setAntRun(project);\r | |
136 | runner.setCommandline(cmdline.getCommandline());\r | |
137 | //\r | |
138 | // Set debug log information.\r | |
139 | //\r | |
140 | EdkLog.log(EdkLog.EDK_INFO, Commandline.toString(cmdline\r | |
141 | .getCommandline()));\r | |
142 | \r | |
143 | revl = runner.execute();\r | |
144 | \r | |
145 | if (EFI_SUCCESS == revl) {\r | |
146 | //\r | |
147 | // command execution success\r | |
148 | //\r | |
149 | EdkLog.log(EdkLog.EDK_INFO, "GenCapsuleHdr succeeded!");\r | |
150 | } else {\r | |
151 | //\r | |
152 | // command execution fail\r | |
153 | //\r | |
154 | EdkLog.log(EdkLog.EDK_ERROR, "GenCapsuleHdr failed. (error="\r | |
155 | + Integer.toHexString(revl) + ")");\r | |
156 | throw new BuildException("GenCapsuleHdr failed. (error="\r | |
157 | + Integer.toHexString(revl) + ")");\r | |
158 | \r | |
159 | }\r | |
160 | } catch (Exception e) {\r | |
161 | throw new BuildException(e.getMessage());\r | |
162 | }\r | |
163 | }\r | |
164 | \r | |
165 | /**\r | |
166 | * getInputFile\r | |
167 | * \r | |
168 | * This function is to get class member "scriptFile".\r | |
169 | * \r | |
170 | * @return string of input file name.\r | |
171 | */\r | |
172 | public String getScriptFile() {\r | |
173 | return this.scriptFile;\r | |
174 | }\r | |
175 | \r | |
176 | /**\r | |
177 | * setComponentType\r | |
178 | * \r | |
179 | * This function is to set class member "inputFile".\r | |
180 | * \r | |
181 | * @param inputFile\r | |
182 | * string of input file name.\r | |
183 | */\r | |
184 | public void setScriptFile(String scriptFile) {\r | |
185 | this.scriptFile = "-script " + scriptFile;\r | |
186 | }\r | |
187 | \r | |
188 | /**\r | |
189 | * getOutputFile\r | |
190 | * \r | |
191 | * This function is to get class member "outputFile"\r | |
192 | * \r | |
193 | * @return outputFile string of output file name.\r | |
194 | */\r | |
195 | public String getOutputFile() {\r | |
196 | return outputFile;\r | |
197 | }\r | |
198 | \r | |
199 | /**\r | |
200 | * setOutputFile\r | |
201 | * \r | |
202 | * This function is to set class member "outputFile"\r | |
203 | * \r | |
204 | * @param outputFile\r | |
205 | * string of output file name.\r | |
206 | */\r | |
207 | public void setOutputFile(String outputFile) {\r | |
208 | this.outputFile = outputFile + " ";\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | * getOutputDir\r | |
213 | * \r | |
214 | * This function is to get class member "outputDir"\r | |
215 | * \r | |
216 | * @return outputDir string of output directory.\r | |
217 | */\r | |
218 | public String getOutputDir() {\r | |
219 | return outputDir;\r | |
220 | }\r | |
221 | \r | |
222 | /**\r | |
223 | * setOutputDir\r | |
224 | * \r | |
225 | * This function is to set class member "outputDir"\r | |
226 | * \r | |
227 | * @param outputDir\r | |
228 | * string of output directory.\r | |
229 | */\r | |
230 | public void setOutputDir(String outputDir) {\r | |
231 | this.outputDir = outputDir;\r | |
232 | }\r | |
233 | \r | |
234 | /**\r | |
235 | * getVerbose\r | |
236 | * \r | |
237 | * This function is to get class member "verbose"\r | |
238 | * \r | |
239 | * @return verbose the flag of verbose.\r | |
240 | */\r | |
241 | public String getVerbose() {\r | |
242 | return this.verbose;\r | |
243 | }\r | |
244 | \r | |
245 | /**\r | |
246 | * setVerbose\r | |
247 | * \r | |
248 | * This function is to set class member "verbose"\r | |
249 | * \r | |
250 | * @param verbose\r | |
251 | * True or False.\r | |
252 | */\r | |
253 | public void setVerbose(boolean verbose) {\r | |
254 | if (verbose) {\r | |
255 | this.verbose = "-v ";\r | |
256 | }\r | |
257 | }\r | |
258 | \r | |
259 | /**\r | |
260 | * getDump\r | |
261 | * \r | |
262 | * This function is to get class member "dump"\r | |
263 | * \r | |
264 | * @return verbose the flag of dump.\r | |
265 | */\r | |
266 | public String getDump() {\r | |
267 | return dump;\r | |
268 | }\r | |
269 | \r | |
270 | /**\r | |
271 | * setDump\r | |
272 | * \r | |
273 | * This function is to set class member "dump".\r | |
274 | * \r | |
275 | * @param dump\r | |
276 | * True or False.\r | |
277 | */\r | |
278 | public void setDump(boolean dump) {\r | |
279 | if (dump) {\r | |
280 | this.dump = "-dump ";\r | |
281 | }\r | |
282 | }\r | |
283 | \r | |
284 | /**\r | |
285 | * getSize\r | |
286 | * \r | |
287 | * This function is to set class member "size".\r | |
288 | * \r | |
289 | * @return size string of size value\r | |
290 | */\r | |
291 | public String getSize() {\r | |
292 | return size;\r | |
293 | }\r | |
294 | \r | |
295 | /**\r | |
296 | * setSize\r | |
297 | * \r | |
298 | * This function is to set class member "size".\r | |
299 | * \r | |
300 | * @param size string of size value.\r | |
301 | */\r | |
302 | public void setSize(String size) {\r | |
303 | this.size = "-split " + size;\r | |
304 | }\r | |
305 | \r | |
306 | /**\r | |
307 | * getCapsuleFile\r | |
308 | * \r | |
309 | * This function is to get class member "capsuleFile"\r | |
310 | * \r | |
311 | * @return capsuleFile capsule file name\r | |
312 | */\r | |
313 | public String getCapsuleFile() {\r | |
314 | return capsuleFile;\r | |
315 | }\r | |
316 | \r | |
317 | /**\r | |
318 | * setCapsuleFile\r | |
319 | * \r | |
320 | * This function is to set class member "capsuleFile"\r | |
321 | * \r | |
322 | * @param capsuleFile capsule file name\r | |
323 | */\r | |
324 | public void setCapsuleFile(String capsuleFile) {\r | |
325 | this.capsuleFile = capsuleFile;\r | |
326 | }\r | |
327 | \r | |
328 | /**\r | |
329 | * isJoinFlag\r | |
330 | * \r | |
331 | * This function is to get class member "joinFlag"\r | |
332 | * \r | |
333 | * @return joinFlag flag of if need to join split capsule images into \r | |
334 | * a single image.\r | |
335 | */\r | |
336 | public String getJoinFlag() {\r | |
337 | return joinFlag;\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | * setJoinFlag\r | |
342 | * \r | |
343 | * This function is to set class member "joinFlag"\r | |
344 | * \r | |
345 | * @param joinFlag flag of if need to join split capsule images into \r | |
346 | * a single image. \r | |
347 | */\r | |
348 | public void setJoinFlag(boolean joinFlag) {\r | |
349 | if (joinFlag){\r | |
350 | this.joinFlag = "-j "; \r | |
351 | }\r | |
352 | \r | |
353 | }\r | |
354 | }\r |