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