]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Modify GenFfsFileTask.
authorqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Sep 2006 08:16:10 +0000 (08:16 +0000)
committerqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Sep 2006 08:16:10 +0000 (08:16 +0000)
If GenFfsFileTask is failed, the *.ffs file will not be create.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1598 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java

index cbe20f02960aa12b715422bc26ba9c33e0be7a04..4cbbfab8c6ec34c1a8a07d962015b853726425fd 100644 (file)
@@ -150,7 +150,6 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         if (this.ffsFileType.equals("")) {\r
             throw new BuildException ("Must set ffsFileType!\n");\r
         }\r
-\r
         //\r
         //  Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix.\r
         //  If outputDir's value was set,  file will output to the outputDir.\r
@@ -169,7 +168,16 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
 \r
         String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;\r
         File ffsFile = new File (ffsFilePath);\r
-        genFfs(ffsFile);\r
+        try{\r
+            genFfs(ffsFile);\r
+        }catch (BuildException e){\r
+            if (ffsFile != null && ffsFile.exists()){\r
+                ffsFile.deleteOnExit();\r
+            }\r
+            throw new BuildException(e.getMessage());\r
+            \r
+        }\r
+        \r
     }   \r
 \r
     /**\r
@@ -742,7 +750,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
        @param ffsFile          Name of FFS file.\r
        @param isOrg            Flag to indicate generate ORG ffs file or not.\r
     **/\r
-    private void genFfs(File ffsFile) {\r
+    private void genFfs(File ffsFile) throws BuildException {\r
         Section           sect;\r
         int               fileSize;\r
         int               fileDataSize;\r
@@ -772,6 +780,9 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
                     //\r
                     sect.toBuffer((DataOutputStream)dataBuffer);\r
                 } catch (Exception e) {\r
+                    if (dataBuffer != null){\r
+                        dataBuffer.close();\r
+                    }\r
                     throw new BuildException (e.getMessage());\r
                 }\r
             }\r
index a2bbf4fe8be64372c1311e53638de250ac005d4f..4cd7a96cdbd76fc71dd2e0ea72cf5e2dcebf8418 100644 (file)
@@ -303,11 +303,12 @@ public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes
                         System.out.print(e.getMessage());\r
                         throw new BuildException(\r
                                 "Compress.toBuffer failed at section");\r
+                    } finally {\r
+                        if (Do != null){\r
+                            Do.close();\r
+                        }\r
                     }\r
-\r
                 }\r
-                Do.close();\r
-\r
                 //\r
                 // Call compress\r
                 //\r
@@ -364,7 +365,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes
                 }\r
             } catch (Exception e) {\r
                 throw new BuildException("compress.toBuffer failed!\n");\r
-            }\r
+            } \r
         } else {\r
             Section sect;\r
             Iterator sectionIter = this.sectFileList.iterator();\r
index a7d28f5e7f9e7578248553c7cb7bf81061225ce2..17e6298e003cac3bb8f7a0e4097837ef6e14c6fb 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