**/\r
package org.tianocore.framework.tasks;\r
\r
+import java.io.ByteArrayOutputStream;\r
import java.io.DataInputStream;\r
import java.io.DataOutputStream;\r
import java.io.File;\r
import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
import java.util.ArrayList;\r
import java.util.Iterator;\r
import java.util.List;\r
\r
import org.apache.tools.ant.BuildException;\r
+import org.tianocore.common.logger.EdkLog;\r
\r
/**\r
Class Tool is to define an external tool to be used for genffsfile\r
String outputPath;\r
File outputFile ;\r
List<Input> inputFiles = new ArrayList<Input>();\r
-\r
+ List<Section> gensectList = new ArrayList<Section>();\r
+ String inputArg = "-i ";\r
/**\r
Call extern tool\r
\r
Iterator inputIter = inputFiles.iterator();\r
ToolArg toolArg;\r
Input file = null;\r
+ \r
+ \r
+ //\r
+ // Get each section which under the compress {};\r
+ // And add it is contains to File;\r
+ //\r
+ Section sect;\r
+ try{\r
+ Iterator SectionIter = this.gensectList.iterator();\r
+ while (SectionIter.hasNext()){\r
+ sect = (Section)SectionIter.next();\r
+ //\r
+ // Parse <genSection> element\r
+ //\r
+ File outputFile = File.createTempFile("temp", "sec1",new File(outputPath));\r
+ FileOutputStream bo = new FileOutputStream(outputFile);\r
+ DataOutputStream Do = new DataOutputStream (bo);\r
+ //\r
+ // Call each section class's toBuffer function.\r
+ //\r
+ try {\r
+ sect.toBuffer(Do);\r
+ }\r
+ catch (BuildException e) {\r
+ System.out.print(e.getMessage());\r
+ throw new BuildException ("GenSection failed at Tool!");\r
+ } \r
+ Do.close();\r
+ this.inputArg += outputFile.getPath() + " "; \r
+ } \r
+ } catch (IOException e){\r
+ throw new BuildException ("Gensection failed at tool!");\r
+ }\r
\r
+ \r
///\r
/// argument of tools\r
///\r
///\r
/// input files for tools\r
///\r
- argument += " -i ";\r
while (inputIter.hasNext()) {\r
file = (Input)inputIter.next();\r
- argument += file.toString(" ");\r
+ inputArg += file.toString(" ");\r
}\r
-\r
try {\r
- outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
- argument = argument + " -o " + outputFile.getPath();\r
-\r
+ outputFile = File.createTempFile("temp", null, new File(outputPath));\r
+ argument = argument + inputArg + " -o " + outputFile.getPath();\r
+ EdkLog.log(EdkLog.EDK_INFO, argument);\r
///\r
/// execute command line\r
///\r
- Process crcProcess = Runtime.getRuntime().exec(command + " " + argument);\r
- crcProcess.waitFor();\r
+ Process process = Runtime.getRuntime().exec(command + " " + argument);\r
+ process.waitFor();\r
} catch (Exception e) {\r
System.out.print (e.getMessage());\r
throw new BuildException("Execution of externalTool task failed!\n");\r
public void addInput(Input file) {\r
inputFiles.add(file);\r
}\r
+ \r
+// /**\r
+// addTool\r
+// \r
+// This function is to add instance of Tool to list.\r
+// \r
+// @param tool instance of Tool.\r
+// **/\r
+// public void addTool(Tool tool){\r
+// this.toolList.add(tool);\r
+// }\r
+ \r
+ public void addGenSection(GenSectionTask genSect){\r
+ this.gensectList.add(genSect);\r
+ }\r
+ \r
}\r
\r
\r