X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FFrameworkTasks%2Forg%2Ftianocore%2Fframework%2Ftasks%2FTool.java;h=17e6298e003cac3bb8f7a0e4097837ef6e14c6fb;hb=c493be6c9d2829c73e2e884846d098d955738f62;hp=0ef2a6ea7c22941d7bbb7709e49a7cd2ccc443bd;hpb=0fdb42ac4675ac888d7cfb3f29f68c342f47b9e9;p=mirror_edk2.git diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java index 0ef2a6ea7c..17e6298e00 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Random; import org.apache.tools.ant.BuildException; import org.tianocore.common.logger.EdkLog; @@ -34,8 +35,9 @@ public class Tool implements EfiDefine, Section { private String toolName = ""; private ToolArg toolArgList = new ToolArg(); private Input inputFiles = new Input(); + private Input tempInputFile = new Input(); private String outputPath; - private File outputFile ; + private String outputFileName ; private List
gensectList = new ArrayList
(); /** Call extern tool @@ -55,7 +57,7 @@ public class Tool implements EfiDefine, Section { /// /// check if file exist /// - //File OutputFile = new File (this.outPutFileName); + File outputFile = new File (this.outputFileName); if (!outputFile.exists()) { throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n"); } @@ -93,6 +95,7 @@ public class Tool implements EfiDefine, Section { if (fs != null) { fs.close(); } + outputFile.delete(); } catch (Exception e) { EdkLog.log("WARNING: Cannot close " + outputFile.getPath()); } @@ -131,26 +134,38 @@ public class Tool implements EfiDefine, Section { catch (BuildException e) { EdkLog.log(e.getMessage()); throw new BuildException ("GenSection failed at Tool!"); - } - Do.close(); - this.inputFiles.insFile(outputFile.getPath()); + } finally { + if (Do != null){ + Do.close(); + } + + } + this.tempInputFile.insFile(outputFile.getPath()); } } catch (IOException e){ throw new BuildException ("Gensection failed at tool!"); - } + } try { - outputFile = File.createTempFile("temp", null, new File(outputPath)); + Random ran = new Random(9999); + this.outputFileName = "Temp" + ran.nextInt(); argument = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") - + " -o " + outputFile.getPath(); + + tempInputFile.toString(" ")+ " -o " + outputFileName; EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument); + EdkLog.log(this, EdkLog.EDK_INFO, this.outputFileName); /// /// execute command line /// Process process = Runtime.getRuntime().exec(command + " " + argument); process.waitFor(); - } catch (Exception e) { - EdkLog.log(e.getMessage()); + Iterator tempFile = tempInputFile.getNameList().iterator(); + while (tempFile.hasNext()){ + File file = new File((String)tempFile.next()); + if (file.exists()) { + file.delete(); + } + } + } catch (Exception e) { EdkLog.log(e.getMessage()); throw new BuildException("Execution of externalTool task failed!\n"); } }