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