]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CreateMtFileTask.java
bdc492c0dc7d54d92f8cbc7809bfd121752516fc
[mirror_edk2.git] / Tools / Java / 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 ToolArg fileSize = new ToolArg();
44
45 //
46 // output file
47 //
48 private FileArg outputFile = new FileArg();
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 //
68 // absolute path of efi tools
69 //
70 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
71 String command;
72 String argument;
73 if (path == null) {
74 command = toolName;
75 } else {
76 command = path + File.separator + toolName;
77 }
78 //
79 // argument of tools
80 //
81 argument = "" + outputFile + fileSize;
82 //
83 // return value of fwimage execution
84 //
85 int revl = -1;
86
87 try {
88 Commandline cmdline = new Commandline();
89 cmdline.setExecutable(command);
90 cmdline.createArgument().setLine(argument);
91
92 LogStreamHandler streamHandler = new LogStreamHandler(this,
93 Project.MSG_INFO, Project.MSG_WARN);
94 Execute runner = new Execute(streamHandler, null);
95
96 runner.setAntRun(project);
97 runner.setCommandline(cmdline.getCommandline());
98 runner.setWorkingDirectory(new File(outputDir));
99
100 //
101 // Set debug log information.
102 //
103 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
104 EdkLog.log(this, EdkLog.EDK_INFO, this.outputFile.toFileList());
105
106 revl = runner.execute();
107 if (EFI_SUCCESS == revl) {
108 //
109 // command execution success
110 //
111 EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
112 } else {
113 //
114 // command execution fail
115 //
116 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
117 throw new BuildException(toolName + " failed!");
118 }
119 } catch (Exception e) {
120 throw new BuildException(e.getMessage());
121 }
122 }
123
124 /**
125 getFileSize
126
127 This function is to get class member "fileSize".
128
129 @return fileSize string of file size.
130 **/
131 public String getFileSize() {
132 return this.fileSize.getValue();
133 }
134
135 /**
136 setFileSize
137
138 This function is to set class member "fileSize".
139
140 @param fileSize
141 string of file size value.
142 **/
143 public void setFileSize(String fileSize) {
144 this.fileSize.setArg(" ", fileSize);
145 }
146
147 /**
148 getOutputFile
149
150 This function is to get class member "outputFile"
151
152 @return outputFile string of output file name.
153 **/
154 public String getOutputFile() {
155 return outputFile.getValue();
156 }
157
158 /**
159 setOutputFile
160
161 This function is to set class member "outputFile"
162
163 @param outputFile
164 string of output file name.
165 **/
166 public void setOutputFile(String outputFile) {
167 this.outputFile.setArg(" ", outputFile);
168 }
169
170 /**
171 getOutputDir
172
173 This function is to get class member "outputDir"
174
175 @return outputDir string of output directory.
176 **/
177 public String getOutputDir() {
178 return outputDir;
179 }
180
181 /**
182 setOutputDir
183
184 This function is to set class member "outputDir"
185
186 @param outputDir
187 string of output directory.
188 **/
189 public void setOutputDir(String outputDir) {
190 this.outputDir = outputDir;
191 }
192 }