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