]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SplitfileTask.java
8dbb94b46ec7f03324a0e057d22930361c49496f
[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 import org.tianocore.logger.EdkLog;
29
30 /**
31 SplitfileTask class.
32
33 SplitfileTask is used to call splitfile.exe to split input file to 2 output
34 file.
35 **/
36 public class SplitfileTask extends Task implements EfiDefine {
37 ///
38 /// input file
39 ///
40 private String inputFile = "";
41
42 ///
43 /// offset value
44 ///
45 private String offset = "";
46
47
48 /**
49 * execute
50 *
51 * SplitfleTask execute function is to assemble tool command line & execute
52 * tool command line
53 *
54 * @throws BuidException
55 */
56 public void execute() throws BuildException {
57
58 Project project = this.getOwningTarget().getProject();
59
60 //
61 // set Logger
62 //
63 FrameworkLogger logger = new FrameworkLogger(project, "splitfile");
64 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
65 EdkLog.setLogger(logger);
66
67 //
68 // absolute path of efi tools
69 //
70 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
71 String command;
72 String argument;
73 if (path == null) {
74 command = "SplitFile";
75 } else {
76 command = path + File.separatorChar + "SplitFile";
77 }
78
79 //
80 // argument of tools
81 //
82 argument = inputFile + " " + offset;
83
84 //
85 // return value of fwimage execution
86 //
87 int revl = -1;
88
89 try {
90 Commandline cmdline = new Commandline();
91 cmdline.setExecutable(command);
92 cmdline.createArgument().setLine(argument);
93
94 LogStreamHandler streamHandler = new LogStreamHandler(this,
95 Project.MSG_INFO, Project.MSG_WARN);
96 Execute runner = new Execute(streamHandler, null);
97
98 runner.setAntRun(project);
99 runner.setCommandline(cmdline.getCommandline());
100
101 EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
102 EdkLog.log(EdkLog.EDK_INFO, (new File(this.inputFile)).getName());
103 revl = runner.execute();
104 if (EFI_SUCCESS == revl) {
105 //
106 // command execution success
107 //
108 EdkLog.log(EdkLog.EDK_VERBOSE, "SplitFile succeeded!");
109 } else {
110 //
111 // command execution fail
112 //
113 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
114 throw new BuildException("SplitFile failed!");
115 }
116 } catch (Exception e) {
117 throw new BuildException(e.getMessage());
118 }
119 }
120
121 /**
122 * getInputFile
123 *
124 * This function is to get class member "inputFile".
125 *
126 * @return string of input file name.
127 */
128 public String getInputFile() {
129 return inputFile;
130 }
131
132 /**
133 * setComponentType
134 *
135 * This function is to set class member "inputFile".
136 *
137 * @param inputFile
138 * string of input file name.
139 */
140 public void setInputFile(String inputFile) {
141 this.inputFile = inputFile;
142 }
143
144 /**
145 getOffset
146
147 This function is to get class member "offset"
148
149 @return offset value of string.
150 **/
151 public String getOffset() {
152 return offset;
153 }
154
155 /**
156 setOffset
157
158 This function is to set class member "offset"
159
160 @param offset
161 string of offset value.
162 **/
163 public void setOffset(String offset) {
164 this.offset = offset;
165 }
166
167 }