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