]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
Fixed the issue caused by introducing INCLUDE_PATH property;
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / Tool.java
index 4cc4d374c43136b7a3a6eaaf0de712d62fd57c1e..7f04bf231b59f4845337c63563775c31e08b505a 100644 (file)
@@ -31,7 +31,7 @@ public class Tool implements EfiDefine, Section {
     String toolName     = "";\r
     List<Object>   toolArgList  = new ArrayList<Object>();\r
     String outputPath;\r
-    String outPutFileName ;\r
+    File outputFile ;\r
     List<Input>    inputFiles = new ArrayList<Input>();\r
 \r
     /**\r
@@ -40,9 +40,6 @@ public class Tool implements EfiDefine, Section {
      @param     buffer  The buffer to put the result with alignment\r
      **/\r
     public void toBuffer (DataOutputStream buffer){\r
-        File           OutputFile;\r
-        byte           data;\r
-\r
         ///\r
         /// call extern tool\r
         ///\r
@@ -55,25 +52,25 @@ public class Tool implements EfiDefine, Section {
         ///\r
         /// check if file exist\r
         ///\r
-        OutputFile = new File (this.outPutFileName);\r
-        long fileLen = OutputFile.length();\r
-        if (!OutputFile.exists()) {\r
-            throw new BuildException("The file " + outPutFileName + " does not exist!\n");\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
 \r
         ///\r
         /// Read output file and write it's cotains to buffer\r
         ///\r
+        FileInputStream fs = null;\r
+        DataInputStream in = null;\r
         try {\r
-            FileInputStream fs  = new FileInputStream (this.outPutFileName);\r
-            DataInputStream In  = new DataInputStream (fs);\r
-\r
-            int i = 0;\r
-            while (i < fileLen) {\r
-                data = In.readByte();\r
-                buffer.writeByte(data);\r
-                i ++;\r
-            }\r
+            fs  = new FileInputStream (outputFile);\r
+            in  = new DataInputStream (fs);\r
+\r
+\r
+            int fileLen = (int)outputFile.length();\r
+            byte[] data  = new byte[fileLen];\r
+            in.read(data);\r
+            buffer.write(data, 0, fileLen);\r
 \r
             ///\r
             /// 4 byte alignment\r
@@ -82,11 +79,20 @@ public class Tool implements EfiDefine, Section {
                 fileLen++;\r
                 buffer.writeByte(0);\r
             }\r
-            In.close();\r
-\r
         } catch (Exception e) {\r
             System.out.print(e.getMessage());\r
             throw new BuildException("Tool call, toBuffer failed!\n");\r
+        } finally {\r
+            try {\r
+                if (in != null) {\r
+                    in.close();\r
+                }\r
+                if (fs != null) {\r
+                    fs.close();\r
+                }\r
+            } catch (Exception e) {\r
+                System.out.println("WARNING: Cannot close " + outputFile.getPath());\r
+            }\r
         }\r
     }\r
 \r
@@ -114,16 +120,15 @@ public class Tool implements EfiDefine, Section {
         ///\r
         /// input files for tools\r
         ///\r
-        argument = argument + "-i ";\r
+        argument += " -i ";\r
         while (inputIter.hasNext()) {\r
             file = (Input)inputIter.next();\r
-            argument = argument + file.getFile() + " ";\r
+            argument += file.toString(" ");\r
         }\r
 \r
-        outPutFileName = outputPath + File.separatorChar + (new File(file.getFile())).getName() + ".crc";\r
-        argument       = argument + " -o " + outPutFileName; \r
-\r
         try {\r
+            outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
+            argument   = argument + " -o " + outputFile.getPath();\r
 \r
             ///\r
             /// execute command line\r