]>
Commit | Line | Data |
---|---|---|
a15bb0d3 | 1 | /** @file\r |
2 | StripTask class.\r | |
3 | \r | |
4 | StripTask is used to call Strip.exe to strip input file.\r | |
5 | \r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import java.io.File;\r | |
20 | \r | |
21 | import org.apache.tools.ant.Task;\r | |
22 | import org.apache.tools.ant.Project;\r | |
23 | import org.apache.tools.ant.BuildException;\r | |
24 | import org.apache.tools.ant.taskdefs.Execute;\r | |
25 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
26 | import org.apache.tools.ant.types.Commandline;\r | |
27 | import org.tianocore.logger.EdkLog;\r | |
28 | \r | |
29 | /**\r | |
30 | StripTask class.\r | |
31 | \r | |
32 | StripTask is used to call Strip.exe to strip input file.\r | |
33 | */\r | |
34 | public class StripTask extends Task implements EfiDefine {\r | |
35 | // /\r | |
36 | // / input file\r | |
37 | // /\r | |
38 | private String inputFile = "";\r | |
39 | \r | |
40 | // /\r | |
41 | // / output file\r | |
42 | // /\r | |
43 | private String outputFile = "";\r | |
44 | \r | |
45 | // /\r | |
46 | // / output directory, this variable is added by jave wrap\r | |
47 | // /\r | |
48 | private String outputDir = "";\r | |
49 | \r | |
50 | \r | |
51 | /**\r | |
52 | * execute\r | |
53 | * \r | |
54 | * StripTask execute function is to assemble tool command line & execute\r | |
55 | * tool command line\r | |
56 | * \r | |
57 | * @throws BuidException\r | |
58 | */\r | |
59 | public void execute() throws BuildException {\r | |
60 | \r | |
61 | Project project = this.getOwningTarget().getProject();\r | |
62 | //\r | |
63 | // set Logger\r | |
64 | //\r | |
3f7b510e | 65 | FrameworkLogger logger = new FrameworkLogger(project, "strip");\r |
a15bb0d3 | 66 | EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r |
67 | EdkLog.setLogger(logger);\r | |
68 | //\r | |
69 | // absolute path of efi tools\r | |
70 | //\r | |
71 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
72 | String command;\r | |
73 | String argument;\r | |
74 | if (path == null) {\r | |
3f7b510e | 75 | command = "Strip";\r |
a15bb0d3 | 76 | } else {\r |
77 | command = path + File.separatorChar + "Strip";\r | |
78 | }\r | |
79 | //\r | |
80 | // argument of tools\r | |
81 | //\r | |
82 | File file = new File(outputFile);\r | |
83 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
84 | argument = inputFile + " " + outputDir + File.separatorChar\r | |
85 | + outputFile;\r | |
86 | } else {\r | |
87 | argument = inputFile + " " + outputFile;\r | |
88 | }\r | |
89 | //\r | |
90 | // return value of fwimage execution\r | |
91 | //\r | |
92 | int revl = -1;\r | |
93 | \r | |
94 | try {\r | |
95 | Commandline cmdline = new Commandline();\r | |
96 | cmdline.setExecutable(command);\r | |
97 | cmdline.createArgument().setLine(argument);\r | |
98 | \r | |
99 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
100 | Project.MSG_INFO, Project.MSG_WARN);\r | |
101 | Execute runner = new Execute(streamHandler, null);\r | |
102 | \r | |
103 | runner.setAntRun(project);\r | |
104 | runner.setCommandline(cmdline.getCommandline());\r | |
105 | //\r | |
106 | // Set debug log information.\r | |
107 | //\r | |
219e2247 | 108 | EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r |
109 | EdkLog.log(EdkLog.EDK_INFO, (new File(this.inputFile)).getName());\r | |
a15bb0d3 | 110 | \r |
111 | revl = runner.execute();\r | |
112 | \r | |
113 | if (EFI_SUCCESS == revl) {\r | |
114 | //\r | |
115 | // command execution success\r | |
116 | //\r | |
219e2247 | 117 | EdkLog.log(EdkLog.EDK_VERBOSE, "Strip succeeded!");\r |
a15bb0d3 | 118 | } else {\r |
119 | //\r | |
120 | // command execution fail\r | |
121 | //\r | |
219e2247 | 122 | EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r |
123 | throw new BuildException("Strip failed!");\r | |
a15bb0d3 | 124 | }\r |
125 | } catch (Exception e) {\r | |
126 | throw new BuildException(e.getMessage());\r | |
127 | }\r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | * getInputFile\r | |
132 | * \r | |
133 | * This function is to get class member "inputFile".\r | |
134 | * \r | |
135 | * @return string of input file name.\r | |
136 | */\r | |
137 | public String getInputFile() {\r | |
138 | return inputFile;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | * setComponentType\r | |
143 | * \r | |
144 | * This function is to set class member "inputFile".\r | |
145 | * \r | |
146 | * @param inputFile\r | |
147 | * string of input file name.\r | |
148 | */\r | |
149 | public void setInputFile(String inputFile) {\r | |
150 | this.inputFile = inputFile;\r | |
151 | }\r | |
152 | \r | |
153 | /**\r | |
154 | * getOutputFile\r | |
155 | * \r | |
156 | * This function is to get class member "outputFile"\r | |
157 | * \r | |
158 | * @return outputFile string of output file name.\r | |
159 | */\r | |
160 | public String getOutputFile() {\r | |
161 | return outputFile;\r | |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | * setOutputFile\r | |
166 | * \r | |
167 | * This function is to set class member "outputFile"\r | |
168 | * \r | |
169 | * @param outputFile\r | |
170 | * string of output file name.\r | |
171 | */\r | |
172 | public void setOutputFile(String outputFile) {\r | |
173 | this.outputFile = outputFile;\r | |
174 | }\r | |
175 | \r | |
176 | /**\r | |
177 | * getOutputDir\r | |
178 | * \r | |
179 | * This function is to get class member "outputDir"\r | |
180 | * \r | |
181 | * @return outputDir string of output directory.\r | |
182 | */\r | |
183 | public String getOutputDir() {\r | |
184 | return outputDir;\r | |
185 | }\r | |
186 | \r | |
187 | /**\r | |
188 | * setOutputDir\r | |
189 | * \r | |
190 | * This function is to set class member "outputDir"\r | |
191 | * \r | |
192 | * @param outputDir\r | |
193 | * string of output directory.\r | |
194 | */\r | |
195 | public void setOutputDir(String outputDir) {\r | |
196 | this.outputDir = outputDir;\r | |
197 | }\r | |
198 | }\r |