]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
Modify GenFfsTask to make it don't create ORG file.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / Tool.java
1 /** @file
2 This file is to define nested element which is meant for specifying a tool
3
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
9
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.
12
13 **/
14 package org.tianocore.framework.tasks;
15
16 import java.io.DataInputStream;
17 import java.io.DataOutputStream;
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.apache.tools.ant.BuildException;
25
26 /**
27 Class Tool is to define an external tool to be used for genffsfile
28 **/
29 public class Tool implements EfiDefine, Section {
30
31 String toolName = "";
32 List<Object> toolArgList = new ArrayList<Object>();
33 String outputPath;
34 String outPutFileName ;
35 List<Input> inputFiles = new ArrayList<Input>();
36
37 /**
38 Call extern tool
39
40 @param buffer The buffer to put the result with alignment
41 **/
42 public void toBuffer (DataOutputStream buffer){
43 File OutputFile;
44 byte data;
45
46 ///
47 /// call extern tool
48 ///
49 try {
50 executeTool ();
51 } catch (Exception e) {
52 throw new BuildException("Call to executeTool failed!\n");
53 }
54
55 ///
56 /// check if file exist
57 ///
58 OutputFile = new File (this.outPutFileName);
59 long fileLen = OutputFile.length();
60 if (!OutputFile.exists()) {
61 throw new BuildException("The file " + outPutFileName + " does not exist!\n");
62 }
63
64 ///
65 /// Read output file and write it's cotains to buffer
66 ///
67 try {
68 FileInputStream fs = new FileInputStream (this.outPutFileName);
69 DataInputStream In = new DataInputStream (fs);
70
71 int i = 0;
72 while (i < fileLen) {
73 data = In.readByte();
74 buffer.writeByte(data);
75 i ++;
76 }
77
78 ///
79 /// 4 byte alignment
80 ///
81 while ((fileLen & 0x03) != 0) {
82 fileLen++;
83 buffer.writeByte(0);
84 }
85 In.close();
86
87 } catch (Exception e) {
88 System.out.print(e.getMessage());
89 throw new BuildException("Tool call, toBuffer failed!\n");
90 }
91 }
92
93 ///
94 /// execute external tool for genffsfile
95 ///
96 private void executeTool () {
97 String command = "";
98 String argument = "";
99 command = toolName;
100 Iterator argIter = toolArgList.iterator();
101 Iterator inputIter = inputFiles.iterator();
102 ToolArg toolArg;
103 Input file = null;
104
105 ///
106 /// argument of tools
107 ///
108 while (argIter.hasNext()) {
109 toolArg = (ToolArg)argIter.next();
110 argument = argument + toolArg.getLine() + " ";
111
112 }
113
114 ///
115 /// input files for tools
116 ///
117 argument = argument + "-i ";
118 while (inputIter.hasNext()) {
119 file = (Input)inputIter.next();
120 argument = argument + file.getFile() + " ";
121 }
122
123 outPutFileName = outputPath + File.separatorChar + (new File(file.getFile())).getName() + ".crc";
124 argument = argument + " -o " + outPutFileName;
125
126 try {
127
128 ///
129 /// execute command line
130 ///
131 Process crcProcess = Runtime.getRuntime().exec(command + " " + argument);
132 crcProcess.waitFor();
133 } catch (Exception e) {
134 System.out.print (e.getMessage());
135 throw new BuildException("Execution of externalTool task failed!\n");
136 }
137 }
138
139 /**
140 Add method of ANT task/datatype for nested ToolArg type of element
141
142 @param toolArg The ToolArg object containing arguments for the tool
143 **/
144 public void addToolArg (ToolArg toolArg) {
145 toolArgList.add (toolArg);
146 }
147
148 /**
149 Get method of ANT task/datatype for attribute "OutputPath"
150
151 @returns The name of output path
152 **/
153 public String getOutputPath() {
154 return outputPath;
155 }
156
157 /**
158 Set method of ANT task/datatype for attribute "OutputPath"
159
160 @param outputPath The name of output path
161 **/
162 public void setOutputPath(String outPutPath) {
163 this.outputPath = outPutPath;
164 }
165
166 /**
167 Get method of ANT task/datatype for attribute "ToolName"
168
169 @returns The name of the tool.
170 **/
171 public String getToolName() {
172 return toolName;
173 }
174
175 /**
176 Set method of ANT task/datatype for attribute "ToolName"
177
178 @param toolName The name of the tool
179 **/
180 public void setToolName(String toolName) {
181 this.toolName = toolName;
182 }
183
184 /**
185 Add method of ANT task/datatype for nested Input type of element
186
187 @param file The Input objec which represents a file
188 **/
189 public void addInput(Input file) {
190 inputFiles.add(file);
191 }
192 }
193
194