]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenTeImageTask.java
347ae91e2547d625f37f294d6bf6919592845d25
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenTeImageTask.java
1 /** @file
2 GenTeImageTask class.
3
4 GenTeImageTask is used to call GenTEImage.exe to generate TE image .
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.Task;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.BuildException;
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 * GenTeImageTask class.
31 *
32 * GenTeImageTask is used to call GenAcpiTable.exe to generate ACPI Table image .
33 */
34 public class GenTeImageTask extends Task implements EfiDefine {
35 ///
36 /// tool name
37 ///
38 private String toolName = "GenTeImage";
39 ///
40 /// input file
41 ///
42 private String inputFile = "";
43
44 ///
45 /// output file
46 ///
47 private String outputFile = "";
48
49 ///
50 /// output directory, this variable is added by jave wrap
51 ///
52 private String outputDir = "";
53
54 ///
55 /// Verbose flag
56 ///
57 private String verbose = "";
58
59 ///
60 /// Dump flag
61 ///
62 private String dump = "";
63
64 /**
65 * assemble tool command line & execute tool command line
66 *
67 * @throws BuildException
68 */
69 /**
70 * execute
71 *
72 * GenTeImgaeTask execute function is to assemble tool command line & execute
73 * tool command line
74 *
75 * @throws BuidException
76 */
77 public void execute() throws BuildException {
78
79 Project project = this.getOwningTarget().getProject();
80 //
81 // set Logger
82 //
83 FrameworkLogger logger = new FrameworkLogger(project, toolName.toLowerCase());
84 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
85 EdkLog.setLogger(logger);
86 //
87 // absolute path of efi tools
88 //
89 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
90 String command;
91 String argument;
92 if (path == null) {
93 command = toolName;
94 } else {
95 command = path + File.separatorChar + toolName;
96 }
97 //
98 // argument of tools
99 //
100 File file = new File(outputFile);
101 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
102 argument = this.verbose + this.dump + "-o " +this.outputDir
103 + File.separatorChar + this.outputFile + " "
104 + this.inputFile;
105 } else {
106 argument = this.verbose + this.dump + "-o " + this.outputFile
107 + " " + this.inputFile;
108 }
109 //
110 // return value of fwimage execution
111 //
112 int revl = -1;
113
114 try {
115 Commandline cmdline = new Commandline();
116 cmdline.setExecutable(command);
117 cmdline.createArgument().setLine(argument);
118
119 LogStreamHandler streamHandler = new LogStreamHandler(this,
120 Project.MSG_INFO, Project.MSG_WARN);
121 Execute runner = new Execute(streamHandler, null);
122
123 runner.setAntRun(project);
124 runner.setCommandline(cmdline.getCommandline());
125 //
126 // Set debug log information.
127 //
128 EdkLog.log(EdkLog.EDK_INFO, Commandline.toString(cmdline
129 .getCommandline()));
130
131 revl = runner.execute();
132
133 if (EFI_SUCCESS == revl) {
134 //
135 // command execution success
136 //
137 EdkLog.log(EdkLog.EDK_INFO, "GenTeImage succeeded!");
138 } else {
139 //
140 // command execution fail
141 //
142 EdkLog.log(EdkLog.EDK_ERROR, "GenTeImage failed. (error="
143 + Integer.toHexString(revl) + ")");
144 throw new BuildException("GenTeImage failed. (error="
145 + Integer.toHexString(revl) + ")");
146
147 }
148 } catch (Exception e) {
149 throw new BuildException(e.getMessage());
150 }
151 }
152
153 /**
154 * getInputFile
155 *
156 * This function is to get class member "inputFile".
157 *
158 * @return string of input file name.
159 */
160 public String getInputFile() {
161 return inputFile;
162 }
163
164 /**
165 * setComponentType
166 *
167 * This function is to set class member "inputFile".
168 *
169 * @param inputFile
170 * string of input file name.
171 */
172 public void setInputFile(String inputFile) {
173 this.inputFile = inputFile;
174 }
175
176 /**
177 * getOutputFile
178 *
179 * This function is to get class member "outputFile"
180 *
181 * @return outputFile string of output file name.
182 */
183 public String getOutputFile() {
184 return outputFile;
185 }
186
187 /**
188 * setOutputFile
189 *
190 * This function is to set class member "outputFile"
191 *
192 * @param outputFile
193 * string of output file name.
194 */
195 public void setOutputFile(String outputFile) {
196 this.outputFile = outputFile + " ";
197 }
198
199 /**
200 * getOutputDir
201 *
202 * This function is to get class member "outputDir"
203 *
204 * @return outputDir string of output directory.
205 */
206 public String getOutputDir() {
207 return outputDir;
208 }
209
210 /**
211 * setOutputDir
212 *
213 * This function is to set class member "outputDir"
214 *
215 * @param outputDir
216 * string of output directory.
217 */
218 public void setOutputDir(String outputDir) {
219 this.outputDir = outputDir;
220 }
221
222 /**
223 * getVerbose
224 *
225 * This function is to get class member "verbose"
226 *
227 * @return verbose the flag of verbose.
228 */
229 public String getVerbose() {
230 return this.verbose;
231 }
232
233 /**
234 * setVerbose
235 *
236 * This function is to set class member "verbose"
237 *
238 * @param verbose
239 * True or False.
240 */
241 public void setVerbose(boolean verbose) {
242 if (verbose) {
243 this.verbose = "-v ";
244 }
245 }
246
247 /**
248 * getDump
249 *
250 * This function is to get class member "dump"
251 *
252 * @return verbose the flag of dump.
253 */
254 public String getDump() {
255 return dump;
256 }
257
258 /**
259 * setDump
260 *
261 * This function is to set class member "dump"
262 *
263 * @param dump
264 * True or False.
265 */
266 public void setDump(boolean dump) {
267 if (dump) {
268 this.dump = "-dump ";
269 }
270 }
271 }