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