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