]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/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
;
25 import java
.util
.Random
;
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 int alignment
= 0;
36 private String toolName
= "";
37 private ToolArg toolArgList
= new ToolArg();
38 private Input inputFiles
= new Input();
39 private Input tempInputFile
= new Input();
40 private String outputPath
;
41 private String outputFileName
;
42 private static Random ran
= new Random(9999);
43 private List
<Section
> gensectList
= new ArrayList
<Section
>();
47 @param buffer The buffer to put the result with alignment
49 public void toBuffer (DataOutputStream buffer
){
55 } catch (Exception e
) {
56 throw new BuildException("Call to executeTool failed!\n" + e
.getMessage());
60 /// check if file exist
62 File outputFile
= new File (this.outputFileName
);
63 if (!outputFile
.exists()) {
64 throw new BuildException("The file " + outputFile
.getPath() + " does not exist!\n");
68 /// Read output file and write it's cotains to buffer
70 FileInputStream fs
= null;
71 DataInputStream in
= null;
73 fs
= new FileInputStream (outputFile
);
74 in
= new DataInputStream (fs
);
77 int fileLen
= (int)outputFile
.length();
78 byte[] data
= new byte[fileLen
];
80 buffer
.write(data
, 0, fileLen
);
85 while ((fileLen
& 0x03) != 0) {
89 } catch (Exception e
) {
90 EdkLog
.log(e
.getMessage());
91 throw new BuildException("Tool call, toBuffer failed!\n");
101 } catch (Exception e
) {
102 EdkLog
.log("WARNING: Cannot close " + outputFile
.getPath());
108 /// execute external tool for genffsfile
110 private void executeTool () {
112 String argument
= "";
116 // Get each section which under the compress {};
117 // And add it is contains to File;
121 Iterator SectionIter
= this.gensectList
.iterator();
122 while (SectionIter
.hasNext()){
123 sect
= (Section
)SectionIter
.next();
125 // Parse <genSection> element
127 File outputFile
= File
.createTempFile("temp", "sec1", new File(outputPath
));
128 FileOutputStream bo
= new FileOutputStream(outputFile
);
129 DataOutputStream Do
= new DataOutputStream (bo
);
131 // Call each section class's toBuffer function.
136 catch (BuildException e
) {
137 EdkLog
.log(e
.getMessage());
138 throw new BuildException ("GenSection failed at Tool!");
145 this.tempInputFile
.insFile(outputFile
.getPath());
147 } catch (IOException e
){
148 throw new BuildException ("Gensection failed at tool!");
152 this.outputFileName
= "Temp" + getRand();
153 argument
= toolArgList
+ inputFiles
.toStringWithSinglepPrefix(" -i ")
154 + tempInputFile
.toString(" ")+ " -o " + outputFileName
;
155 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, command
+ " " + argument
);
157 /// execute command line
159 Process process
= Runtime
.getRuntime().exec(command
+ " " + argument
);
161 Iterator tempFile
= tempInputFile
.getNameList().iterator();
162 while (tempFile
.hasNext()){
163 File file
= new File((String
)tempFile
.next());
168 } catch (Exception e
) {
169 EdkLog
.log(e
.getMessage());
170 throw new BuildException("Execution of externalTool task failed!\n");
175 Add method of ANT task/datatype for nested ToolArg type of element
177 @param toolArg The ToolArg object containing arguments for the tool
179 public void addConfiguredToolArg (ToolArg toolArg
) {
180 toolArgList
.insert(toolArg
);
184 Get method of ANT task/datatype for attribute "OutputPath"
186 @returns The name of output path
188 public String
getOutputPath() {
193 Set method of ANT task/datatype for attribute "OutputPath"
195 @param outputPath The name of output path
197 public void setOutputPath(String outPutPath
) {
198 this.outputPath
= outPutPath
;
202 Get method of ANT task/datatype for attribute "ToolName"
204 @returns The name of the tool.
206 public String
getToolName() {
211 Set method of ANT task/datatype for attribute "ToolName"
213 @param toolName The name of the tool
215 public void setToolName(String toolName
) {
216 this.toolName
= toolName
;
220 Add method of ANT task/datatype for nested Input type of element
222 @param file The Input objec which represents a file
224 public void addConfiguredInput(Input file
) {
225 inputFiles
.insert(file
);
231 // This function is to add instance of Tool to list.
233 // @param tool instance of Tool.
235 // public void addTool(Tool tool){
236 // this.toolList.add(tool);
239 public void addGenSection(GenSectionTask genSect
){
240 this.gensectList
.add(genSect
);
246 @returns The random integer.
248 public synchronized int getRand() {
249 return ran
.nextInt();
252 public int getAlignment() {
256 public void setAlignment(int alignment
) {
260 this.alignment
= alignment
;