]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCapsuleHdrTask.java
- Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed.
[mirror_edk2.git] / Tools / Java / 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 FileArg scriptFile = new FileArg();
45
46 //
47 // output file
48 //
49 private FileArg outputFile = new FileArg();
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 ToolArg verbose = new ToolArg();
60
61 //
62 // Dump flag
63 //
64 private ToolArg dump = new ToolArg();
65
66 //
67 // Split size
68 //
69 private ToolArg size = new ToolArg();
70
71 //
72 // capsule into one image flag
73 //
74 private ToolArg joinFlag = new ToolArg();
75
76 //
77 // capsule file
78 //
79 private FileArg capsuleFile = new FileArg();
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.separator + toolName;
103 }
104 //
105 // argument of tools
106 //
107 argument = "" + this.verbose + this.dump + this.outputFile
108 + this.scriptFile + this.size + this.joinFlag + this.capsuleFile;
109
110 //
111 // return value of fwimage execution
112 //
113 int revl = -1;
114
115 try {
116 Commandline cmdline = new Commandline();
117 cmdline.setExecutable(command);
118 cmdline.createArgument().setLine(argument);
119
120 LogStreamHandler streamHandler = new LogStreamHandler(this,
121 Project.MSG_INFO, Project.MSG_WARN);
122 Execute runner = new Execute(streamHandler, null);
123
124 runner.setAntRun(project);
125 runner.setCommandline(cmdline.getCommandline());
126 runner.setWorkingDirectory(new File(outputDir));
127
128 //
129 // Set debug log information.
130 //
131 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
132 EdkLog.log(this, EdkLog.EDK_INFO, scriptFile.toFileList() + " => " +
133 outputFile.toFileList() + capsuleFile.toFileList());
134
135 revl = runner.execute();
136 if (EFI_SUCCESS == revl) {
137 //
138 // command execution success
139 //
140 EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
141 } else {
142 //
143 // command execution fail
144 //
145 EdkLog.log(this, EdkLog.EDK_ERROR, "ERROR = " + Integer.toHexString(revl));
146 throw new BuildException(toolName + " failed!");
147 }
148 } catch (Exception e) {
149 throw new BuildException(e.getMessage());
150 }
151 }
152
153 /**
154 getInputFile
155
156 This function is to get class member "scriptFile".
157
158 @return string of input file name.
159 **/
160 public String getScriptFile() {
161 return this.scriptFile.getValue();
162 }
163
164 /**
165 setComponentType
166
167 This function is to set class member "inputFile".
168
169 @param inputFile
170 string of input file name.
171 **/
172 public void setScriptFile(String scriptFile) {
173 this.scriptFile.setArg(" -script ", scriptFile);
174 }
175
176 /**
177 getOutputFile
178
179 This function is to get class member "outputFile"
180
181 @return outputFile string of output file name.
182 **/
183 public String getOutputFile() {
184 return outputFile.getValue();
185 }
186
187 /**
188 setOutputFile
189
190 This function is to set class member "outputFile"
191
192 @param outputFile
193 string of output file name.
194 **/
195 public void setOutputFile(String outputFile) {
196 this.outputFile.setArg(" -o ", outputFile);
197 }
198
199 /**
200 getOutputDir
201
202 This function is to get class member "outputDir"
203
204 @return outputDir string of output directory.
205 **/
206 public String getOutputDir() {
207 return outputDir;
208 }
209
210 /**
211 setOutputDir
212
213 This function is to set class member "outputDir"
214
215 @param outputDir
216 string of output directory.
217 **/
218 public void setOutputDir(String outputDir) {
219 this.outputDir = outputDir;
220 }
221
222 /**
223 getVerbose
224
225 This function is to get class member "verbose"
226
227 @return verbose the flag of verbose.
228 **/
229 public String getVerbose() {
230 return this.verbose.getValue();
231 }
232
233 /**
234 setVerbose
235
236 This function is to set class member "verbose"
237
238 @param verbose
239 True or False.
240 **/
241 public void setVerbose(boolean verbose) {
242 if (verbose) {
243 this.verbose.setArg(" -", "v");
244 }
245 }
246
247 /**
248 getDump
249
250 This function is to get class member "dump"
251
252 @return verbose the flag of dump.
253 **/
254 public String getDump() {
255 return dump.getValue();
256 }
257
258 /**
259 setDump
260
261 This function is to set class member "dump".
262
263 @param dump
264 True or False.
265 **/
266 public void setDump(boolean dump) {
267 if (dump) {
268 this.dump.setArg(" -", "dump");
269 }
270 }
271
272 /**
273 getSize
274
275 This function is to set class member "size".
276
277 @return size string of size value
278 **/
279 public String getSize() {
280 return size.getValue();
281 }
282
283 /**
284 setSize
285
286 This function is to set class member "size".
287
288 @param size string of size value.
289 **/
290 public void setSize(String size) {
291 this.size.setArg(" -split ", size);
292 }
293
294 /**
295 getCapsuleFile
296
297 This function is to get class member "capsuleFile"
298
299 @return capsuleFile capsule file name
300 **/
301 public String getCapsuleFile() {
302 return capsuleFile.getValue();
303 }
304
305 /**
306 setCapsuleFile
307
308 This function is to set class member "capsuleFile"
309
310 @param capsuleFile capsule file name
311 **/
312 public void setCapsuleFile(String capsuleFile) {
313 this.capsuleFile.setArg(" ", capsuleFile);
314 }
315
316 /**
317 isJoinFlag
318
319 This function is to get class member "joinFlag"
320
321 @return joinFlag flag of if need to join split capsule images into
322 a single image.
323 **/
324 public String getJoinFlag() {
325 return joinFlag.getValue();
326 }
327
328 /**
329 setJoinFlag
330
331 This function is to set class member "joinFlag"
332
333 @param joinFlag flag of if need to join split capsule images into
334 a single image.
335 **/
336 public void setJoinFlag(boolean joinFlag) {
337 if (joinFlag){
338 this.joinFlag.setArg(" -", "j");
339 }
340 }
341 }