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