]>
Commit | Line | Data |
---|---|---|
a15bb0d3 | 1 | /** @file\r |
2 | EfiCompressTask class.\r | |
3 | \r | |
4 | EfiCompressTask is used to call EfiCompress.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 | EfiCompressTask class.\r | |
32 | \r | |
33 | EfiCompressTask is used to call EfiCompress.exe to strip input file.\r | |
34 | **/\r | |
35 | public class EfiCompressTask 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 | |
51 | /**\r | |
52 | * execute\r | |
ff225cbb | 53 | *\r |
a15bb0d3 | 54 | * EfiCompressTask execute function is to assemble tool command line & execute\r |
55 | * tool command line\r | |
ff225cbb | 56 | *\r |
a15bb0d3 | 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 | |
65 | FrameworkLogger logger = new FrameworkLogger(project, "eficompress");\r | |
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 | |
75 | command = "EfiCompress";\r | |
76 | } else {\r | |
77 | command = path + File.separatorChar + "EfiCompress";\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 | |
ff225cbb | 110 | \r |
a15bb0d3 | 111 | revl = runner.execute();\r |
ff225cbb | 112 | \r |
a15bb0d3 | 113 | if (EFI_SUCCESS == revl) {\r |
114 | //\r | |
115 | // command execution success\r | |
116 | //\r | |
219e2247 | 117 | EdkLog.log(EdkLog.EDK_VERBOSE, "EfiCompress 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 |
3f7b510e | 123 | throw new BuildException("EfiCompress failed!");\r |
a15bb0d3 | 124 | \r |
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 |