]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SplitfileTask.java
1) Applied ToolArg and FileArg class to represent tool arguments
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / SplitfileTask.java
1 /** @file
2 SplitfileTask class.
3
4 SplitfileTask is used to call splitfile.exe to split input file to 2 output
5 file.
6
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18 package org.tianocore.framework.tasks;
19
20 import java.io.File;
21
22 import org.apache.tools.ant.Task;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.taskdefs.Execute;
26 import org.apache.tools.ant.taskdefs.LogStreamHandler;
27 import org.apache.tools.ant.types.Commandline;
28
29 import org.tianocore.common.logger.EdkLog;
30
31 /**
32 SplitfileTask class.
33
34 SplitfileTask is used to call splitfile.exe to split input file to 2 output
35 file.
36 **/
37 public class SplitfileTask extends Task implements EfiDefine {
38 //
39 // Tool name
40 //
41 private static String toolName = "SplitFile";
42
43 //
44 // input file
45 //
46 private FileArg inputFile = new FileArg();
47
48 //
49 // offset value
50 //
51 private ToolArg offset = new ToolArg();
52
53 //
54 // Output directory
55 //
56 private String outputDir = ".";
57
58 /**
59 execute
60
61 SplitfleTask execute function is to assemble tool command line & execute
62 tool command line
63
64 @throws BuidException
65 **/
66 public void execute() throws BuildException {
67
68 Project project = this.getOwningTarget().getProject();
69
70 //
71 // absolute path of efi tools
72 //
73 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
74 String command;
75 String argument;
76 if (path == null) {
77 command = toolName;
78 } else {
79 command = path + File.separator + toolName;
80 }
81
82 //
83 // argument of tools
84 //
85 argument = "" + inputFile + offset;
86
87 //
88 // return value of fwimage execution
89 //
90 int revl = -1;
91
92 try {
93 Commandline cmdline = new Commandline();
94 cmdline.setExecutable(command);
95 cmdline.createArgument().setLine(argument);
96
97 LogStreamHandler streamHandler = new LogStreamHandler(this,
98 Project.MSG_INFO, Project.MSG_WARN);
99 Execute runner = new Execute(streamHandler, null);
100
101 runner.setAntRun(project);
102 runner.setCommandline(cmdline.getCommandline());
103 runner.setWorkingDirectory(new File(outputDir));
104
105 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
106 String fileName = inputFile.toFileList();
107 EdkLog.log(this, EdkLog.EDK_INFO, fileName + " => " + fileName + "1 " + fileName + "2");
108
109 revl = runner.execute();
110 if (EFI_SUCCESS == revl) {
111 //
112 // command execution success
113 //
114 EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
115 } else {
116 //
117 // command execution fail
118 //
119 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
120 throw new BuildException(toolName + " failed!");
121 }
122 } catch (Exception e) {
123 throw new BuildException(e.getMessage());
124 }
125 }
126
127 /**
128 getInputFile
129
130 This function is to get class member "inputFile".
131
132 @return string of input file name.
133 **/
134 public String getInputFile() {
135 return inputFile.getValue();
136 }
137
138 /**
139 setComponentType
140
141 This function is to set class member "inputFile".
142
143 @param inputFile
144 string of input file name.
145 **/
146 public void setInputFile(String inputFile) {
147 this.inputFile.setArg(" ", inputFile);
148 }
149
150 /**
151 getOffset
152
153 This function is to get class member "offset"
154
155 @return offset value of string.
156 **/
157 public String getOffset() {
158 return offset.getValue();
159 }
160
161 /**
162 setOffset
163
164 This function is to set class member "offset"
165
166 @param offset
167 string of offset value.
168 **/
169 public void setOffset(String offset) {
170 this.offset.setArg(" ", offset);
171 }
172
173 /**
174 getOutputDir
175
176 This function is to get class member "outputDir"
177
178 @return outputDir string of output directory.
179 **/
180 public String getOutputDir() {
181 return outputDir;
182 }
183
184 /**
185 setOutputDir
186
187 This function is to set class member "outputDir"
188
189 @param outputDir
190 string of output directory.
191 **/
192 public void setOutputDir(String outputDir) {
193 this.outputDir = outputDir;
194 }
195 }