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