]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCapsuleHdrTask.java
Polished the build tools' screen output to be in a more coherent form
[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_VERBOSE, Commandline.toString(cmdline.getCommandline()));
141 EdkLog.log(EdkLog.EDK_INFO, (new File(scriptFile)).getName());
142 revl = runner.execute();
143
144 if (EFI_SUCCESS == revl) {
145 //
146 // command execution success
147 //
148 EdkLog.log(EdkLog.EDK_VERBOSE, "GenCapsuleHdr succeeded!");
149 } else {
150 //
151 // command execution fail
152 //
153 EdkLog.log(EdkLog.EDK_ERROR, "ERROR = " + Integer.toHexString(revl));
154 throw new BuildException("GenCapsuleHdr failed!");
155 }
156 } catch (Exception e) {
157 throw new BuildException(e.getMessage());
158 }
159 }
160
161 /**
162 * getInputFile
163 *
164 * This function is to get class member "scriptFile".
165 *
166 * @return string of input file name.
167 */
168 public String getScriptFile() {
169 return this.scriptFile;
170 }
171
172 /**
173 * setComponentType
174 *
175 * This function is to set class member "inputFile".
176 *
177 * @param inputFile
178 * string of input file name.
179 */
180 public void setScriptFile(String scriptFile) {
181 this.scriptFile = "-script " + scriptFile;
182 }
183
184 /**
185 * getOutputFile
186 *
187 * This function is to get class member "outputFile"
188 *
189 * @return outputFile string of output file name.
190 */
191 public String getOutputFile() {
192 return outputFile;
193 }
194
195 /**
196 * setOutputFile
197 *
198 * This function is to set class member "outputFile"
199 *
200 * @param outputFile
201 * string of output file name.
202 */
203 public void setOutputFile(String outputFile) {
204 this.outputFile = outputFile + " ";
205 }
206
207 /**
208 * getOutputDir
209 *
210 * This function is to get class member "outputDir"
211 *
212 * @return outputDir string of output directory.
213 */
214 public String getOutputDir() {
215 return outputDir;
216 }
217
218 /**
219 * setOutputDir
220 *
221 * This function is to set class member "outputDir"
222 *
223 * @param outputDir
224 * string of output directory.
225 */
226 public void setOutputDir(String outputDir) {
227 this.outputDir = outputDir;
228 }
229
230 /**
231 * getVerbose
232 *
233 * This function is to get class member "verbose"
234 *
235 * @return verbose the flag of verbose.
236 */
237 public String getVerbose() {
238 return this.verbose;
239 }
240
241 /**
242 * setVerbose
243 *
244 * This function is to set class member "verbose"
245 *
246 * @param verbose
247 * True or False.
248 */
249 public void setVerbose(boolean verbose) {
250 if (verbose) {
251 this.verbose = "-v ";
252 }
253 }
254
255 /**
256 * getDump
257 *
258 * This function is to get class member "dump"
259 *
260 * @return verbose the flag of dump.
261 */
262 public String getDump() {
263 return dump;
264 }
265
266 /**
267 * setDump
268 *
269 * This function is to set class member "dump".
270 *
271 * @param dump
272 * True or False.
273 */
274 public void setDump(boolean dump) {
275 if (dump) {
276 this.dump = "-dump ";
277 }
278 }
279
280 /**
281 * getSize
282 *
283 * This function is to set class member "size".
284 *
285 * @return size string of size value
286 */
287 public String getSize() {
288 return size;
289 }
290
291 /**
292 * setSize
293 *
294 * This function is to set class member "size".
295 *
296 * @param size string of size value.
297 */
298 public void setSize(String size) {
299 this.size = "-split " + size;
300 }
301
302 /**
303 * getCapsuleFile
304 *
305 * This function is to get class member "capsuleFile"
306 *
307 * @return capsuleFile capsule file name
308 */
309 public String getCapsuleFile() {
310 return capsuleFile;
311 }
312
313 /**
314 * setCapsuleFile
315 *
316 * This function is to set class member "capsuleFile"
317 *
318 * @param capsuleFile capsule file name
319 */
320 public void setCapsuleFile(String capsuleFile) {
321 this.capsuleFile = capsuleFile;
322 }
323
324 /**
325 * isJoinFlag
326 *
327 * This function is to get class member "joinFlag"
328 *
329 * @return joinFlag flag of if need to join split capsule images into
330 * a single image.
331 */
332 public String getJoinFlag() {
333 return joinFlag;
334 }
335
336 /**
337 * setJoinFlag
338 *
339 * This function is to set class member "joinFlag"
340 *
341 * @param joinFlag flag of if need to join split capsule images into
342 * a single image.
343 */
344 public void setJoinFlag(boolean joinFlag) {
345 if (joinFlag){
346 this.joinFlag = "-j ";
347 }
348
349 }
350 }