]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CreateMtFileTask.java
Fixed EDKT102;
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / CreateMtFileTask.java
CommitLineData
a15bb0d3 1/** @file\r
2 CreateMtFileTask class.\r
3\r
4 CreateMtFileTask is used to call CreateMtFile.exe to create MT file.\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 CreateMtFileTask class.\r
31\r
32 CreateMtFileTask is used to call CreateMtFile.exe to create MT file.\r
33**/\r
34public class CreateMtFileTask extends Task implements EfiDefine {\r
35 ///\r
36 /// Tool name\r
37 ///\r
38 private String toolName="CreateMtFile";\r
39 ///\r
40 /// file size\r
41 ///\r
42 private String fileSize = "";\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 * execute\r
56 * \r
57 * StripTask execute function is to assemble tool command line & execute\r
58 * tool command line\r
59 * \r
60 * @throws BuidException\r
61 */\r
62 public void execute() throws BuildException {\r
63\r
64 Project project = this.getOwningTarget().getProject();\r
65 //\r
66 // set Logger\r
67 //\r
68 FrameworkLogger logger = new FrameworkLogger(project, "createmtfile");\r
69 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r
70 EdkLog.setLogger(logger);\r
71 //\r
72 // absolute path of efi tools\r
73 //\r
74 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
75 String command;\r
76 String argument;\r
77 if (path == null) {\r
78 command = toolName;\r
79 } else {\r
80 command = path + File.separatorChar + toolName;\r
81 }\r
82 //\r
83 // argument of tools\r
84 //\r
85 File file = new File(outputFile);\r
86 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r
87 argument = outputDir + File.separatorChar + outputFile + " " + this.fileSize;\r
88 \r
89 } else {\r
90 argument = outputFile + " " + this.fileSize;\r
91 }\r
92 //\r
93 // return value of fwimage execution\r
94 //\r
95 int revl = -1;\r
96\r
97 try {\r
98 Commandline cmdline = new Commandline();\r
99 cmdline.setExecutable(command);\r
100 cmdline.createArgument().setLine(argument);\r
101\r
102 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
103 Project.MSG_INFO, Project.MSG_WARN);\r
104 Execute runner = new Execute(streamHandler, null);\r
105\r
106 runner.setAntRun(project);\r
107 runner.setCommandline(cmdline.getCommandline());\r
108 //\r
109 // Set debug log information.\r
110 //\r
111 EdkLog.log(EdkLog.EDK_INFO, Commandline.toString(cmdline.getCommandline()));\r
112 \r
113 revl = runner.execute();\r
114 \r
115 if (EFI_SUCCESS == revl) {\r
116 //\r
117 // command execution success\r
118 //\r
119 EdkLog.log(EdkLog.EDK_INFO,"CreateMtFile succeeded!");\r
120 } else {\r
121 //\r
122 // command execution fail\r
123 //\r
124 EdkLog.log(EdkLog.EDK_ERROR, "CreateMtFile failed. (error="\r
125 + Integer.toHexString(revl) + ")");\r
126 throw new BuildException("CreateMtFile failed. (error="\r
127 + Integer.toHexString(revl) + ")");\r
128\r
129 }\r
130 } catch (Exception e) {\r
131 throw new BuildException(e.getMessage());\r
132 }\r
133 }\r
134\r
135 /**\r
136 * getFileSize\r
137 * \r
138 * This function is to get class member "fileSize".\r
139 * \r
140 * @return fileSize string of file size.\r
141 */\r
142 public String getFileSize() {\r
143 return this.fileSize;\r
144 }\r
145\r
146 /**\r
147 * setFileSize\r
148 * \r
149 * This function is to set class member "fileSize".\r
150 * \r
151 * @param fileSize\r
152 * string of file size value.\r
153 */\r
154 public void setFileSize(String fileSize) {\r
155 this.fileSize = fileSize;\r
156 }\r
157\r
158 /**\r
159 * getOutputFile\r
160 * \r
161 * This function is to get class member "outputFile"\r
162 * \r
163 * @return outputFile string of output file name.\r
164 */\r
165 public String getOutputFile() {\r
166 return outputFile;\r
167 }\r
168\r
169 /**\r
170 * setOutputFile\r
171 * \r
172 * This function is to set class member "outputFile"\r
173 * \r
174 * @param outputFile\r
175 * string of output file name.\r
176 */\r
177 public void setOutputFile(String outputFile) {\r
178 this.outputFile = outputFile;\r
179 }\r
180\r
181 /**\r
182 * getOutputDir\r
183 * \r
184 * This function is to get class member "outputDir"\r
185 * \r
186 * @return outputDir string of output directory.\r
187 */\r
188 public String getOutputDir() {\r
189 return outputDir;\r
190 }\r
191\r
192 /**\r
193 * setOutputDir\r
194 * \r
195 * This function is to set class member "outputDir"\r
196 * \r
197 * @param outputDir\r
198 * string of output directory.\r
199 */\r
200 public void setOutputDir(String outputDir) {\r
201 this.outputDir = outputDir;\r
202 }\r
203}\r