]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java
update GetPerformanceCounterProperties() declare
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenSectionTask.java
... / ...
CommitLineData
1/** @file\r
2 GenSectionTask class.\r
3\r
4 GenSectionTask is to call GenSection.exe to generate Section.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14 \r
15**/\r
16\r
17package org.tianocore.framework.tasks;\r
18\r
19import java.io.ByteArrayOutputStream;\r
20import java.io.DataOutputStream;\r
21import java.io.File;\r
22import java.util.ArrayList;\r
23import java.util.Iterator;\r
24import java.util.List;\r
25\r
26import org.apache.tools.ant.BuildException;\r
27import org.apache.tools.ant.Project;\r
28import org.apache.tools.ant.Task;\r
29import org.apache.tools.ant.taskdefs.Execute;\r
30import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
31import org.apache.tools.ant.types.Commandline;\r
32import org.tianocore.common.logger.EdkLog;\r
33\r
34public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes {\r
35 ///\r
36 /// inputfile name\r
37 ///\r
38 private String inputFile = "";\r
39 ///\r
40 /// \r
41 /// \r
42 private String inputFileName = "";\r
43 ///\r
44 /// outputfile name\r
45 ///\r
46 private String outputFile = "";\r
47 ///\r
48 /// section type\r
49 ///\r
50 private String sectionType = "";\r
51 ///\r
52 /// version number\r
53 ///\r
54 private String versionNum = "";\r
55 ///\r
56 /// interface string\r
57 ///\r
58 private String interfaceString = "";\r
59 ///\r
60 /// Section file list\r
61 ///\r
62 private List<Section> sectFileList = new ArrayList<Section>();\r
63 \r
64 /**\r
65 execute\r
66 \r
67 GenSectionTaks execute is to assemble tool command line & execute tool\r
68 command line.\r
69 \r
70 @throws BuildException\r
71 **/\r
72 public void execute() throws BuildException {\r
73 String command;\r
74 Project project = this.getOwningTarget().getProject();\r
75 //\r
76 // absolute path of efi tools\r
77 //\r
78 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
79 if (path == null) {\r
80 command = "GenSection";\r
81 } else {\r
82 command = path + "/" + "GenSection";\r
83 }\r
84 //\r
85 // argument of tools\r
86 //\r
87 String argument = inputFile + outputFile + " -s "+ sectionType + versionNum\r
88 + interfaceString;\r
89 //\r
90 // return value of gensection execution\r
91 //\r
92 int revl = -1;\r
93\r
94 try {\r
95 Commandline cmdline = new Commandline();\r
96 cmdline.setExecutable(command);\r
97 cmdline.createArgument().setLine(argument);\r
98\r
99 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
100 Project.MSG_INFO, Project.MSG_WARN);\r
101 Execute runner = new Execute(streamHandler, null);\r
102\r
103 runner.setAntRun(project);\r
104 runner.setCommandline(cmdline.getCommandline());\r
105\r
106 EdkLog.log(this, EdkLog.EDK_INFO, inputFileName);\r
107 EdkLog.log(this, EdkLog.EDK_DEBUG, Commandline.toString(cmdline.getCommandline()));\r
108 revl = runner.execute();\r
109 if (EFI_SUCCESS == revl) {\r
110 log("GenSection succeeded!", Project.MSG_VERBOSE);\r
111 } else {\r
112 //\r
113 // command execution fail\r
114 //\r
115 log("ERROR = " + Integer.toHexString(revl));\r
116 throw new BuildException("GenSection failed!");\r
117 }\r
118 } catch (Exception e) {\r
119 throw new BuildException(e.getMessage());\r
120 }\r
121 }\r
122\r
123 /**\r
124 getInputFile\r
125 \r
126 This function is to get class member "inputFile".\r
127 \r
128 @return name of input file\r
129 **/\r
130 public String getInputFile() {\r
131 return this.inputFile;\r
132 }\r
133\r
134 /**\r
135 setInputFile\r
136 \r
137 This function is to set class member "inputFile".\r
138 \r
139 @param inputFile name of input file\r
140 **/\r
141 public void setInputFile(String inputFile) {\r
142 this.inputFileName = (new File(inputFile)).getName();\r
143 this.inputFile = " -i " + inputFile;\r
144 }\r
145\r
146 /**\r
147 getOutputFile\r
148 \r
149 This function is to get class member "outputFile".\r
150 \r
151 @return name of output file\r
152 **/\r
153 public String getOutputFile() {\r
154 return this.outputFile;\r
155 }\r
156\r
157 /**\r
158 setOutputfile\r
159 \r
160 This function is to set class member "outputFile".\r
161 @param outputFile name of output file\r
162 **/\r
163 public void setOutputfile(String outputFile) {\r
164 this.outputFile = " -o " + outputFile;\r
165 }\r
166\r
167 /**\r
168 getSectionType\r
169 \r
170 This function is to get class member "sectionType".\r
171 \r
172 @return sectoin type\r
173 **/\r
174 public String getSectionType() {\r
175 return this.sectionType;\r
176 }\r
177\r
178 /**\r
179 setSectionType\r
180 \r
181 This function is to set class member "sectionType".\r
182 \r
183 @param sectionType section type\r
184 **/\r
185 public void setSectionType(String sectionType) {\r
186 this.sectionType = sectionType;\r
187 }\r
188\r
189 /**\r
190 getVersionNum\r
191 \r
192 This function is to get class member "versionNum".\r
193 @return version number\r
194 **/\r
195 public String getVersionNum() {\r
196 return this.versionNum;\r
197 }\r
198\r
199 /**\r
200 setVersionNume\r
201 \r
202 This function is to set class member "versionNum".\r
203 @param versionNum version number\r
204 **/\r
205 public void setVersionNum(String versionNum) {\r
206 this.versionNum = " -v " + versionNum;\r
207 }\r
208\r
209 /**\r
210 getInterfaceString\r
211 \r
212 This function is to get class member "interfaceString".\r
213 @return interface string\r
214 **/\r
215 public String getInterfaceString() {\r
216 return this.interfaceString;\r
217 }\r
218\r
219 /**\r
220 setInterfaceString\r
221 \r
222 This funcion is to set class member "interfaceString".\r
223 @param interfaceString interface string\r
224 **/\r
225 public void setInterfaceString(String interfaceString) {\r
226 this.interfaceString = " -a " + "\"" + interfaceString + "\"";\r
227 }\r
228 \r
229 /**\r
230 addSectFile\r
231 \r
232 This function is to add sectFile to list.\r
233 \r
234 @param sectFile instance of sectFile.\r
235 **/\r
236 public void addSectFile(SectFile sectFile){\r
237 this.sectFileList.add(sectFile);\r
238 }\r
239\r
240 /**\r
241 setTool\r
242 \r
243 This function is to set the class member "Tool";\r
244 \r
245 @param tool \r
246 **/\r
247 public void addTool(Tool tool) {\r
248 this.sectFileList.add(tool);\r
249 }\r
250 \r
251 /**\r
252 addGenSection\r
253 \r
254 This function is to add GenSectin element to list\r
255 @param task Instance of genSection\r
256 **/\r
257 public void addGenSection(GenSectionTask task){\r
258 this.sectFileList.add(task);\r
259 }\r
260 \r
261 public void toBuffer(DataOutputStream buffer){\r
262 //\r
263 // Search SectionList find earch section and call it's \r
264 // ToBuffer function.\r
265 //\r
266 if (this.sectionType.equalsIgnoreCase("EFI_SECTION_COMPRESSION")){\r
267 Section sect;\r
268 \r
269 //\r
270 // Get section file in compress node.\r
271 //\r
272 try{\r
273 ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
274 DataOutputStream Do = new DataOutputStream (bo);\r
275 \r
276 //\r
277 // Get each section which under the compress {};\r
278 // And add it is contains to File;\r
279 //\r
280 Iterator SectionIter = this.sectFileList.iterator();\r
281 while (SectionIter.hasNext()){\r
282 sect = (Section)SectionIter.next();\r
283 \r
284 //\r
285 // Call each section class's toBuffer function.\r
286 //\r
287 try {\r
288 sect.toBuffer(Do);\r
289 }\r
290 catch (BuildException e) {\r
291 System.out.print(e.getMessage());\r
292 throw new BuildException ("Compress.toBuffer failed at section");\r
293 } \r
294 \r
295 }\r
296 Do.close(); \r
297 \r
298 //\r
299 // Call compress\r
300 //\r
301 byte[] fileBuffer = bo.toByteArray();\r
302 \r
303 synchronized (CompressSection.semaphore) {\r
304 Compress myCompress = new Compress(fileBuffer, fileBuffer.length); \r
305 \r
306 //\r
307 // Add Compress header\r
308 //\r
309 CompressHeader Ch = new CompressHeader();\r
310 Ch.SectionHeader.Size[0] = (byte)((myCompress.outputBuffer.length +\r
311 Ch.GetSize()) &\r
312 0xff\r
313 );\r
314 Ch.SectionHeader.Size[1] = (byte)(((myCompress.outputBuffer.length + \r
315 Ch.GetSize())&\r
316 0xff00) >> 8\r
317 );\r
318 Ch.SectionHeader.Size[2] = (byte)(((myCompress.outputBuffer.length + \r
319 Ch.GetSize()) & \r
320 0xff0000) >> 16\r
321 );\r
322 Ch.SectionHeader.type = (byte) EFI_SECTION_COMPRESSION;\r
323 \r
324 //\r
325 // Note: The compressName was not efsfective now. Using the\r
326 // EFI_STANDARD_COMPRSSION for compressType .\r
327 // That is follow old Genffsfile tools. Some code will be added for \r
328 // the different compressName;\r
329 //\r
330 Ch.UncompressLen = fileBuffer.length;\r
331 Ch.CompressType = EFI_STANDARD_COMPRESSION; \r
332 \r
333 //\r
334 // Change header struct to byte buffer\r
335 //\r
336 byte [] headerBuffer = new byte[Ch.GetSize()];\r
337 Ch.StructToBuffer(headerBuffer);\r
338 \r
339 //\r
340 // First add CompressHeader to Buffer, then add Compress data.\r
341 //\r
342 buffer.write (headerBuffer);\r
343 buffer.write(myCompress.outputBuffer); \r
344 \r
345 //\r
346 // Buffer 4 Byte aligment \r
347 //\r
348 int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
349 \r
350 while ((size & 0x03) != 0){\r
351 size ++;\r
352 buffer.writeByte(0);\r
353 }\r
354 }\r
355 }\r
356 catch (Exception e){\r
357 throw new BuildException("compress.toBuffer failed!\n");\r
358 } \r
359 } else {\r
360 Section sect;\r
361 Iterator sectionIter = this.sectFileList.iterator();\r
362 while (sectionIter.hasNext()) {\r
363 sect = (Section)sectionIter.next(); \r
364 try {\r
365 //\r
366 // The last section don't need 4 byte ffsAligment.\r
367 //\r
368 sect.toBuffer(buffer);\r
369 } catch (Exception e) {\r
370 throw new BuildException (e.getMessage());\r
371 }\r
372 }\r
373 }\r
374 }\r
375}\r