]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
Modify GenFfsTask to make it don't create ORG file.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFvImageTask.java
index f9340758b31931e021e058a33e536f3d940ede39..78eabf9f8d032eecc2b29a8b1bfd5cb1b600915e 100644 (file)
 \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.Task;\r
-import org.apache.tools.ant.taskdefs.Execute;\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.InputStreamReader;\r
+import java.lang.ProcessBuilder;\r
+import java.util.LinkedList;\r
 \r
 /**\r
   GenFvImageTask\r
@@ -30,15 +31,23 @@ import org.apache.tools.ant.types.Commandline;
   \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
@@ -48,74 +57,40 @@ public class GenFvImageTask extends Task implements EfiDefine{
     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
+\r
+        if (path == null) {\r
             path = "";\r
-        }else {\r
-            path = path + File.separatorChar;\r
-        }\r
-        \r
-        // FIXME arch should be passed via schema attributes.\r
-        arch=System.getenv("ARCH");\r
-        if (arch == null) {\r
-          arch = "";\r
+        } else {\r
+            path += File.separatorChar;\r
         }\r
-        // FIXME end\r
+        argList.addFirst(path + toolName);\r
 \r
-        if (arch.equalsIgnoreCase("IA32")){\r
-            command = path + "GenFvImage_Ia32";\r
-        }   \r
-        else if (arch.equalsIgnoreCase("X64")){\r
-            command = path + "GenFvImage_X64";\r
-        }\r
-        else if (arch.equalsIgnoreCase("IPF")){\r
-            command = path + "GenFvImage_Ipf";\r
-        }\r
-        else {\r
-            command = path + "GenFvImage";\r
-        }\r
-        String argument = infFile;\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
@@ -135,27 +110,30 @@ public class GenFvImageTask extends Task implements EfiDefine{
       @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
+    public void setOutputDir(String outputDir) {\r
+        this.outputDir = outputDir;\r
+    }\r
 }\r