\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
private String infFile="";\r
///\r
- /// The target architecture.\r
+ /// Output directory\r
///\r
- private String arch="";\r
- \r
+ private String outputDir = ".";\r
+ ///\r
+ /// argument list\r
+ ///\r
+ LinkedList<String> argList = new LinkedList<String>();\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
- String command = "";\r
- \r
- if (path == null){\r
+ String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
+\r
+ if (path == null) {\r
path = "";\r
- }else {\r
- path = path + File.separatorChar;\r
- }\r
- \r
- if (arch.equalsIgnoreCase("")){\r
- command = path + "GenFvImage";\r
+ } else {\r
+ path += File.separatorChar;\r
}\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
+ argList.addFirst(path + toolName);\r
+\r
+ /// lauch the program\r
+ ///\r
+ ProcessBuilder pb = new ProcessBuilder(argList);\r
+ pb.directory(new File(outputDir));\r
+ int exitCode = 0;\r
+ log((new File(this.infFile)).getName());\r
try {\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
+ 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));\r
} else {\r
- \r
- // \r
- // execute command line failed! \r
- //\r
- throw new BuildException("GenFvImage failed !(error =" + \r
- Integer.toHexString(revl) + ")");\r
+ log("GenFvImage succeeded!", Project.MSG_VERBOSE);\r
}\r
- \r
} catch (Exception e) {\r
- System.out.println(e.getMessage());\r
- } \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
}\r
/**\r
getInfFile\r
@param infFile name of infFile\r
**/\r
public void setInfFile(String infFile) {\r
- this.infFile = "-I " + infFile;\r
+ this.infFile = infFile;\r
+ argList.add("-I");\r
+ argList.add(infFile);\r
}\r
\r
/**\r
- getArch\r
+ getOutputDir\r
+ \r
+ This function is to get output directory.\r
\r
- This function is to get class member of arch.\r
- @return The target architecture.\r
+ @return Path of output directory.\r
**/\r
- public String getArch() {\r
- return arch;\r
+ public String getOutputDir() {\r
+ return outputDir;\r
}\r
- \r
+\r
/**\r
- setArch\r
+ setOutputDir\r
\r
- This function is to set class member of arch. \r
+ This function is to set output directory.\r
\r
- @param arch The target architecture.\r
+ @param outputDir The output direcotry.\r
**/\r
- public void setArch(String arch) {\r
- this.arch = arch;\r
- } \r
-}
\ No newline at end of file
+ public void setOutputDir(String outputDir) {\r
+ this.outputDir = outputDir;\r
+ }\r
+}\r