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