]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ZeroDebugDataTask.java
ccba47d4a60b8f06cdb966dd56b974e094a10375
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / ZeroDebugDataTask.java
1 /** @file
2 ZeroDebugDataTask class.
3
4 ZeroDebugDataTask is used to call ZeroDebugData.exe to remove debug data.
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 ZeroDebugDataTask class.
32
33 ZeroDebugDataTask is used to call ZeroDebugData.exe to remove debug data.
34 **/
35 public class ZeroDebugDataTask extends Task implements EfiDefine {
36 // /
37 // / input PE file
38 // /
39 private String peFile = "";
40
41 // /
42 // / output file
43 // /
44 private String outputFile = "DebugData.dat";
45
46 // /
47 // / output directory, this variable is added by jave wrap
48 // /
49 private String outputDir = "";
50
51
52 /**
53 * execute
54 *
55 * ZeroDebugDataTask execute function is to assemble tool command line & execute
56 * tool command line
57 *
58 * @throws BuidException
59 */
60 public void execute() throws BuildException {
61
62 Project project = this.getOwningTarget().getProject();
63 //
64 // set Logger
65 //
66 FrameworkLogger logger = new FrameworkLogger(project, "zerodebugdata");
67 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
68 EdkLog.setLogger(logger);
69 //
70 // absolute path of efi tools
71 //
72 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
73 String command;
74 String argument;
75 if (path == null) {
76 command = "ZeroDebugData";
77 } else {
78 command = path + File.separatorChar + "ZeroDebugData";
79 }
80 //
81 // argument of tools
82 //
83 File file = new File(outputFile);
84 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
85 argument = this.peFile + " " + outputDir + File.separatorChar
86 + outputFile;
87 } else {
88 argument = this.peFile + " " + outputFile;
89 }
90 //
91 // return value of fwimage execution
92 //
93 int revl = -1;
94
95 try {
96 Commandline cmdline = new Commandline();
97 cmdline.setExecutable(command);
98 cmdline.createArgument().setLine(argument);
99
100 LogStreamHandler streamHandler = new LogStreamHandler(this,
101 Project.MSG_INFO, Project.MSG_WARN);
102 Execute runner = new Execute(streamHandler, null);
103
104 runner.setAntRun(project);
105 runner.setCommandline(cmdline.getCommandline());
106 //
107 // Set debug log information.
108 //
109 EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
110 EdkLog.log(EdkLog.EDK_INFO, (new File(this.peFile)).getName());
111
112 revl = runner.execute();
113
114 if (EFI_SUCCESS == revl) {
115 //
116 // command execution success
117 //
118 EdkLog.log(EdkLog.EDK_VERBOSE, "ZeroDebugData succeeded!");
119 } else {
120 //
121 // command execution fail
122 //
123 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
124 throw new BuildException("ZeroDebugData failed!");
125
126 }
127 } catch (Exception e) {
128 throw new BuildException(e.getMessage());
129 }
130 }
131
132 /**
133 * getPeFile
134 *
135 * This function is to get class member "inputFile".
136 *
137 * @return string of input file name.
138 */
139 public String getPeFile() {
140 return this.peFile;
141 }
142
143 /**
144 * setPeFile
145 *
146 * This function is to set class member "peFile".
147 *
148 * @param peFile
149 * string of input file name.
150 */
151 public void setPeFile(String peFile) {
152 this.peFile = peFile;
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 }