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