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