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