]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
Support calling customized compression tool in FrameworkTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / Tool.java
index 7f04bf231b59f4845337c63563775c31e08b505a..ea9546487a54d0fa73338f26b82deba695ea2ec3 100644 (file)
@@ -13,15 +13,19 @@ 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
 import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
 \r
 import org.apache.tools.ant.BuildException;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
  Class Tool is to define an external tool to be used for genffsfile\r
@@ -33,7 +37,8 @@ public class Tool implements EfiDefine, Section {
     String outputPath;\r
     File outputFile ;\r
     List<Input>    inputFiles = new ArrayList<Input>();\r
-\r
+    List<Section>  gensectList = new ArrayList<Section>();\r
+    String inputArg = "-i ";\r
     /**\r
      Call extern tool\r
 \r
@@ -107,7 +112,41 @@ public class Tool implements EfiDefine, Section {
         Iterator inputIter = inputFiles.iterator();\r
         ToolArg toolArg;\r
         Input file = null;\r
+              \r
+        \r
+        //\r
+        //  Get each section which under the compress {};\r
+        //  And add it is contains to File;\r
+        //\r
+        Section sect;\r
+        try{\r
+            Iterator SectionIter = this.gensectList.iterator();\r
+            while (SectionIter.hasNext()){\r
+                sect = (Section)SectionIter.next();\r
+                //\r
+                // Parse <genSection> element\r
+                //\r
+                File outputFile = File.createTempFile("temp", "sec1",new File(outputPath));\r
+                FileOutputStream bo = new FileOutputStream(outputFile);\r
+                DataOutputStream Do = new DataOutputStream (bo);\r
+                //\r
+                //  Call each section class's toBuffer function.\r
+                //\r
+                try {\r
+                    sect.toBuffer(Do);\r
+                }\r
+                catch (BuildException e) {\r
+                    System.out.print(e.getMessage());\r
+                    throw new BuildException ("GenSection failed at Tool!");\r
+                }  \r
+                Do.close();\r
+                this.inputArg += 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
@@ -120,21 +159,19 @@ public class Tool implements EfiDefine, Section {
         ///\r
         /// input files for tools\r
         ///\r
-        argument += " -i ";\r
         while (inputIter.hasNext()) {\r
             file = (Input)inputIter.next();\r
-            argument += file.toString(" ");\r
+            inputArg += file.toString(" ");\r
         }\r
-\r
         try {\r
-            outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
-            argument   = argument + " -o " + outputFile.getPath();\r
-\r
+            outputFile = File.createTempFile("temp", null, new File(outputPath));\r
+            argument   = argument + inputArg + " -o " + outputFile.getPath();\r
+            EdkLog.log(EdkLog.EDK_INFO, argument);\r
             ///\r
             /// execute command line\r
             ///\r
-            Process crcProcess = Runtime.getRuntime().exec(command + " " + argument);\r
-            crcProcess.waitFor();\r
+            Process process = Runtime.getRuntime().exec(command + " " + argument);\r
+            process.waitFor();\r
         } catch (Exception e) {\r
             System.out.print (e.getMessage());\r
             throw new BuildException("Execution of externalTool task failed!\n");\r
@@ -194,6 +231,22 @@ public class Tool implements EfiDefine, Section {
     public void addInput(Input file) {\r
         inputFiles.add(file);\r
     }\r
+    \r
+//    /**\r
+//      addTool\r
+//      \r
+//      This function is to add instance of Tool to list.\r
+//      \r
+//      @param tool             instance of Tool.\r
+//    **/\r
+//    public void addTool(Tool tool){\r
+//        this.toolList.add(tool);\r
+//    }\r
+    \r
+    public void addGenSection(GenSectionTask genSect){\r
+        this.gensectList.add(genSect);\r
+    }\r
+    \r
 }\r
 \r
 \r