]>
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 | |
ff225cbb | 5 | \r |
6 | \r | |
a15bb0d3 | 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 | |
ff225cbb | 12 | \r |
a15bb0d3 | 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 | |
ff225cbb | 27 | \r |
28 | import org.tianocore.common.logger.EdkLog;\r | |
a15bb0d3 | 29 | \r |
30 | /**\r | |
31 | StripTask class.\r | |
32 | \r | |
33 | StripTask is used to call Strip.exe to strip input file.\r | |
34 | */\r | |
35 | public class StripTask extends Task implements EfiDefine {\r | |
36 | // /\r | |
37 | // / input file\r | |
38 | // /\r | |
39 | private String inputFile = "";\r | |
40 | \r | |
41 | // /\r | |
42 | // / output file\r | |
43 | // /\r | |
44 | private String outputFile = "";\r | |
45 | \r | |
46 | // /\r | |
47 | // / output directory, this variable is added by jave wrap\r | |
48 | // /\r | |
49 | private String outputDir = "";\r | |
50 | \r | |
ff225cbb | 51 | \r |
a15bb0d3 | 52 | /**\r |
53 | * execute\r | |
ff225cbb | 54 | *\r |
a15bb0d3 | 55 | * StripTask execute function is to assemble tool command line & execute\r |
56 | * tool command line\r | |
ff225cbb | 57 | *\r |
a15bb0d3 | 58 | * @throws BuidException\r |
59 | */\r | |
60 | public void execute() throws BuildException {\r | |
61 | \r | |
62 | Project project = this.getOwningTarget().getProject();\r | |
63 | //\r | |
64 | // set Logger\r | |
65 | //\r | |
3f7b510e | 66 | FrameworkLogger logger = new FrameworkLogger(project, "strip");\r |
a15bb0d3 | 67 | EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r |
68 | EdkLog.setLogger(logger);\r | |
69 | //\r | |
70 | // absolute path of efi tools\r | |
71 | //\r | |
72 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
73 | String command;\r | |
74 | String argument;\r | |
75 | if (path == null) {\r | |
3f7b510e | 76 | command = "Strip";\r |
a15bb0d3 | 77 | } else {\r |
78 | command = path + File.separatorChar + "Strip";\r | |
79 | }\r | |
80 | //\r | |
81 | // argument of tools\r | |
82 | //\r | |
83 | File file = new File(outputFile);\r | |
84 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
85 | argument = inputFile + " " + outputDir + File.separatorChar\r | |
86 | + outputFile;\r | |
87 | } else {\r | |
88 | argument = inputFile + " " + outputFile;\r | |
89 | }\r | |
90 | //\r | |
91 | // return value of fwimage execution\r | |
92 | //\r | |
93 | int revl = -1;\r | |
94 | \r | |
95 | try {\r | |
96 | Commandline cmdline = new Commandline();\r | |
97 | cmdline.setExecutable(command);\r | |
98 | cmdline.createArgument().setLine(argument);\r | |
99 | \r | |
100 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
101 | Project.MSG_INFO, Project.MSG_WARN);\r | |
102 | Execute runner = new Execute(streamHandler, null);\r | |
103 | \r | |
104 | runner.setAntRun(project);\r | |
105 | runner.setCommandline(cmdline.getCommandline());\r | |
106 | //\r | |
107 | // Set debug log information.\r | |
108 | //\r | |
219e2247 | 109 | EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r |
110 | EdkLog.log(EdkLog.EDK_INFO, (new File(this.inputFile)).getName());\r | |
ff225cbb | 111 | \r |
a15bb0d3 | 112 | revl = runner.execute();\r |
ff225cbb | 113 | \r |
a15bb0d3 | 114 | if (EFI_SUCCESS == revl) {\r |
115 | //\r | |
116 | // command execution success\r | |
117 | //\r | |
219e2247 | 118 | EdkLog.log(EdkLog.EDK_VERBOSE, "Strip succeeded!");\r |
a15bb0d3 | 119 | } else {\r |
120 | //\r | |
121 | // command execution fail\r | |
122 | //\r | |
219e2247 | 123 | EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r |
124 | throw new BuildException("Strip failed!");\r | |
a15bb0d3 | 125 | }\r |
126 | } catch (Exception e) {\r | |
127 | throw new BuildException(e.getMessage());\r | |
128 | }\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | * getInputFile\r | |
ff225cbb | 133 | *\r |
a15bb0d3 | 134 | * This function is to get class member "inputFile".\r |
ff225cbb | 135 | *\r |
a15bb0d3 | 136 | * @return string of input file name.\r |
137 | */\r | |
138 | public String getInputFile() {\r | |
139 | return inputFile;\r | |
140 | }\r | |
141 | \r | |
142 | /**\r | |
143 | * setComponentType\r | |
ff225cbb | 144 | *\r |
a15bb0d3 | 145 | * This function is to set class member "inputFile".\r |
ff225cbb | 146 | *\r |
a15bb0d3 | 147 | * @param inputFile\r |
148 | * string of input file name.\r | |
149 | */\r | |
150 | public void setInputFile(String inputFile) {\r | |
151 | this.inputFile = inputFile;\r | |
152 | }\r | |
153 | \r | |
154 | /**\r | |
155 | * getOutputFile\r | |
ff225cbb | 156 | *\r |
a15bb0d3 | 157 | * This function is to get class member "outputFile"\r |
ff225cbb | 158 | *\r |
a15bb0d3 | 159 | * @return outputFile string of output file name.\r |
160 | */\r | |
161 | public String getOutputFile() {\r | |
162 | return outputFile;\r | |
163 | }\r | |
164 | \r | |
165 | /**\r | |
166 | * setOutputFile\r | |
ff225cbb | 167 | *\r |
a15bb0d3 | 168 | * This function is to set class member "outputFile"\r |
ff225cbb | 169 | *\r |
a15bb0d3 | 170 | * @param outputFile\r |
171 | * string of output file name.\r | |
172 | */\r | |
173 | public void setOutputFile(String outputFile) {\r | |
174 | this.outputFile = outputFile;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | * getOutputDir\r | |
ff225cbb | 179 | *\r |
a15bb0d3 | 180 | * This function is to get class member "outputDir"\r |
ff225cbb | 181 | *\r |
a15bb0d3 | 182 | * @return outputDir string of output directory.\r |
183 | */\r | |
184 | public String getOutputDir() {\r | |
185 | return outputDir;\r | |
186 | }\r | |
187 | \r | |
188 | /**\r | |
189 | * setOutputDir\r | |
ff225cbb | 190 | *\r |
a15bb0d3 | 191 | * This function is to set class member "outputDir"\r |
ff225cbb | 192 | *\r |
a15bb0d3 | 193 | * @param outputDir\r |
194 | * string of output directory.\r | |
195 | */\r | |
196 | public void setOutputDir(String outputDir) {\r | |
197 | this.outputDir = outputDir;\r | |
198 | }\r | |
199 | }\r |