Polished the build tools' screen output to be in a more coherent form
[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_VERBOSE, Commandline.toString(cmdline.getCommandline()));
129 EdkLog.log(EdkLog.EDK_INFO, (new File(this.inputFile)).getName());
130
131 revl = runner.execute();
132
133 if (EFI_SUCCESS == revl) {
134 //
135 // command execution success
136 //
137 EdkLog.log(EdkLog.EDK_VERBOSE, "GenTeImage succeeded!");
138 } else {
139 //
140 // command execution fail
141 //
142 EdkLog.log(EdkLog.EDK_INFO, "ERROR = "+ Integer.toHexString(revl));
143 throw new BuildException("GenTeImage failed!");
144 }
145 } catch (Exception e) {
146 throw new BuildException(e.getMessage());
147 }
148 }
149
150 /**
151 * getInputFile
152 *
153 * This function is to get class member "inputFile".
154 *
155 * @return string of input file name.
156 */
157 public String getInputFile() {
158 return inputFile;
159 }
160
161 /**
162 * setComponentType
163 *
164 * This function is to set class member "inputFile".
165 *
166 * @param inputFile
167 * string of input file name.
168 */
169 public void setInputFile(String inputFile) {
170 this.inputFile = inputFile;
171 }
172
173 /**
174 * getOutputFile
175 *
176 * This function is to get class member "outputFile"
177 *
178 * @return outputFile string of output file name.
179 */
180 public String getOutputFile() {
181 return outputFile;
182 }
183
184 /**
185 * setOutputFile
186 *
187 * This function is to set class member "outputFile"
188 *
189 * @param outputFile
190 * string of output file name.
191 */
192 public void setOutputFile(String outputFile) {
193 this.outputFile = outputFile + " ";
194 }
195
196 /**
197 * getOutputDir
198 *
199 * This function is to get class member "outputDir"
200 *
201 * @return outputDir string of output directory.
202 */
203 public String getOutputDir() {
204 return outputDir;
205 }
206
207 /**
208 * setOutputDir
209 *
210 * This function is to set class member "outputDir"
211 *
212 * @param outputDir
213 * string of output directory.
214 */
215 public void setOutputDir(String outputDir) {
216 this.outputDir = outputDir;
217 }
218
219 /**
220 * getVerbose
221 *
222 * This function is to get class member "verbose"
223 *
224 * @return verbose the flag of verbose.
225 */
226 public String getVerbose() {
227 return this.verbose;
228 }
229
230 /**
231 * setVerbose
232 *
233 * This function is to set class member "verbose"
234 *
235 * @param verbose
236 * True or False.
237 */
238 public void setVerbose(boolean verbose) {
239 if (verbose) {
240 this.verbose = "-v ";
241 }
242 }
243
244 /**
245 * getDump
246 *
247 * This function is to get class member "dump"
248 *
249 * @return verbose the flag of dump.
250 */
251 public String getDump() {
252 return dump;
253 }
254
255 /**
256 * setDump
257 *
258 * This function is to set class member "dump"
259 *
260 * @param dump
261 * True or False.
262 */
263 public void setDump(boolean dump) {
264 if (dump) {
265 this.dump = "-dump ";
266 }
267 }
268 }