]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FwImageTask.java
c991aa3f58fc327e6ecb344e8327c5eac285b629
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / FwImageTask.java
1 /** @file
2 FwImageTask class.
3
4 FwImageTask is used to call FwImage.ext to generate the FwImage.
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 org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.taskdefs.Execute;
23 import org.apache.tools.ant.taskdefs.LogStreamHandler;
24 import org.apache.tools.ant.types.Commandline;
25
26 import org.tianocore.common.logger.EdkLog;
27
28 /**
29 FwImageTask class.
30
31 FwImageTask is used to call FwImage.ext to generate the FwImage.
32 **/
33 public class FwImageTask extends Task implements EfiDefine {
34 //
35 // fwimage tool name
36 //
37 private static String toolName = "FwImage";
38 //
39 // time&data
40 //
41 private ToolArg time = new ToolArg();
42 //
43 // input PE image
44 //
45 private FileArg peImage = new FileArg();
46 //
47 // output EFI image
48 //
49 private FileArg outImage = new FileArg();
50 //
51 // component type
52 //
53 private ToolArg componentType = new ToolArg();
54
55 /**
56 * assemble tool command line & execute tool command line
57 *
58 * @throws BuildException
59 */
60 /**
61 execute
62
63 FwimageTask execute function is to assemble tool command line & execute
64 tool command line
65
66 @throws BuidException
67 **/
68 public void execute() throws BuildException {
69
70 Project project = this.getOwningTarget().getProject();
71 //
72 // absolute path of efi tools
73 //
74 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
75 String command;
76 if (path == null) {
77 command = toolName;
78 } else {
79 command = path + "/" + toolName;
80 }
81 //
82 // argument of tools
83 //
84 String argument = "" + time + componentType + peImage + outImage;
85 //
86 // return value of fwimage execution
87 //
88 int revl = -1;
89
90 try {
91 Commandline cmdline = new Commandline();
92 cmdline.setExecutable(command);
93 cmdline.createArgument().setLine(argument);
94
95 LogStreamHandler streamHandler = new LogStreamHandler(this,
96 Project.MSG_INFO, Project.MSG_WARN);
97 Execute runner = new Execute(streamHandler, null);
98
99 runner.setAntRun(project);
100 runner.setCommandline(cmdline.getCommandline());
101
102 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
103 EdkLog.log(this, peImage.toFileList() + " => " + outImage.toFileList());
104
105 revl = runner.execute();
106 if (EFI_SUCCESS == revl) {
107 EdkLog.log(this, EdkLog.EDK_VERBOSE, "FwImage succeeded!");
108 } else {
109 //
110 // command execution fail
111 //
112 EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));
113 throw new BuildException("FwImage failed!");
114 }
115 } catch (Exception e) {
116 throw new BuildException(e.getMessage());
117 }
118 }
119
120 /**
121 setTime
122
123 This function is to set operation of class member "time".
124
125 @param time string of time
126 **/
127 public void setTime(String time) {
128 this.time.setArg(" -t ", time);
129 }
130
131 /**
132 getTime
133
134 This function is to get class member "time"
135 @return time string of time
136 **/
137 public String getTime() {
138 return this.time.getValue();
139 }
140
141 /**
142 getPeImage
143
144 This function is to get class member "peImage".
145 @return name of PE image
146 **/
147 public String getPeImage() {
148 return this.peImage.getValue();
149 }
150
151 /**
152 setPeImage
153
154 This function is to set class member "peImage"
155 @param peImage name of PE image
156 **/
157 public void setPeImage(String peImage) {
158 this.peImage.setArg(" ", peImage);
159 }
160
161 /**
162 getOutImage
163
164 This function is to get class member "outImage".
165 @return name of output EFI image
166 **/
167 public String getOutImage() {
168 return this.outImage.getValue();
169 }
170
171 /**
172 setOutImage
173
174 This function is to set class member "outImage".
175 @param outImage name of output EFI image
176 **/
177 public void setOutImage(String outImage) {
178 this.outImage.setArg(" ", outImage);
179 }
180
181 /**
182 getComponentType
183
184 This function is to get class member "componentType".
185
186 @return string of componentType
187 **/
188 public String getComponentType() {
189 return this.componentType.getValue();
190 }
191
192 /**
193 setComponentType
194
195 This function is to set class member "componentType".
196 @param componentType string of component type
197 **/
198 public void setComponentType(String componentType) {
199 this.componentType.setArg(" ", componentType);
200 }
201 }