]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SecFixupTask.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / SecFixupTask.java
1 /** @file
2 SecFixupTask class.
3
4 SecFixupTask is used to call SecFixup.exe to fix up sec image.
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 * SecFixupTask class.
32 *
33 * SecFixupTask is used to call SecFixup.exe to fix up sec image.
34 */
35 public class SecFixupTask extends Task implements EfiDefine {
36 //
37 // tool name
38 //
39 private String toolName = "SecFixup";
40
41 //
42 // input file
43 //
44 private FileArg secExeFile = new FileArg();
45
46 //
47 // output file
48 //
49 private FileArg resetVectorDataFile = new FileArg();
50
51 //
52 // output file
53 //
54 private FileArg outputFile = new FileArg();
55
56 //
57 // output directory, this variable is added by jave wrap
58 //
59 private String outputDir = ".";
60
61 /**
62 execute
63
64 SecFixupTask execute function is to assemble tool command line & execute
65 tool command line
66
67 @throws BuidException
68 **/
69 public void execute() throws BuildException {
70
71 Project project = this.getOwningTarget().getProject();
72
73 //
74 // absolute path of efi tools
75 //
76 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
77 String command;
78 String argument;
79 if (path == null) {
80 command = toolName;
81 } else {
82 command = path + File.separatorChar + toolName;
83 }
84 //
85 // argument of tools
86 //
87 argument = "" + secExeFile + resetVectorDataFile + outputFile;
88
89 //
90 // return value of fwimage execution
91 //
92 int revl = -1;
93
94 try {
95 Commandline cmdline = new Commandline();
96 cmdline.setExecutable(command);
97 cmdline.createArgument().setLine(argument);
98
99 LogStreamHandler streamHandler = new LogStreamHandler(this,
100 Project.MSG_INFO, Project.MSG_WARN);
101 Execute runner = new Execute(streamHandler, null);
102
103 runner.setAntRun(project);
104 runner.setCommandline(cmdline.getCommandline());
105 runner.setWorkingDirectory(new File(outputDir));
106
107 //
108 // Set debug log information.
109 //
110 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
111 EdkLog.log(this, EdkLog.EDK_INFO, secExeFile.toFileList()
112 + resetVectorDataFile.toFileList() + " => " + outputFile.toFileList());
113
114 revl = runner.execute();
115
116 if (EFI_SUCCESS == revl) {
117 //
118 // command execution success
119 //
120 EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
121 } else {
122 //
123 // command execution fail
124 //
125 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = "+ Integer.toHexString(revl));
126 throw new BuildException(toolName + " failed!");
127 }
128 } catch (Exception e) {
129 throw new BuildException(e.getMessage());
130 }
131 }
132
133 /**
134 getSecExeFile
135
136 This function is to get class member "secExeFile".
137
138 @return string of sectExe file name.
139 **/
140 public String getSecExeFile() {
141 return this.secExeFile.getValue();
142 }
143
144 /**
145 setSecExeFile
146
147 This function is to set class member "secExeFile".
148
149 @param secExeFile
150 string of secExe file name.
151 **/
152 public void setSecExeFile(String secExeFile) {
153 this.secExeFile.setArg(" ", secExeFile);
154 }
155
156 /**
157 getResetVectorDataFile
158
159 This function is to get class member "resetVectorDataFile"
160
161 @return resetVectorDataFile string of resetVectorData file name.
162 **/
163 public String getResetVectorDataFile() {
164 return this.resetVectorDataFile.getValue();
165 }
166
167 /**
168 setResetVectorDataFile
169
170 This function is to set class member "resetVectorDataFile"
171
172 @param resetVectorDataFile
173 string of resetVectorData file name.
174 **/
175 public void setResetVectorDataFile(String resetVectorDataFile) {
176 this.resetVectorDataFile.setArg(" ", resetVectorDataFile);
177 }
178
179 /**
180 getOutputFile
181
182 This function is to get class member "outputFile"
183
184 @return outputFile string of output file name.
185 **/
186 public String getOutputFile() {
187 return this.outputFile.getValue();
188 }
189
190 /**
191 setOutputFile
192
193 This function is to set class member "outputFile"
194
195 @param outputFile
196 string of output file name.
197 **/
198 public void setOutputFile(String outputFile) {
199 this.outputFile.setArg(" ", outputFile);
200 }
201
202 /**
203 getOutputDir
204
205 This function is to get class member "outputDir"
206
207 @return outputDir name of output directory
208 **/
209 public String getOutputDir() {
210 return outputDir;
211 }
212
213 /**
214 setOutputDir
215
216 This function is to set class member "outputDir"
217
218 @param outputDir
219 name of output directory
220 **/
221 public void setOutputDir(String outputDir) {
222 this.outputDir = outputDir;
223 }
224 }