]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java
Fixed EDKT102;
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / ModifyInfTask.java
1 /** @file
2 ModifyInfTask class.
3
4 ModifyInfTask is used to call Modify.exe to generate inf 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 import org.tianocore.logger.EdkLog;
28
29 /**
30 ModifyInfTask class.
31
32 ModifyInfTask is used to call Modify.exe to generate inf file.
33 **/
34 public class ModifyInfTask extends Task implements EfiDefine {
35 ///
36 /// tool name
37 ///
38 private String toolName = "ModifyInf";
39
40 ///
41 /// input FV inf file
42 ///
43 private String inputFVInfFileName = "";
44
45 ///
46 /// output FV inf file
47 ///
48 private String outputFVInfFileName = "";
49
50 ///
51 /// pattern string
52 ///
53 private String patternStr = "";
54
55 ///
56 /// Output dir
57 ///
58 private String outputDir = "";
59
60 /**
61 * execute
62 *
63 * ModifyInfTask execute function is to assemble tool command line & execute
64 * tool command line
65 *
66 * @throws BuidException
67 */
68 public void execute() throws BuildException {
69
70 Project project = this.getOwningTarget().getProject();
71 //
72 // set Logger
73 //
74 FrameworkLogger logger = new FrameworkLogger(project, "modifytask");
75 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
76 EdkLog.setLogger(logger);
77 //
78 // absolute path of efi tools
79 //
80 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
81 String command;
82 String argument;
83 if (path == null) {
84 command = toolName;
85 } else {
86 command = path + File.separatorChar + toolName;
87 }
88 //
89 // argument of tools
90 //
91 File file = new File(outputFVInfFileName);
92 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
93 argument = this.inputFVInfFileName +
94 this.outputDir +
95 File.separatorChar +
96 this.outputFVInfFileName +
97 this.patternStr;
98 } else {
99 argument = this.inputFVInfFileName +
100 this.outputFVInfFileName +
101 this.patternStr;
102 }
103 //
104 // return value of fwimage execution
105 //
106 int revl = -1;
107
108 try {
109 Commandline cmdline = new Commandline();
110 cmdline.setExecutable(command);
111 cmdline.createArgument().setLine(argument);
112
113 LogStreamHandler streamHandler = new LogStreamHandler(this,
114 Project.MSG_INFO, Project.MSG_WARN);
115 Execute runner = new Execute(streamHandler, null);
116
117 runner.setAntRun(project);
118 runner.setCommandline(cmdline.getCommandline());
119 //
120 // Set debug log information.
121 //
122 EdkLog.log(EdkLog.EDK_INFO, Commandline.toString(cmdline
123 .getCommandline()));
124
125 revl = runner.execute();
126
127 if (EFI_SUCCESS == revl) {
128 //
129 // command execution success
130 //
131 EdkLog.log(EdkLog.EDK_INFO, "ModifyInfTask succeeded!");
132 } else {
133 //
134 // command execution fail
135 //
136 EdkLog.log(EdkLog.EDK_ERROR, "ModifyInfTask failed. (error="
137 + Integer.toHexString(revl) + ")");
138 throw new BuildException("ModifyInfTask failed. (error="
139 + Integer.toHexString(revl) + ")");
140
141 }
142 } catch (Exception e) {
143 throw new BuildException(e.getMessage());
144 }
145 }
146
147 /**
148 * getinputFVInfFileName
149 *
150 * This function is to get class member "inputFVInfFileName".
151 *
152 * @return string of input inf file name.
153 */
154 public String getinputFVInfFileName() {
155 return this.inputFVInfFileName;
156 }
157
158 /**
159 * setinputFVInfFileName
160 *
161 * This function is to set class member "inputFVInfFileName".
162 *
163 * @param inputFile
164 * string of input inf file name.
165 */
166 public void setinputFVInfFileName(String inputFVInfFileName) {
167 this.inputFVInfFileName = inputFVInfFileName + " ";
168 }
169
170 /**
171 * getoutputFVInfFileName
172 *
173 * This function is to get class member "outputFVInfFileName"
174 *
175 * @return outputFVInfFileName string of output inf file name.
176 */
177 public String getoutputFVInfFileName() {
178 return this.outputFVInfFileName;
179 }
180
181 /**
182 * setoutputFVInfFileName
183 *
184 * This function is to set class member "outputFVInfFileName"
185 *
186 * @param outputFVInfFileName
187 * string of output inf file name.
188 */
189 public void setoutputFVInfFileName(String outputFVInfFileName) {
190 this.outputFVInfFileName = outputFVInfFileName + " ";
191 }
192
193 /**
194 * getpatternStr
195 *
196 * This function is to get class member "patternStr"
197 *
198 * @return patternStr string of pattern.
199 */
200 public String getpatternStr() {
201 return this.patternStr;
202 }
203
204 /**
205 * setpatternStr
206 *
207 * This function is to set class member "patternStr"
208 *
209 * @param patternStr
210 * string of patternStr.
211 */
212 public void setpatternStr(String patternStr) {
213 this.patternStr = patternStr;
214 }
215
216 /**
217 * getoutputDir
218 *
219 * This function is to get class member "outputDir"
220 *
221 * @return outputDir string of output directory.
222 */
223 public String getoutputDir() {
224 return this.outputDir;
225 }
226
227 /**
228 * setoutputDir
229 *
230 * This function is to set class member "outputDir"
231 *
232 * @param patternStr
233 * string of output directory.
234 */
235 public void setoutputDir(String outputDir) {
236 this.outputDir = outputDir;
237 }
238 }