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