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
.util
.ArrayList
;
21 import java
.util
.Iterator
;
22 import java
.util
.List
;
24 import org
.apache
.tools
.ant
.BuildException
;
27 Class Tool is to define an external tool to be used for genffsfile
29 public class Tool
implements EfiDefine
, Section
{
32 List
<Object
> toolArgList
= new ArrayList
<Object
>();
34 String outPutFileName
;
35 List
<Input
> inputFiles
= new ArrayList
<Input
>();
40 @param buffer The buffer to put the result with alignment
42 public void toBuffer (DataOutputStream buffer
, DataOutputStream orgBuffer
){
51 } catch (Exception e
) {
52 throw new BuildException("Call tools failed!\n");
56 /// check if file exist
58 OutputFile
= new File (this.outPutFileName
);
59 long fileLen
= OutputFile
.length();
60 if (!OutputFile
.exists()) {
61 throw new BuildException("The file " + outPutFileName
+ " is not exist!\n");
65 /// Read output file and write it's cotains to buffer
68 FileInputStream fs
= new FileInputStream (this.outPutFileName
);
69 DataInputStream In
= new DataInputStream (fs
);
74 buffer
.writeByte(data
);
76 // Add data to org file
78 orgBuffer
.writeByte(data
);
85 while ((fileLen
& 0x03) != 0) {
88 orgBuffer
.writeByte(0);
92 } catch (Exception e
) {
93 System
.out
.print(e
.getMessage());
94 throw new BuildException("Call tool2buffer failed!\n");
99 /// execute external tool for genffsfile
101 private void executeTool () {
103 String argument
= "";
105 Iterator argIter
= toolArgList
.iterator();
106 Iterator inputIter
= inputFiles
.iterator();
111 /// argument of tools
113 while (argIter
.hasNext()) {
114 toolArg
= (ToolArg
)argIter
.next();
115 argument
= argument
+ toolArg
.getLine() + " ";
120 /// input files for tools
122 argument
= argument
+ "-i ";
123 while (inputIter
.hasNext()) {
124 file
= (Input
)inputIter
.next();
125 argument
= argument
+ file
.getFile() + " ";
128 outPutFileName
= outputPath
+ File
.separatorChar
+ (new File(file
.getFile())).getName() + ".crc";
129 argument
= argument
+ " -o " + outPutFileName
;
134 /// execute command line
136 Process crcProcess
= Runtime
.getRuntime().exec(command
+ " " + argument
);
137 crcProcess
.waitFor();
138 } catch (Exception e
) {
139 System
.out
.print (e
.getMessage());
140 throw new BuildException("Execute tools fails!\n");
145 Add method of ANT task/datatype for nested ToolArg type of element
147 @param toolArg The ToolArg object containing arguments for the tool
149 public void addToolArg (ToolArg toolArg
) {
150 toolArgList
.add (toolArg
);
154 Get method of ANT task/datatype for attribute "OutputPath"
156 @returns The name of output path
158 public String
getOutputPath() {
163 Set method of ANT task/datatype for attribute "OutputPath"
165 @param outputPath The name of output path
167 public void setOutputPath(String outPutPath
) {
168 this.outputPath
= outPutPath
;
172 Get method of ANT task/datatype for attribute "ToolName"
174 @returns The name of the tool.
176 public String
getToolName() {
181 Set method of ANT task/datatype for attribute "ToolName"
183 @param toolName The name of the tool
185 public void setToolName(String toolName
) {
186 this.toolName
= toolName
;
190 Add method of ANT task/datatype for nested Input type of element
192 @param file The Input objec which represents a file
194 public void addInput(Input file
) {
195 inputFiles
.add(file
);