]>
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
.ByteArrayOutputStream
;
17 import java
.io
.DataInputStream
;
18 import java
.io
.DataOutputStream
;
20 import java
.io
.FileInputStream
;
21 import java
.io
.FileOutputStream
;
22 import java
.io
.IOException
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Iterator
;
25 import java
.util
.List
;
27 import org
.apache
.tools
.ant
.BuildException
;
28 import org
.tianocore
.common
.logger
.EdkLog
;
31 Class Tool is to define an external tool to be used for genffsfile
33 public class Tool
implements EfiDefine
, Section
{
35 private String toolName
= "";
36 private ToolArg toolArgList
= new ToolArg();
37 private Input inputFiles
= 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");
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 System
.out
.print(e
.getMessage());
88 throw new BuildException("Tool call, toBuffer failed!\n");
97 } catch (Exception e
) {
98 System
.out
.println("WARNING: Cannot close " + outputFile
.getPath());
104 /// execute external tool for genffsfile
106 private void executeTool () {
108 String argument
= "";
112 // Get each section which under the compress {};
113 // And add it is contains to File;
117 Iterator SectionIter
= this.gensectList
.iterator();
118 while (SectionIter
.hasNext()){
119 sect
= (Section
)SectionIter
.next();
121 // Parse <genSection> element
123 File outputFile
= File
.createTempFile("temp", "sec1", new File(outputPath
));
124 FileOutputStream bo
= new FileOutputStream(outputFile
);
125 DataOutputStream Do
= new DataOutputStream (bo
);
127 // Call each section class's toBuffer function.
132 catch (BuildException e
) {
133 System
.out
.print(e
.getMessage());
134 throw new BuildException ("GenSection failed at Tool!");
137 this.inputFiles
.insFile(outputFile
.getPath());
139 } catch (IOException e
){
140 throw new BuildException ("Gensection failed at tool!");
144 outputFile
= File
.createTempFile("temp", null, new File(outputPath
));
145 argument
= toolArgList
+ inputFiles
.toStringWithSinglepPrefix(" -i ")
146 + " -o " + outputFile
.getPath();
147 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, command
+ " " + argument
);
149 /// execute command line
151 Process process
= Runtime
.getRuntime().exec(command
+ " " + argument
);
153 } catch (Exception e
) {
154 System
.out
.print (e
.getMessage());
155 throw new BuildException("Execution of externalTool task failed!\n");
160 Add method of ANT task/datatype for nested ToolArg type of element
162 @param toolArg The ToolArg object containing arguments for the tool
164 public void addConfiguredToolArg (ToolArg toolArg
) {
165 toolArgList
.insert(toolArg
);
169 Get method of ANT task/datatype for attribute "OutputPath"
171 @returns The name of output path
173 public String
getOutputPath() {
178 Set method of ANT task/datatype for attribute "OutputPath"
180 @param outputPath The name of output path
182 public void setOutputPath(String outPutPath
) {
183 this.outputPath
= outPutPath
;
187 Get method of ANT task/datatype for attribute "ToolName"
189 @returns The name of the tool.
191 public String
getToolName() {
196 Set method of ANT task/datatype for attribute "ToolName"
198 @param toolName The name of the tool
200 public void setToolName(String toolName
) {
201 this.toolName
= toolName
;
205 Add method of ANT task/datatype for nested Input type of element
207 @param file The Input objec which represents a file
209 public void addConfiguredInput(Input file
) {
210 inputFiles
.insert(file
);
216 // This function is to add instance of Tool to list.
218 // @param tool instance of Tool.
220 // public void addTool(Tool tool){
221 // this.toolList.add(tool);
224 public void addGenSection(GenSectionTask genSect
){
225 this.gensectList
.add(genSect
);