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