]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CreateMtFileTask.java
Updated PeiRebase to produce a map file of the relocations done by this tool. This...
[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_VERBOSE, Commandline.toString(cmdline.getCommandline()));
112 EdkLog.log(EdkLog.EDK_INFO, (new File(this.outputFile)).getName());
113 revl = runner.execute();
114
115 if (EFI_SUCCESS == revl) {
116 //
117 // command execution success
118 //
119 EdkLog.log(EdkLog.EDK_VERBOSE, "CreateMtFile succeeded!");
120 } else {
121 //
122 // command execution fail
123 //
124 EdkLog.log(EdkLog.EDK_INFO, "ERROR = "+ Integer.toHexString(revl));
125 throw new BuildException("CreateMtFile failed!");
126 }
127 } catch (Exception e) {
128 throw new BuildException(e.getMessage());
129 }
130 }
131
132 /**
133 * getFileSize
134 *
135 * This function is to get class member "fileSize".
136 *
137 * @return fileSize string of file size.
138 */
139 public String getFileSize() {
140 return this.fileSize;
141 }
142
143 /**
144 * setFileSize
145 *
146 * This function is to set class member "fileSize".
147 *
148 * @param fileSize
149 * string of file size value.
150 */
151 public void setFileSize(String fileSize) {
152 this.fileSize = fileSize;
153 }
154
155 /**
156 * getOutputFile
157 *
158 * This function is to get class member "outputFile"
159 *
160 * @return outputFile string of output file name.
161 */
162 public String getOutputFile() {
163 return outputFile;
164 }
165
166 /**
167 * setOutputFile
168 *
169 * This function is to set class member "outputFile"
170 *
171 * @param outputFile
172 * string of output file name.
173 */
174 public void setOutputFile(String outputFile) {
175 this.outputFile = outputFile;
176 }
177
178 /**
179 * getOutputDir
180 *
181 * This function is to get class member "outputDir"
182 *
183 * @return outputDir string of output directory.
184 */
185 public String getOutputDir() {
186 return outputDir;
187 }
188
189 /**
190 * setOutputDir
191 *
192 * This function is to set class member "outputDir"
193 *
194 * @param outputDir
195 * string of output directory.
196 */
197 public void setOutputDir(String outputDir) {
198 this.outputDir = outputDir;
199 }
200 }