]>
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 | |
a15bb0d3 | 94 | // absolute path of efi tools\r |
95 | //\r | |
96 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
97 | String command;\r | |
98 | String argument;\r | |
99 | if (path == null) {\r | |
100 | command = toolName;\r | |
101 | } else {\r | |
102 | command = path + File.separatorChar + toolName;\r | |
103 | }\r | |
104 | //\r | |
105 | // argument of tools\r | |
106 | //\r | |
107 | File file = new File(outputFile);\r | |
108 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
109 | argument = this.verbose + this.dump + "-o " +this.outputDir\r | |
110 | + File.separatorChar + this.outputFile + " "\r | |
111 | + this.scriptFile + " " + this.size + " " + this.joinFlag + this.capsuleFile;\r | |
112 | } else {\r | |
113 | argument = this.verbose + this.dump + "-o " + this.outputFile\r | |
114 | + " " + this.scriptFile + " " + this.size + " " + this.joinFlag + this.capsuleFile;\r | |
115 | }\r | |
116 | //\r | |
117 | // return value of fwimage execution\r | |
118 | //\r | |
119 | int revl = -1;\r | |
120 | \r | |
121 | try {\r | |
122 | Commandline cmdline = new Commandline();\r | |
123 | cmdline.setExecutable(command);\r | |
124 | cmdline.createArgument().setLine(argument);\r | |
125 | \r | |
126 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
127 | Project.MSG_INFO, Project.MSG_WARN);\r | |
128 | Execute runner = new Execute(streamHandler, null);\r | |
129 | \r | |
130 | runner.setAntRun(project);\r | |
131 | runner.setCommandline(cmdline.getCommandline());\r | |
132 | //\r | |
133 | // Set debug log information.\r | |
134 | //\r | |
91f7d582 | 135 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r |
136 | EdkLog.log(this, EdkLog.EDK_INFO, (new File(scriptFile)).getName());\r | |
a15bb0d3 | 137 | revl = runner.execute();\r |
138 | \r | |
139 | if (EFI_SUCCESS == revl) {\r | |
140 | //\r | |
141 | // command execution success\r | |
142 | //\r | |
91f7d582 | 143 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "GenCapsuleHdr succeeded!");\r |
a15bb0d3 | 144 | } else {\r |
145 | //\r | |
146 | // command execution fail\r | |
147 | //\r | |
91f7d582 | 148 | EdkLog.log(this, EdkLog.EDK_ERROR, "ERROR = " + Integer.toHexString(revl));\r |
219e2247 | 149 | throw new BuildException("GenCapsuleHdr failed!");\r |
a15bb0d3 | 150 | }\r |
151 | } catch (Exception e) {\r | |
152 | throw new BuildException(e.getMessage());\r | |
153 | }\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | * getInputFile\r | |
ff225cbb | 158 | *\r |
a15bb0d3 | 159 | * This function is to get class member "scriptFile".\r |
ff225cbb | 160 | *\r |
a15bb0d3 | 161 | * @return string of input file name.\r |
162 | */\r | |
163 | public String getScriptFile() {\r | |
164 | return this.scriptFile;\r | |
165 | }\r | |
166 | \r | |
167 | /**\r | |
168 | * setComponentType\r | |
ff225cbb | 169 | *\r |
a15bb0d3 | 170 | * This function is to set class member "inputFile".\r |
ff225cbb | 171 | *\r |
a15bb0d3 | 172 | * @param inputFile\r |
173 | * string of input file name.\r | |
174 | */\r | |
175 | public void setScriptFile(String scriptFile) {\r | |
176 | this.scriptFile = "-script " + scriptFile;\r | |
177 | }\r | |
178 | \r | |
179 | /**\r | |
180 | * getOutputFile\r | |
ff225cbb | 181 | *\r |
a15bb0d3 | 182 | * This function is to get class member "outputFile"\r |
ff225cbb | 183 | *\r |
a15bb0d3 | 184 | * @return outputFile string of output file name.\r |
185 | */\r | |
186 | public String getOutputFile() {\r | |
187 | return outputFile;\r | |
188 | }\r | |
189 | \r | |
190 | /**\r | |
191 | * setOutputFile\r | |
ff225cbb | 192 | *\r |
a15bb0d3 | 193 | * This function is to set class member "outputFile"\r |
ff225cbb | 194 | *\r |
a15bb0d3 | 195 | * @param outputFile\r |
196 | * string of output file name.\r | |
197 | */\r | |
198 | public void setOutputFile(String outputFile) {\r | |
199 | this.outputFile = outputFile + " ";\r | |
200 | }\r | |
201 | \r | |
202 | /**\r | |
203 | * getOutputDir\r | |
ff225cbb | 204 | *\r |
a15bb0d3 | 205 | * This function is to get class member "outputDir"\r |
ff225cbb | 206 | *\r |
a15bb0d3 | 207 | * @return outputDir string of output directory.\r |
208 | */\r | |
209 | public String getOutputDir() {\r | |
210 | return outputDir;\r | |
211 | }\r | |
212 | \r | |
213 | /**\r | |
214 | * setOutputDir\r | |
ff225cbb | 215 | *\r |
a15bb0d3 | 216 | * This function is to set class member "outputDir"\r |
ff225cbb | 217 | *\r |
a15bb0d3 | 218 | * @param outputDir\r |
219 | * string of output directory.\r | |
220 | */\r | |
221 | public void setOutputDir(String outputDir) {\r | |
222 | this.outputDir = outputDir;\r | |
223 | }\r | |
224 | \r | |
225 | /**\r | |
226 | * getVerbose\r | |
ff225cbb | 227 | *\r |
a15bb0d3 | 228 | * This function is to get class member "verbose"\r |
ff225cbb | 229 | *\r |
a15bb0d3 | 230 | * @return verbose the flag of verbose.\r |
231 | */\r | |
232 | public String getVerbose() {\r | |
233 | return this.verbose;\r | |
234 | }\r | |
235 | \r | |
236 | /**\r | |
237 | * setVerbose\r | |
ff225cbb | 238 | *\r |
a15bb0d3 | 239 | * This function is to set class member "verbose"\r |
ff225cbb | 240 | *\r |
a15bb0d3 | 241 | * @param verbose\r |
242 | * True or False.\r | |
243 | */\r | |
244 | public void setVerbose(boolean verbose) {\r | |
245 | if (verbose) {\r | |
246 | this.verbose = "-v ";\r | |
247 | }\r | |
248 | }\r | |
249 | \r | |
250 | /**\r | |
251 | * getDump\r | |
ff225cbb | 252 | *\r |
a15bb0d3 | 253 | * This function is to get class member "dump"\r |
ff225cbb | 254 | *\r |
a15bb0d3 | 255 | * @return verbose the flag of dump.\r |
256 | */\r | |
257 | public String getDump() {\r | |
258 | return dump;\r | |
259 | }\r | |
260 | \r | |
261 | /**\r | |
262 | * setDump\r | |
ff225cbb | 263 | *\r |
a15bb0d3 | 264 | * This function is to set class member "dump".\r |
ff225cbb | 265 | *\r |
a15bb0d3 | 266 | * @param dump\r |
267 | * True or False.\r | |
268 | */\r | |
269 | public void setDump(boolean dump) {\r | |
270 | if (dump) {\r | |
271 | this.dump = "-dump ";\r | |
272 | }\r | |
273 | }\r | |
274 | \r | |
275 | /**\r | |
276 | * getSize\r | |
ff225cbb | 277 | *\r |
a15bb0d3 | 278 | * This function is to set class member "size".\r |
ff225cbb | 279 | *\r |
a15bb0d3 | 280 | * @return size string of size value\r |
281 | */\r | |
282 | public String getSize() {\r | |
283 | return size;\r | |
284 | }\r | |
285 | \r | |
286 | /**\r | |
287 | * setSize\r | |
ff225cbb | 288 | *\r |
a15bb0d3 | 289 | * This function is to set class member "size".\r |
ff225cbb | 290 | *\r |
a15bb0d3 | 291 | * @param size string of size value.\r |
292 | */\r | |
293 | public void setSize(String size) {\r | |
294 | this.size = "-split " + size;\r | |
295 | }\r | |
296 | \r | |
297 | /**\r | |
298 | * getCapsuleFile\r | |
ff225cbb | 299 | *\r |
a15bb0d3 | 300 | * This function is to get class member "capsuleFile"\r |
ff225cbb | 301 | *\r |
a15bb0d3 | 302 | * @return capsuleFile capsule file name\r |
303 | */\r | |
304 | public String getCapsuleFile() {\r | |
305 | return capsuleFile;\r | |
306 | }\r | |
307 | \r | |
308 | /**\r | |
309 | * setCapsuleFile\r | |
ff225cbb | 310 | *\r |
a15bb0d3 | 311 | * This function is to set class member "capsuleFile"\r |
ff225cbb | 312 | *\r |
a15bb0d3 | 313 | * @param capsuleFile capsule file name\r |
314 | */\r | |
315 | public void setCapsuleFile(String capsuleFile) {\r | |
316 | this.capsuleFile = capsuleFile;\r | |
317 | }\r | |
318 | \r | |
319 | /**\r | |
320 | * isJoinFlag\r | |
ff225cbb | 321 | *\r |
a15bb0d3 | 322 | * This function is to get class member "joinFlag"\r |
ff225cbb | 323 | *\r |
324 | * @return joinFlag flag of if need to join split capsule images into\r | |
a15bb0d3 | 325 | * a single image.\r |
326 | */\r | |
327 | public String getJoinFlag() {\r | |
328 | return joinFlag;\r | |
329 | }\r | |
330 | \r | |
331 | /**\r | |
332 | * setJoinFlag\r | |
ff225cbb | 333 | *\r |
a15bb0d3 | 334 | * This function is to set class member "joinFlag"\r |
ff225cbb | 335 | *\r |
336 | * @param joinFlag flag of if need to join split capsule images into\r | |
337 | * a single image.\r | |
a15bb0d3 | 338 | */\r |
339 | public void setJoinFlag(boolean joinFlag) {\r | |
340 | if (joinFlag){\r | |
ff225cbb | 341 | this.joinFlag = "-j ";\r |
a15bb0d3 | 342 | }\r |
ff225cbb | 343 | \r |
a15bb0d3 | 344 | }\r |
345 | }\r |