\r
**/\r
package org.tianocore.framework.tasks;\r
+import java.io.File;\r
\r
import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.Project;\r
import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
import org.apache.tools.ant.types.Commandline;\r
\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.lang.ProcessBuilder;\r
-import java.util.ArrayList;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
/**\r
GenFvImageTask\r
\r
\r
**/\r
public class GenFvImageTask extends Task implements EfiDefine{\r
- ///\r
- /// tool name\r
- ///\r
- static final private String toolName = "GenFvImage";\r
///\r
/// The name of input inf file\r
///\r
/// The target architecture.\r
///\r
private String arch="";\r
- ///\r
- /// Output directory\r
- ///\r
- private String outputDir = ".";\r
- ///\r
- /// argument list\r
- ///\r
- LinkedList<String> argList = new LinkedList<String>();\r
-\r
+ \r
/**\r
execute\r
\r
**/\r
public void execute() throws BuildException {\r
Project project = this.getOwningTarget().getProject();\r
- String path = project.getProperty("env.Framework_Tools_Path");\r
- if (path == null) {\r
+ String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
+ String command = "";\r
+ \r
+ if (path == null){\r
path = "";\r
- } else {\r
- path += File.separatorChar;\r
+ }else {\r
+ path = path + File.separatorChar;\r
}\r
-\r
- if (arch != null && arch.length() > 0) {\r
- argList.addFirst(path + toolName + "_" + arch);\r
- } else {\r
- argList.addFirst(path + toolName);\r
+ \r
+ if (arch.equalsIgnoreCase("")){\r
+ command = path + "GenFvImage";\r
}\r
-\r
- ///\r
- /// lauch the program\r
- ///\r
- ProcessBuilder pb = new ProcessBuilder(argList);\r
- pb.directory(new File(outputDir));\r
- int exitCode = 0;\r
+ if (arch.equalsIgnoreCase("ia32")){\r
+ command = path + "GenFvImage_IA32";\r
+ } \r
+ if (arch.equalsIgnoreCase("x64")){\r
+ command = path + "GenFvImage_X64";\r
+ }\r
+ if (arch.equalsIgnoreCase("ipf")){\r
+ command = path + "GenFvImage_IPF";\r
+ }\r
+ String argument = infFile;\r
+ \r
try {\r
- Process cmdProc = pb.start();\r
- InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());\r
- char[] buf = new char[1024];\r
-\r
- exitCode = cmdProc.waitFor();\r
- if (exitCode != 0) {\r
- int len = cmdOut.read(buf, 0, 1024);\r
- log(new String(buf, 0, len), Project.MSG_ERR);\r
+ \r
+ Commandline commandLine = new Commandline();\r
+ commandLine.setExecutable(command);\r
+ commandLine.createArgument().setLine(argument);\r
+ \r
+ LogStreamHandler streamHandler = new LogStreamHandler(this,\r
+ Project.MSG_INFO,\r
+ Project.MSG_WARN);\r
+ //\r
+ // create a execute object and set it's commandline\r
+ //\r
+ Execute runner = new Execute(streamHandler,null);\r
+ runner.setAntRun(project);\r
+ runner.setCommandline(commandLine.getCommandline()); \r
+ System.out.println(Commandline.toString(commandLine.getCommandline()));\r
+ \r
+ int revl = -1;\r
+ //\r
+ // user execute class call external programs - GenFvImage\r
+ //\r
+ revl = runner.execute();\r
+ // \r
+ // execute command line success!\r
+ //\r
+ if (EFI_SUCCESS == revl){\r
+ System.out.println("GenFvImage succeeded!");\r
} else {\r
- log("GenFvImage - DONE!", Project.MSG_VERBOSE);\r
+ \r
+ // \r
+ // execute command line failed! \r
+ //\r
+ throw new BuildException("GenFvImage failed !(error =" + \r
+ Integer.toHexString(revl) + ")");\r
}\r
+ \r
} catch (Exception e) {\r
- throw new BuildException(e.getMessage());\r
- } finally {\r
- if (exitCode != 0) {\r
- throw new BuildException("GenFvImage: failed to generate FV file!");\r
- }\r
- }\r
-\r
+ System.out.println(e.getMessage());\r
+ } \r
}\r
/**\r
getInfFile\r
@param infFile name of infFile\r
**/\r
public void setInfFile(String infFile) {\r
- this.infFile = infFile;\r
- argList.add("-I");\r
- argList.add(infFile);\r
+ this.infFile = "-I " + infFile;\r
}\r
\r
/**\r
**/\r
public void setArch(String arch) {\r
this.arch = arch;\r
- }\r
-\r
- /**\r
- getOutputDir\r
- \r
- This function is to get output directory.\r
- \r
- @return Path of output directory.\r
- **/\r
- public String getOutputDir() {\r
- return outputDir;\r
- }\r
-\r
- /**\r
- setOutputDir\r
- \r
- This function is to set output directory.\r
- \r
- @param outputDir The output direcotry.\r
- **/\r
- public void setOutputDir(String outputDir) {\r
- this.outputDir = outputDir;\r
- }\r
+ } \r
}
\ No newline at end of file