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