Modify GenFfsFileTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / Tool.java
index a7d28f5..17e6298 100644 (file)
@@ -22,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
@@ -36,7 +37,7 @@ public class Tool implements EfiDefine, Section {
     private Input inputFiles = new Input();\r
     private Input tempInputFile = new Input();\r
     private String outputPath;\r
-    private File outputFile ;\r
+    private String outputFileName ;\r
     private List<Section>  gensectList = new ArrayList<Section>();\r
     /**\r
      Call extern tool\r
@@ -56,7 +57,7 @@ public class Tool implements EfiDefine, Section {
         ///\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
@@ -133,19 +134,25 @@ public class Tool implements EfiDefine, Section {
                 catch (BuildException e) {\r
                     EdkLog.log(e.getMessage());\r
                     throw new BuildException ("GenSection failed at Tool!");\r
-                }  \r
-                Do.close();\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
         try {\r
-            outputFile = File.createTempFile("temp", null, new File(outputPath));\r
+            Random ran = new Random(9999); \r
+            this.outputFileName = "Temp" + ran.nextInt();\r
             argument   = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") \r
-                         + tempInputFile.toString(" ")+ " -o " + outputFile.getPath();\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
@@ -158,8 +165,7 @@ public class Tool implements EfiDefine, Section {
                     file.delete();\r
                 }\r
             }\r
-        } catch (Exception e) {\r
-            EdkLog.log(e.getMessage());\r
+        } catch (Exception e) {\r            EdkLog.log(e.getMessage());\r
             throw new BuildException("Execution of externalTool task failed!\n");\r
         }\r
     }\r