2 This file is to define nested element which is meant for specifying a tool
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.framework
.tasks
;
16 import java
.io
.DataInputStream
;
17 import java
.io
.DataOutputStream
;
19 import java
.io
.FileInputStream
;
20 import java
.io
.FileOutputStream
;
21 import java
.io
.IOException
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
26 import org
.apache
.tools
.ant
.BuildException
;
27 import org
.tianocore
.common
.logger
.EdkLog
;
30 Class Tool is to define an external tool to be used for genffsfile
32 public class Tool
implements EfiDefine
, Section
{
34 private String toolName
= "";
35 private ToolArg toolArgList
= new ToolArg();
36 private Input inputFiles
= new Input();
37 private String outputPath
;
38 private File outputFile
;
39 private List
<Section
> gensectList
= new ArrayList
<Section
>();
43 @param buffer The buffer to put the result with alignment
45 public void toBuffer (DataOutputStream buffer
){
51 } catch (Exception e
) {
52 throw new BuildException("Call to executeTool failed!\n" + e
.getMessage());
56 /// check if file exist
58 //File OutputFile = new File (this.outPutFileName);
59 if (!outputFile
.exists()) {
60 throw new BuildException("The file " + outputFile
.getPath() + " does not exist!\n");
64 /// Read output file and write it's cotains to buffer
66 FileInputStream fs
= null;
67 DataInputStream in
= null;
69 fs
= new FileInputStream (outputFile
);
70 in
= new DataInputStream (fs
);
73 int fileLen
= (int)outputFile
.length();
74 byte[] data
= new byte[fileLen
];
76 buffer
.write(data
, 0, fileLen
);
81 while ((fileLen
& 0x03) != 0) {
85 } catch (Exception e
) {
86 EdkLog
.log(e
.getMessage());
87 throw new BuildException("Tool call, toBuffer failed!\n");
96 } catch (Exception e
) {
97 EdkLog
.log("WARNING: Cannot close " + outputFile
.getPath());
103 /// execute external tool for genffsfile
105 private void executeTool () {
107 String argument
= "";
111 // Get each section which under the compress {};
112 // And add it is contains to File;
116 Iterator SectionIter
= this.gensectList
.iterator();
117 while (SectionIter
.hasNext()){
118 sect
= (Section
)SectionIter
.next();
120 // Parse <genSection> element
122 File outputFile
= File
.createTempFile("temp", "sec1", new File(outputPath
));
123 FileOutputStream bo
= new FileOutputStream(outputFile
);
124 DataOutputStream Do
= new DataOutputStream (bo
);
126 // Call each section class's toBuffer function.
131 catch (BuildException e
) {
132 EdkLog
.log(e
.getMessage());
133 throw new BuildException ("GenSection failed at Tool!");
136 this.inputFiles
.insFile(outputFile
.getPath());
138 } catch (IOException e
){
139 throw new BuildException ("Gensection failed at tool!");
143 outputFile
= File
.createTempFile("temp", null, new File(outputPath
));
144 argument
= toolArgList
+ inputFiles
.toStringWithSinglepPrefix(" -i ")
145 + " -o " + outputFile
.getPath();
146 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, command
+ " " + argument
);
148 /// execute command line
150 Process process
= Runtime
.getRuntime().exec(command
+ " " + argument
);
152 } catch (Exception e
) {
153 EdkLog
.log(e
.getMessage());
154 throw new BuildException("Execution of externalTool task failed!\n");
159 Add method of ANT task/datatype for nested ToolArg type of element
161 @param toolArg The ToolArg object containing arguments for the tool
163 public void addConfiguredToolArg (ToolArg toolArg
) {
164 toolArgList
.insert(toolArg
);
168 Get method of ANT task/datatype for attribute "OutputPath"
170 @returns The name of output path
172 public String
getOutputPath() {
177 Set method of ANT task/datatype for attribute "OutputPath"
179 @param outputPath The name of output path
181 public void setOutputPath(String outPutPath
) {
182 this.outputPath
= outPutPath
;
186 Get method of ANT task/datatype for attribute "ToolName"
188 @returns The name of the tool.
190 public String
getToolName() {
195 Set method of ANT task/datatype for attribute "ToolName"
197 @param toolName The name of the tool
199 public void setToolName(String toolName
) {
200 this.toolName
= toolName
;
204 Add method of ANT task/datatype for nested Input type of element
206 @param file The Input objec which represents a file
208 public void addConfiguredInput(Input file
) {
209 inputFiles
.insert(file
);
215 // This function is to add instance of Tool to list.
217 // @param tool instance of Tool.
219 // public void addTool(Tool tool){
220 // this.toolList.add(tool);
223 public void addGenSection(GenSectionTask genSect
){
224 this.gensectList
.add(genSect
);