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