]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
Modify GenFfsFileTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / Tool.java
index ea9546487a54d0fa73338f26b82deba695ea2ec3..17e6298e003cac3bb8f7a0e4097837ef6e14c6fb 100644 (file)
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.framework.tasks;\r
 \r
-import java.io.ByteArrayOutputStream;\r
 import java.io.DataInputStream;\r
 import java.io.DataOutputStream;\r
 import java.io.File;\r
@@ -23,6 +22,7 @@ import java.io.IOException;
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
+import java.util.Random;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.tianocore.common.logger.EdkLog;\r
@@ -32,13 +32,13 @@ import org.tianocore.common.logger.EdkLog;
  **/\r
 public class Tool implements EfiDefine, Section {\r
 \r
-    String toolName     = "";\r
-    List<Object>   toolArgList  = new ArrayList<Object>();\r
-    String outputPath;\r
-    File outputFile ;\r
-    List<Input>    inputFiles = new ArrayList<Input>();\r
-    List<Section>  gensectList = new ArrayList<Section>();\r
-    String inputArg = "-i ";\r
+    private String toolName     = "";\r
+    private ToolArg toolArgList = new ToolArg();\r
+    private Input inputFiles = new Input();\r
+    private Input tempInputFile = new Input();\r
+    private String outputPath;\r
+    private String outputFileName ;\r
+    private List<Section>  gensectList = new ArrayList<Section>();\r
     /**\r
      Call extern tool\r
 \r
@@ -51,13 +51,13 @@ public class Tool implements EfiDefine, Section {
         try {\r
             executeTool ();\r
         } catch (Exception e) {\r
-            throw new BuildException("Call to executeTool failed!\n");\r
+            throw new BuildException("Call to executeTool failed!\n" + e.getMessage());\r
         }\r
 \r
         ///\r
         /// check if file exist\r
         ///\r
-        //File OutputFile = new File (this.outPutFileName);\r
+        File outputFile = new File (this.outputFileName);\r
         if (!outputFile.exists()) {\r
             throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n");\r
         }\r
@@ -85,7 +85,7 @@ public class Tool implements EfiDefine, Section {
                 buffer.writeByte(0);\r
             }\r
         } catch (Exception e) {\r
-            System.out.print(e.getMessage());\r
+            EdkLog.log(e.getMessage());\r
             throw new BuildException("Tool call, toBuffer failed!\n");\r
         } finally {\r
             try {\r
@@ -95,8 +95,9 @@ public class Tool implements EfiDefine, Section {
                 if (fs != null) {\r
                     fs.close();\r
                 }\r
+                outputFile.delete(); \r
             } catch (Exception e) {\r
-                System.out.println("WARNING: Cannot close " + outputFile.getPath());\r
+                EdkLog.log("WARNING: Cannot close " + outputFile.getPath());\r
             }\r
         }\r
     }\r
@@ -108,11 +109,6 @@ public class Tool implements EfiDefine, Section {
         String command   = "";\r
         String argument  = "";\r
         command          = toolName;\r
-        Iterator argIter = toolArgList.iterator();\r
-        Iterator inputIter = inputFiles.iterator();\r
-        ToolArg toolArg;\r
-        Input file = null;\r
-              \r
         \r
         //\r
         //  Get each section which under the compress {};\r
@@ -126,7 +122,7 @@ public class Tool implements EfiDefine, Section {
                 //\r
                 // Parse <genSection> element\r
                 //\r
-                File outputFile = File.createTempFile("temp", "sec1",new File(outputPath));\r
+                File outputFile = File.createTempFile("temp", "sec1", new File(outputPath));\r
                 FileOutputStream bo = new FileOutputStream(outputFile);\r
                 DataOutputStream Do = new DataOutputStream (bo);\r
                 //\r
@@ -136,44 +132,40 @@ public class Tool implements EfiDefine, Section {
                     sect.toBuffer(Do);\r
                 }\r
                 catch (BuildException e) {\r
-                    System.out.print(e.getMessage());\r
+                    EdkLog.log(e.getMessage());\r
                     throw new BuildException ("GenSection failed at Tool!");\r
-                }  \r
-                Do.close();\r
-                this.inputArg += outputFile.getPath() + " ";                        \r
+                } finally {\r
+                    if (Do != null){\r
+                        Do.close();    \r
+                    }\r
+                    \r
+                } \r
+                this.tempInputFile.insFile(outputFile.getPath());\r
             }        \r
         } catch (IOException e){\r
             throw new BuildException ("Gensection failed at tool!");\r
-        }\r
-\r
-        \r
-        ///\r
-        /// argument of tools\r
-        ///\r
-        while (argIter.hasNext()) {\r
-            toolArg = (ToolArg)argIter.next();\r
-            argument = argument + toolArg.getLine() + " ";\r
-\r
-        }\r
+        } \r
 \r
-        ///\r
-        /// input files for tools\r
-        ///\r
-        while (inputIter.hasNext()) {\r
-            file = (Input)inputIter.next();\r
-            inputArg += file.toString(" ");\r
-        }\r
         try {\r
-            outputFile = File.createTempFile("temp", null, new File(outputPath));\r
-            argument   = argument + inputArg + " -o " + outputFile.getPath();\r
-            EdkLog.log(EdkLog.EDK_INFO, argument);\r
+            Random ran = new Random(9999); \r
+            this.outputFileName = "Temp" + ran.nextInt();\r
+            argument   = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") \r
+                         + tempInputFile.toString(" ")+ " -o " + outputFileName;\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument);\r
+            EdkLog.log(this, EdkLog.EDK_INFO, this.outputFileName);\r
             ///\r
             /// execute command line\r
             ///\r
             Process process = Runtime.getRuntime().exec(command + " " + argument);\r
             process.waitFor();\r
-        } catch (Exception e) {\r
-            System.out.print (e.getMessage());\r
+            Iterator tempFile = tempInputFile.getNameList().iterator();\r
+            while (tempFile.hasNext()){\r
+                File file = new File((String)tempFile.next());\r
+                if (file.exists()) {\r
+                    file.delete();\r
+                }\r
+            }\r
+        } catch (Exception e) {\r            EdkLog.log(e.getMessage());\r
             throw new BuildException("Execution of externalTool task failed!\n");\r
         }\r
     }\r
@@ -183,8 +175,8 @@ public class Tool implements EfiDefine, Section {
 \r
      @param     toolArg     The ToolArg object containing arguments for the tool\r
      **/\r
-    public void addToolArg (ToolArg toolArg) {\r
-        toolArgList.add (toolArg);\r
+    public void addConfiguredToolArg (ToolArg toolArg) {\r
+        toolArgList.insert(toolArg);\r
     }\r
 \r
     /**\r
@@ -228,8 +220,8 @@ public class Tool implements EfiDefine, Section {
 \r
      @param     file    The Input objec which represents a file\r
      **/\r
-    public void addInput(Input file) {\r
-        inputFiles.add(file);\r
+    public void addConfiguredInput(Input file) {\r
+        inputFiles.insert(file);\r
     }\r
     \r
 //    /**\r
@@ -245,8 +237,7 @@ public class Tool implements EfiDefine, Section {
     \r
     public void addGenSection(GenSectionTask genSect){\r
         this.gensectList.add(genSect);\r
-    }\r
-    \r
+    }    \r
 }\r
 \r
 \r