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