]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
1.Change environment variable from "Framework_Tools_Path" to "FRAMEWORK_TOOLS_PATH".
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFvImageTask.java
index 6f3cd7bd7b8c9afe49868547ee633a321af70ef5..1f5e4ecf6d8e362e9eae18a7935a2a135c5234ac 100644 (file)
@@ -14,6 +14,7 @@
 \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
@@ -22,16 +23,6 @@ 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
@@ -39,10 +30,6 @@ import java.util.Map;
   \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
@@ -51,15 +38,7 @@ public class GenFvImageTask extends Task implements EfiDefine{
     /// 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
@@ -68,45 +47,68 @@ public class GenFvImageTask extends Task implements EfiDefine{
     **/\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
@@ -126,9 +128,7 @@ public class GenFvImageTask extends Task implements EfiDefine{
       @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
@@ -150,27 +150,5 @@ public class GenFvImageTask extends Task implements EfiDefine{
     **/\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