Added outputDir attribute to support generating FV file in specified directory
authorjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 07:45:15 +0000 (07:45 +0000)
committerjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 07:45:15 +0000 (07:45 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@273 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java

index cd1e421..6f3cd7b 100644 (file)
@@ -14,7 +14,6 @@
 \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
@@ -23,6 +22,16 @@ import org.apache.tools.ant.taskdefs.Execute;
 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
@@ -30,6 +39,10 @@ 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
@@ -38,7 +51,15 @@ public class GenFvImageTask extends Task implements EfiDefine{
     /// The target architecture.\r
     ///\r
     private String arch="";\r
-    \r
+    ///\r
+    /// Output directory\r
+    ///\r
+    private String outputDir = ".";\r
+    ///\r
+    /// argument list\r
+    ///\r
+    LinkedList<String> argList = new LinkedList<String>();\r
+\r
     /**\r
       execute\r
       \r
@@ -48,67 +69,44 @@ 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
+        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
+        if (arch != null && arch.length() > 0) {\r
+            argList.addFirst(path + toolName + "_" + arch);\r
+        } else {\r
+            argList.addFirst(path + toolName);\r
         }\r
-        String argument = infFile;\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
         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), Project.MSG_ERR);\r
             } else {\r
-                \r
-            // \r
-            // execute command line failed! \r
-            //\r
-                throw new BuildException("GenFvImage failed !(error =" + \r
-                    Integer.toHexString(revl) + ")");\r
+                log("GenFvImage - DONE!", 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
@@ -128,7 +126,9 @@ 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
@@ -150,5 +150,27 @@ public class GenFvImageTask extends Task implements EfiDefine{
     **/\r
     public void setArch(String arch) {\r
         this.arch = arch;\r
-    }   \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
 }
\ No newline at end of file