]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java
7e67fdabc865d25ced839ce05c9b8bbd0b93c320
[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, "modifyinftask");
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_VERBOSE, Commandline.toString(cmdline.getCommandline()));
123 EdkLog.log(EdkLog.EDK_INFO, (new File(this.inputFVInfFileName)).getName());
124 revl = runner.execute();
125
126 if (EFI_SUCCESS == revl) {
127 //
128 // command execution success
129 //
130 EdkLog.log(EdkLog.EDK_VERBOSE, "ModifyInfTask succeeded!");
131 } else {
132 //
133 // command execution fail
134 //
135 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
136 throw new BuildException("ModifyInfTask failed!");
137 }
138 } catch (Exception e) {
139 throw new BuildException(e.getMessage());
140 }
141 }
142
143 /**
144 * getinputFVInfFileName
145 *
146 * This function is to get class member "inputFVInfFileName".
147 *
148 * @return string of input inf file name.
149 */
150 public String getinputFVInfFileName() {
151 return this.inputFVInfFileName;
152 }
153
154 /**
155 * setinputFVInfFileName
156 *
157 * This function is to set class member "inputFVInfFileName".
158 *
159 * @param inputFile
160 * string of input inf file name.
161 */
162 public void setinputFVInfFileName(String inputFVInfFileName) {
163 this.inputFVInfFileName = inputFVInfFileName + " ";
164 }
165
166 /**
167 * getoutputFVInfFileName
168 *
169 * This function is to get class member "outputFVInfFileName"
170 *
171 * @return outputFVInfFileName string of output inf file name.
172 */
173 public String getoutputFVInfFileName() {
174 return this.outputFVInfFileName;
175 }
176
177 /**
178 * setoutputFVInfFileName
179 *
180 * This function is to set class member "outputFVInfFileName"
181 *
182 * @param outputFVInfFileName
183 * string of output inf file name.
184 */
185 public void setoutputFVInfFileName(String outputFVInfFileName) {
186 this.outputFVInfFileName = outputFVInfFileName + " ";
187 }
188
189 /**
190 * getpatternStr
191 *
192 * This function is to get class member "patternStr"
193 *
194 * @return patternStr string of pattern.
195 */
196 public String getpatternStr() {
197 return this.patternStr;
198 }
199
200 /**
201 * setpatternStr
202 *
203 * This function is to set class member "patternStr"
204 *
205 * @param patternStr
206 * string of patternStr.
207 */
208 public void setpatternStr(String patternStr) {
209 this.patternStr = patternStr;
210 }
211
212 /**
213 * getoutputDir
214 *
215 * This function is to get class member "outputDir"
216 *
217 * @return outputDir string of output directory.
218 */
219 public String getoutputDir() {
220 return this.outputDir;
221 }
222
223 /**
224 * setoutputDir
225 *
226 * This function is to set class member "outputDir"
227 *
228 * @param patternStr
229 * string of output directory.
230 */
231 public void setoutputDir(String outputDir) {
232 this.outputDir = outputDir;
233 }
234 }