X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkTasks%2Forg%2Ftianocore%2Fframework%2Ftasks%2FTool.java;h=6eb9f65e316906eed39b179a5a42552c8e10d465;hp=ea9546487a54d0fa73338f26b82deba695ea2ec3;hb=eeaddae2960be8747f99ad155cd4b405f62d94a9;hpb=a1ffb10f211fa712dfd6d54156a412cce24014f4 diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java index ea9546487a..6eb9f65e31 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ package org.tianocore.framework.tasks; -import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; @@ -23,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; @@ -32,13 +32,13 @@ import org.tianocore.common.logger.EdkLog; **/ public class Tool implements EfiDefine, Section { - String toolName = ""; - List toolArgList = new ArrayList(); - String outputPath; - File outputFile ; - List inputFiles = new ArrayList(); - List
gensectList = new ArrayList
(); - String inputArg = "-i "; + private String toolName = ""; + private ToolArg toolArgList = new ToolArg(); + private Input inputFiles = new Input(); + private Input tempInputFile = new Input(); + private String outputPath; + private String outputFileName ; + private List
gensectList = new ArrayList
(); /** Call extern tool @@ -51,13 +51,13 @@ public class Tool implements EfiDefine, Section { try { executeTool (); } catch (Exception e) { - throw new BuildException("Call to executeTool failed!\n"); + throw new BuildException("Call to executeTool failed!\n" + e.getMessage()); } /// /// 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"); } @@ -85,7 +85,7 @@ public class Tool implements EfiDefine, Section { buffer.writeByte(0); } } catch (Exception e) { - System.out.print(e.getMessage()); + EdkLog.log(e.getMessage()); throw new BuildException("Tool call, toBuffer failed!\n"); } finally { try { @@ -95,8 +95,9 @@ public class Tool implements EfiDefine, Section { if (fs != null) { fs.close(); } + outputFile.delete(); } catch (Exception e) { - System.out.println("WARNING: Cannot close " + outputFile.getPath()); + EdkLog.log("WARNING: Cannot close " + outputFile.getPath()); } } } @@ -108,11 +109,6 @@ public class Tool implements EfiDefine, Section { String command = ""; String argument = ""; command = toolName; - Iterator argIter = toolArgList.iterator(); - Iterator inputIter = inputFiles.iterator(); - ToolArg toolArg; - Input file = null; - // // Get each section which under the compress {}; @@ -126,7 +122,7 @@ public class Tool implements EfiDefine, Section { // // Parse element // - File outputFile = File.createTempFile("temp", "sec1",new File(outputPath)); + File outputFile = File.createTempFile("temp", "sec1", new File(outputPath)); FileOutputStream bo = new FileOutputStream(outputFile); DataOutputStream Do = new DataOutputStream (bo); // @@ -136,44 +132,39 @@ public class Tool implements EfiDefine, Section { sect.toBuffer(Do); } catch (BuildException e) { - System.out.print(e.getMessage()); + EdkLog.log(e.getMessage()); throw new BuildException ("GenSection failed at Tool!"); - } - Do.close(); - this.inputArg += outputFile.getPath() + " "; + } finally { + if (Do != null){ + Do.close(); + } + + } + this.tempInputFile.insFile(outputFile.getPath()); } } catch (IOException e){ throw new BuildException ("Gensection failed at tool!"); - } - - - /// - /// argument of tools - /// - while (argIter.hasNext()) { - toolArg = (ToolArg)argIter.next(); - argument = argument + toolArg.getLine() + " "; - - } + } - /// - /// input files for tools - /// - while (inputIter.hasNext()) { - file = (Input)inputIter.next(); - inputArg += file.toString(" "); - } try { - outputFile = File.createTempFile("temp", null, new File(outputPath)); - argument = argument + inputArg + " -o " + outputFile.getPath(); - EdkLog.log(EdkLog.EDK_INFO, argument); + Random ran = new Random(9999); + this.outputFileName = "Temp" + ran.nextInt(); + argument = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") + + tempInputFile.toString(" ")+ " -o " + outputFileName; + EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument); /// /// execute command line /// Process process = Runtime.getRuntime().exec(command + " " + argument); process.waitFor(); - } catch (Exception e) { - System.out.print (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"); } } @@ -183,8 +174,8 @@ public class Tool implements EfiDefine, Section { @param toolArg The ToolArg object containing arguments for the tool **/ - public void addToolArg (ToolArg toolArg) { - toolArgList.add (toolArg); + public void addConfiguredToolArg (ToolArg toolArg) { + toolArgList.insert(toolArg); } /** @@ -228,8 +219,8 @@ public class Tool implements EfiDefine, Section { @param file The Input objec which represents a file **/ - public void addInput(Input file) { - inputFiles.add(file); + public void addConfiguredInput(Input file) { + inputFiles.insert(file); } // /** @@ -245,8 +236,7 @@ public class Tool implements EfiDefine, Section { public void addGenSection(GenSectionTask genSect){ this.gensectList.add(genSect); - } - + } }