]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
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 Input tempInputFile
= new Input();
38 private String outputPath
;
39 private File outputFile
;
40 private List
<Section
> gensectList
= new ArrayList
<Section
>();
44 @param buffer The buffer to put the result with alignment
46 public void toBuffer (DataOutputStream buffer
){
52 } catch (Exception e
) {
53 throw new BuildException("Call to executeTool failed!\n" + e
.getMessage());
57 /// check if file exist
59 //File OutputFile = new File (this.outPutFileName);
60 if (!outputFile
.exists()) {
61 throw new BuildException("The file " + outputFile
.getPath() + " does not exist!\n");
65 /// Read output file and write it's cotains to buffer
67 FileInputStream fs
= null;
68 DataInputStream in
= null;
70 fs
= new FileInputStream (outputFile
);
71 in
= new DataInputStream (fs
);
74 int fileLen
= (int)outputFile
.length();
75 byte[] data
= new byte[fileLen
];
77 buffer
.write(data
, 0, fileLen
);
82 while ((fileLen
& 0x03) != 0) {
86 } catch (Exception e
) {
87 EdkLog
.log(e
.getMessage());
88 throw new BuildException("Tool call, toBuffer failed!\n");
98 } catch (Exception e
) {
99 EdkLog
.log("WARNING: Cannot close " + outputFile
.getPath());
105 /// execute external tool for genffsfile
107 private void executeTool () {
109 String argument
= "";
113 // Get each section which under the compress {};
114 // And add it is contains to File;
118 Iterator SectionIter
= this.gensectList
.iterator();
119 while (SectionIter
.hasNext()){
120 sect
= (Section
)SectionIter
.next();
122 // Parse <genSection> element
124 File outputFile
= File
.createTempFile("temp", "sec1", new File(outputPath
));
125 FileOutputStream bo
= new FileOutputStream(outputFile
);
126 DataOutputStream Do
= new DataOutputStream (bo
);
128 // Call each section class's toBuffer function.
133 catch (BuildException e
) {
134 EdkLog
.log(e
.getMessage());
135 throw new BuildException ("GenSection failed at Tool!");
138 this.tempInputFile
.insFile(outputFile
.getPath());
140 } catch (IOException e
){
141 throw new BuildException ("Gensection failed at tool!");
145 outputFile
= File
.createTempFile("temp", null, new File(outputPath
));
146 argument
= toolArgList
+ inputFiles
.toStringWithSinglepPrefix(" -i ")
147 + tempInputFile
.toString(" ")+ " -o " + outputFile
.getPath();
148 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, command
+ " " + argument
);
150 /// execute command line
152 Process process
= Runtime
.getRuntime().exec(command
+ " " + argument
);
154 Iterator tempFile
= tempInputFile
.getNameList().iterator();
155 while (tempFile
.hasNext()){
156 File file
= new File((String
)tempFile
.next());
161 } catch (Exception e
) {
162 EdkLog
.log(e
.getMessage());
163 throw new BuildException("Execution of externalTool task failed!\n");
168 Add method of ANT task/datatype for nested ToolArg type of element
170 @param toolArg The ToolArg object containing arguments for the tool
172 public void addConfiguredToolArg (ToolArg toolArg
) {
173 toolArgList
.insert(toolArg
);
177 Get method of ANT task/datatype for attribute "OutputPath"
179 @returns The name of output path
181 public String
getOutputPath() {
186 Set method of ANT task/datatype for attribute "OutputPath"
188 @param outputPath The name of output path
190 public void setOutputPath(String outPutPath
) {
191 this.outputPath
= outPutPath
;
195 Get method of ANT task/datatype for attribute "ToolName"
197 @returns The name of the tool.
199 public String
getToolName() {
204 Set method of ANT task/datatype for attribute "ToolName"
206 @param toolName The name of the tool
208 public void setToolName(String toolName
) {
209 this.toolName
= toolName
;
213 Add method of ANT task/datatype for nested Input type of element
215 @param file The Input objec which represents a file
217 public void addConfiguredInput(Input file
) {
218 inputFiles
.insert(file
);
224 // This function is to add instance of Tool to list.
226 // @param tool instance of Tool.
228 // public void addTool(Tool tool){
229 // this.toolList.add(tool);
232 public void addGenSection(GenSectionTask genSect
){
233 this.gensectList
.add(genSect
);