]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java
e01b0404a8a6363ad2fd092c4ecfc1a09416cea7
[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 inputFVInfFile = "";
45
46 ///
47 /// output FV inf file
48 ///
49 private String outputFVInfFile = "";
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 // absolute path of efi tools
74 //
75 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
76 String command;
77 String argument;
78 if (path == null) {
79 command = toolName;
80 } else {
81 command = path + File.separatorChar + toolName;
82 }
83 //
84 // argument of tools
85 //
86 File file = new File(outputFVInfFile);
87 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
88 argument = this.inputFVInfFile +
89 this.outputDir +
90 File.separatorChar +
91 this.outputFVInfFile +
92 this.patternStr;
93 } else {
94 argument = this.inputFVInfFile +
95 this.outputFVInfFile +
96 this.patternStr;
97 }
98 //
99 // return value of fwimage execution
100 //
101 int revl = -1;
102
103 try {
104 Commandline cmdline = new Commandline();
105 cmdline.setExecutable(command);
106 cmdline.createArgument().setLine(argument);
107
108 LogStreamHandler streamHandler = new LogStreamHandler(this,
109 Project.MSG_INFO, Project.MSG_WARN);
110 Execute runner = new Execute(streamHandler, null);
111
112 runner.setAntRun(project);
113 runner.setCommandline(cmdline.getCommandline());
114 //
115 // Set debug log information.
116 //
117 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
118 EdkLog.log(this, EdkLog.EDK_INFO, (new File(this.inputFVInfFile)).getName());
119 revl = runner.execute();
120
121 if (EFI_SUCCESS == revl) {
122 //
123 // command execution success
124 //
125 EdkLog.log(this, EdkLog.EDK_VERBOSE, "ModifyInfTask succeeded!");
126 } else {
127 //
128 // command execution fail
129 //
130 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
131 throw new BuildException("ModifyInfTask failed!");
132 }
133 } catch (Exception e) {
134 throw new BuildException(e.getMessage());
135 }
136 }
137
138 /**
139 * getinputFVInfFile
140 *
141 * This function is to get class member "inputFVInfFile".
142 *
143 * @return string of input inf file name.
144 */
145 public String getinputFVInfFile() {
146 return this.inputFVInfFile;
147 }
148
149 /**
150 * setinputFVInfFile
151 *
152 * This function is to set class member "inputFVInfFile".
153 *
154 * @param inputFile
155 * string of input inf file name.
156 */
157 public void setinputFVInfFile(String inputFVInfFileName) {
158 this.inputFVInfFile= inputFVInfFileName + " ";
159 }
160
161 /**
162 * getoutputFVInfFile
163 *
164 * This function is to get class member "outputFVInfFile"
165 *
166 * @return outputFVInfFile string of output inf file name.
167 */
168 public String getoutputFVInfFile() {
169 return this.outputFVInfFile;
170 }
171
172 /**
173 * setoutputFVInfFile
174 *
175 * This function is to set class member "outputFVInfFile"
176 *
177 * @param outputFVInfFile
178 * string of output inf file name.
179 */
180 public void setoutputFVInfFile(String outputFVInfFileName) {
181 this.outputFVInfFile = outputFVInfFileName + " ";
182 }
183
184 /**
185 * getpatternStr
186 *
187 * This function is to get class member "patternStr"
188 *
189 * @return patternStr string of pattern.
190 */
191 public String getpatternStr() {
192 return this.patternStr;
193 }
194
195 /**
196 * setpatternStr
197 *
198 * This function is to set class member "patternStr"
199 *
200 * @param patternStr
201 * string of patternStr.
202 */
203 public void setpatternStr(String patternStr) {
204 this.patternStr = patternStr;
205 }
206
207 /**
208 * getoutputDir
209 *
210 * This function is to get class member "outputDir"
211 *
212 * @return outputDir string of output directory.
213 */
214 public String getoutputDir() {
215 return this.outputDir;
216 }
217
218 /**
219 * setoutputDir
220 *
221 * This function is to set class member "outputDir"
222 *
223 * @param patternStr
224 * string of output directory.
225 */
226 public void setoutputDir(String outputDir) {
227 this.outputDir = outputDir;
228 }
229 }