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