]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenTeImageTask.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[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 // absolute path of efi tools
83 //
84 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
85 String command;
86 String argument;
87 if (path == null) {
88 command = toolName;
89 } else {
90 command = path + File.separatorChar + toolName;
91 }
92 //
93 // argument of tools
94 //
95 File file = new File(outputFile);
96 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
97 argument = this.verbose + this.dump + "-o " +this.outputDir
98 + File.separatorChar + this.outputFile + " "
99 + this.inputFile;
100 } else {
101 argument = this.verbose + this.dump + "-o " + this.outputFile
102 + " " + this.inputFile;
103 }
104 //
105 // return value of fwimage execution
106 //
107 int revl = -1;
108
109 try {
110 Commandline cmdline = new Commandline();
111 cmdline.setExecutable(command);
112 cmdline.createArgument().setLine(argument);
113
114 LogStreamHandler streamHandler = new LogStreamHandler(this,
115 Project.MSG_INFO, Project.MSG_WARN);
116 Execute runner = new Execute(streamHandler, null);
117
118 runner.setAntRun(project);
119 runner.setCommandline(cmdline.getCommandline());
120 //
121 // Set debug log information.
122 //
123 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
124 EdkLog.log(this, EdkLog.EDK_INFO, (new File(this.inputFile)).getName());
125
126 revl = runner.execute();
127
128 if (EFI_SUCCESS == revl) {
129 //
130 // command execution success
131 //
132 EdkLog.log(this, EdkLog.EDK_VERBOSE, "GenTeImage succeeded!");
133 } else {
134 //
135 // command execution fail
136 //
137 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = "+ Integer.toHexString(revl));
138 throw new BuildException("GenTeImage failed!");
139 }
140 } catch (Exception e) {
141 throw new BuildException(e.getMessage());
142 }
143 }
144
145 /**
146 * getInputFile
147 *
148 * This function is to get class member "inputFile".
149 *
150 * @return string of input file name.
151 */
152 public String getInputFile() {
153 return inputFile;
154 }
155
156 /**
157 * setComponentType
158 *
159 * This function is to set class member "inputFile".
160 *
161 * @param inputFile
162 * string of input file name.
163 */
164 public void setInputFile(String inputFile) {
165 this.inputFile = inputFile;
166 }
167
168 /**
169 * getOutputFile
170 *
171 * This function is to get class member "outputFile"
172 *
173 * @return outputFile string of output file name.
174 */
175 public String getOutputFile() {
176 return outputFile;
177 }
178
179 /**
180 * setOutputFile
181 *
182 * This function is to set class member "outputFile"
183 *
184 * @param outputFile
185 * string of output file name.
186 */
187 public void setOutputFile(String outputFile) {
188 this.outputFile = outputFile + " ";
189 }
190
191 /**
192 * getOutputDir
193 *
194 * This function is to get class member "outputDir"
195 *
196 * @return outputDir string of output directory.
197 */
198 public String getOutputDir() {
199 return outputDir;
200 }
201
202 /**
203 * setOutputDir
204 *
205 * This function is to set class member "outputDir"
206 *
207 * @param outputDir
208 * string of output directory.
209 */
210 public void setOutputDir(String outputDir) {
211 this.outputDir = outputDir;
212 }
213
214 /**
215 * getVerbose
216 *
217 * This function is to get class member "verbose"
218 *
219 * @return verbose the flag of verbose.
220 */
221 public String getVerbose() {
222 return this.verbose;
223 }
224
225 /**
226 * setVerbose
227 *
228 * This function is to set class member "verbose"
229 *
230 * @param verbose
231 * True or False.
232 */
233 public void setVerbose(boolean verbose) {
234 if (verbose) {
235 this.verbose = "-v ";
236 }
237 }
238
239 /**
240 * getDump
241 *
242 * This function is to get class member "dump"
243 *
244 * @return verbose the flag of dump.
245 */
246 public String getDump() {
247 return dump;
248 }
249
250 /**
251 * setDump
252 *
253 * This function is to set class member "dump"
254 *
255 * @param dump
256 * True or False.
257 */
258 public void setDump(boolean dump) {
259 if (dump) {
260 this.dump = "-dump ";
261 }
262 }
263 }