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