Fix a misspelling.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / FwImageTask.java
CommitLineData
878ddf1f 1/** @file\r
2 FwImageTask class.\r
3\r
4 FwImageTask is used to call FwImage.ext to generate the FwImage.\r
5 \r
6 \r
7 Copyright (c) 2006, Intel Corporation\r
8 All rights reserved. This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12 \r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16 **/\r
17package org.tianocore.framework.tasks;\r
18\r
19import org.apache.tools.ant.Task;\r
20import org.apache.tools.ant.Project;\r
21import org.apache.tools.ant.BuildException;\r
22import org.apache.tools.ant.taskdefs.Execute;\r
23import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
24import org.apache.tools.ant.types.Commandline;\r
2da8968b 25import org.tianocore.build.*;\r
878ddf1f 26\r
27/**\r
28 FwImageTask class.\r
29\r
30 FwImageTask is used to call FwImage.ext to generate the FwImage.\r
31**/\r
32public class FwImageTask extends Task implements EfiDefine{\r
33 ///\r
34 /// time&data \r
35 ///\r
36 private String time = "";\r
37 ///\r
38 /// input PE image\r
39 /// \r
40 private String peImage = "";\r
41 ///\r
42 /// output EFI image\r
43 /// \r
44 private String outImage = "";\r
45 ///\r
46 /// component type\r
47 ///\r
48 private String componentType = "";\r
49\r
50 /**\r
51 * assemble tool command line & execute tool command line\r
52 * \r
53 * @throws BuildException\r
54 */\r
55 /**\r
56 execute \r
57 \r
58 FwimageTask execute function is to assemble tool command line & execute\r
59 tool command line\r
60 \r
61 @throws BuidException\r
62 **/\r
63 public void execute() throws BuildException {\r
64\r
65 Project project = this.getOwningTarget().getProject();\r
66 //\r
67 // absolute path of efi tools\r
68 //\r
2da8968b 69 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
878ddf1f 70 String command;\r
71 if (path == null) {\r
2da8968b 72 command = "fwimage";\r
878ddf1f 73 } else {\r
2da8968b 74 command = path + "/" + "fwimage";\r
878ddf1f 75 }\r
76 //\r
77 // argument of tools\r
78 //\r
79 String argument = time + componentType + peImage + outImage;\r
80 //\r
81 // return value of fwimage execution\r
82 //\r
83 int revl = -1;\r
84\r
85 try {\r
86 Commandline cmdline = new Commandline();\r
87 cmdline.setExecutable(command);\r
88 cmdline.createArgument().setLine(argument);\r
89\r
90 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
91 Project.MSG_INFO, Project.MSG_WARN);\r
92 Execute runner = new Execute(streamHandler, null);\r
93\r
94 runner.setAntRun(project);\r
95 runner.setCommandline(cmdline.getCommandline());\r
2da8968b 96 //System.out.println(Commandline.toString(cmdline.getCommandline()));\r
97 //GenBuildTask.myLogger.log(Commandline.toString(cmdline.getCommandline()),0);\r
98 //getProject().log(Commandline.toString(cmdline.getCommandline()));\r
878ddf1f 99 revl = runner.execute();\r
100 if (EFI_SUCCESS == revl) {\r
101 //\r
102 // command execution success\r
103 //\r
1f0032d8 104 System.out.println("fwimage succeeded!");\r
878ddf1f 105 } else {\r
106 //\r
107 // command execution fail\r
108 //\r
109 System.out.println("fwimage failed. (error="\r
110 + Integer.toHexString(revl) + ")");\r
111 throw new BuildException("fwimage failed. (error="\r
112 + Integer.toHexString(revl) + ")");\r
113\r
114 }\r
115 } catch (Exception e) {\r
116 throw new BuildException(e.getMessage());\r
117 }\r
118 }\r
119\r
120 /**\r
121 setTime\r
122 \r
123 This function is to set operation of class member "time".\r
124 \r
125 @param time string of time\r
126 **/\r
127 public void setTime(String time) {\r
128 this.time = " -t " + time;\r
129 }\r
130\r
131 /**\r
132 getTime\r
133 \r
134 This function is to get class member "time"\r
135 @return time string of time\r
136 **/\r
137 public String getTime() {\r
138 return this.time;\r
139 }\r
140\r
141 /**\r
142 getPeImage\r
143 \r
144 This function is to get class member "peImage".\r
145 @return name of PE image\r
146 **/\r
147 public String getPeImage() {\r
148 return this.peImage;\r
149 }\r
150\r
151 /**\r
152 setPeImage\r
153 \r
154 This function is to set class member "peImage"\r
155 @param peImage name of PE image\r
156 **/\r
157 public void setPeImage(String peImage) {\r
158 this.peImage = " " + peImage;\r
159 }\r
160\r
161 /**\r
162 getOutImage\r
163 \r
164 This function is to get class member "outImage".\r
165 @return name of output EFI image\r
166 **/\r
167 public String getOutImage() {\r
168 return this.outImage;\r
169 }\r
170\r
171 /**\r
172 setOutImage\r
173 \r
174 This function is to set class member "outImage".\r
175 @param outImage name of output EFI image\r
176 **/\r
177 public void setOutImage(String outImage) {\r
178 this.outImage = " " + outImage;\r
179 }\r
180\r
181 /**\r
182 getComponentType\r
183 \r
184 This function is to get class member "componentType".\r
185 \r
186 @return string of componentType\r
187 **/\r
188 public String getComponentType() {\r
189 return this.componentType;\r
190 }\r
191\r
192 /**\r
193 setComponentType\r
194 \r
195 This function is to set class member "componentType".\r
196 @param componentType string of component type\r
197 **/\r
198 public void setComponentType(String componentType) {\r
199 this.componentType = " " + componentType;\r
200 }\r
201}\r