X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkTasks%2Forg%2Ftianocore%2Fframework%2Ftasks%2FGenFvImageTask.java;h=78eabf9f8d032eecc2b29a8b1bfd5cb1b600915e;hp=1f5e4ecf6d8e362e9eae18a7935a2a135c5234ac;hb=87379bbecf036195249649680b958e501dc952a5;hpb=2da8968bb588b2bf72501a90597b8de464394024 diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java index 1f5e4ecf6d..78eabf9f8d 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java @@ -14,14 +14,15 @@ **/ package org.tianocore.framework.tasks; -import java.io.File; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.Execute; -import org.apache.tools.ant.taskdefs.LogStreamHandler; -import org.apache.tools.ant.types.Commandline; + +import java.io.File; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder; +import java.util.LinkedList; /** GenFvImageTask @@ -30,15 +31,23 @@ import org.apache.tools.ant.types.Commandline; **/ public class GenFvImageTask extends Task implements EfiDefine{ + /// + /// tool name + /// + static final private String toolName = "GenFvImage"; /// /// The name of input inf file /// private String infFile=""; /// - /// The target architecture. + /// Output directory /// - private String arch=""; - + private String outputDir = "."; + /// + /// argument list + /// + LinkedList argList = new LinkedList(); + /** execute @@ -48,67 +57,40 @@ public class GenFvImageTask extends Task implements EfiDefine{ public void execute() throws BuildException { Project project = this.getOwningTarget().getProject(); String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); - String command = ""; - - if (path == null){ + + if (path == null) { path = ""; - }else { - path = path + File.separatorChar; - } - - if (arch.equalsIgnoreCase("")){ - command = path + "GenFvImage"; + } else { + path += File.separatorChar; } - if (arch.equalsIgnoreCase("ia32")){ - command = path + "GenFvImage_IA32"; - } - if (arch.equalsIgnoreCase("x64")){ - command = path + "GenFvImage_X64"; - } - if (arch.equalsIgnoreCase("ipf")){ - command = path + "GenFvImage_IPF"; - } - String argument = infFile; - + argList.addFirst(path + toolName); + + /// lauch the program + /// + ProcessBuilder pb = new ProcessBuilder(argList); + pb.directory(new File(outputDir)); + int exitCode = 0; + log((new File(this.infFile)).getName()); try { - - Commandline commandLine = new Commandline(); - commandLine.setExecutable(command); - commandLine.createArgument().setLine(argument); - - LogStreamHandler streamHandler = new LogStreamHandler(this, - Project.MSG_INFO, - Project.MSG_WARN); - // - // create a execute object and set it's commandline - // - Execute runner = new Execute(streamHandler,null); - runner.setAntRun(project); - runner.setCommandline(commandLine.getCommandline()); - System.out.println(Commandline.toString(commandLine.getCommandline())); - - int revl = -1; - // - // user execute class call external programs - GenFvImage - // - revl = runner.execute(); - // - // execute command line success! - // - if (EFI_SUCCESS == revl){ - System.out.println("GenFvImage succeeded!"); + Process cmdProc = pb.start(); + InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream()); + char[] buf = new char[1024]; + + exitCode = cmdProc.waitFor(); + if (exitCode != 0) { + int len = cmdOut.read(buf, 0, 1024); + log(new String(buf, 0, len)); } else { - - // - // execute command line failed! - // - throw new BuildException("GenFvImage failed !(error =" + - Integer.toHexString(revl) + ")"); + log("GenFvImage succeeded!", Project.MSG_VERBOSE); } - } catch (Exception e) { - System.out.println(e.getMessage()); - } + throw new BuildException(e.getMessage()); + } finally { + if (exitCode != 0) { + //throw new BuildException("GenFvImage: failed to generate FV file!"); + } + } + } /** getInfFile @@ -128,27 +110,30 @@ public class GenFvImageTask extends Task implements EfiDefine{ @param infFile name of infFile **/ public void setInfFile(String infFile) { - this.infFile = "-I " + infFile; + this.infFile = infFile; + argList.add("-I"); + argList.add(infFile); } /** - getArch + getOutputDir + + This function is to get output directory. - This function is to get class member of arch. - @return The target architecture. + @return Path of output directory. **/ - public String getArch() { - return arch; + public String getOutputDir() { + return outputDir; } - + /** - setArch + setOutputDir - This function is to set class member of arch. + This function is to set output directory. - @param arch The target architecture. + @param outputDir The output direcotry. **/ - public void setArch(String arch) { - this.arch = arch; - } -} \ No newline at end of file + public void setOutputDir(String outputDir) { + this.outputDir = outputDir; + } +}