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=a7d28f5e7f9e7578248553c7cb7bf81061225ce2;hp=7f04bf231b59f4845337c63563775c31e08b505a;hb=34a0c84476d23d14ddfea559276b2960b6c68c08;hpb=82810f3b0f9ba49ed2d9f96c5b53e90dd7e66d88 diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java index 7f04bf231b..a7d28f5e7f 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java @@ -17,23 +17,27 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.tools.ant.BuildException; +import org.tianocore.common.logger.EdkLog; /** Class Tool is to define an external tool to be used for genffsfile **/ public class Tool implements EfiDefine, Section { - String toolName = ""; - List toolArgList = new ArrayList(); - String outputPath; - File outputFile ; - List inputFiles = new ArrayList(); - + 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 List
gensectList = new ArrayList
(); /** Call extern tool @@ -46,7 +50,7 @@ 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()); } /// @@ -80,7 +84,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 { @@ -90,8 +94,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()); } } } @@ -103,40 +108,58 @@ 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; - - /// - /// argument of tools - /// - while (argIter.hasNext()) { - toolArg = (ToolArg)argIter.next(); - argument = argument + toolArg.getLine() + " "; - - } - - /// - /// input files for tools - /// - argument += " -i "; - while (inputIter.hasNext()) { - file = (Input)inputIter.next(); - argument += file.toString(" "); + + // + // Get each section which under the compress {}; + // And add it is contains to File; + // + Section sect; + try{ + Iterator SectionIter = this.gensectList.iterator(); + while (SectionIter.hasNext()){ + sect = (Section)SectionIter.next(); + // + // Parse element + // + File outputFile = File.createTempFile("temp", "sec1", new File(outputPath)); + FileOutputStream bo = new FileOutputStream(outputFile); + DataOutputStream Do = new DataOutputStream (bo); + // + // Call each section class's toBuffer function. + // + try { + sect.toBuffer(Do); + } + catch (BuildException e) { + EdkLog.log(e.getMessage()); + throw new BuildException ("GenSection failed at Tool!"); + } + Do.close(); + this.tempInputFile.insFile(outputFile.getPath()); + } + } catch (IOException e){ + throw new BuildException ("Gensection failed at tool!"); } try { - outputFile = File.createTempFile("temp", ".crc", new File(outputPath)); - argument = argument + " -o " + outputFile.getPath(); - + outputFile = File.createTempFile("temp", null, new File(outputPath)); + argument = toolArgList + inputFiles.toStringWithSinglepPrefix(" -i ") + + tempInputFile.toString(" ")+ " -o " + outputFile.getPath(); + EdkLog.log(this, EdkLog.EDK_VERBOSE, command + " " + argument); /// /// execute command line /// - Process crcProcess = Runtime.getRuntime().exec(command + " " + argument); - crcProcess.waitFor(); + Process process = Runtime.getRuntime().exec(command + " " + argument); + process.waitFor(); + Iterator tempFile = tempInputFile.getNameList().iterator(); + while (tempFile.hasNext()){ + File file = new File((String)tempFile.next()); + if (file.exists()) { + file.delete(); + } + } } catch (Exception e) { - System.out.print (e.getMessage()); + EdkLog.log(e.getMessage()); throw new BuildException("Execution of externalTool task failed!\n"); } } @@ -146,8 +169,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); } /** @@ -191,9 +214,24 @@ 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); } + +// /** +// addTool +// +// This function is to add instance of Tool to list. +// +// @param tool instance of Tool. +// **/ +// public void addTool(Tool tool){ +// this.toolList.add(tool); +// } + + public void addGenSection(GenSectionTask genSect){ + this.gensectList.add(genSect); + } }