]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCRC32SectionTask.java
Fix EDKT 188.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenCRC32SectionTask.java
CommitLineData
878ddf1f 1/** @file\r
2 GenCRC32SectionTask class.\r
3\r
4 GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 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.util.*;\r
20import org.apache.tools.ant.Project;\r
21import org.apache.tools.ant.Task;\r
22import org.apache.tools.ant.BuildException;\r
23import org.apache.tools.ant.taskdefs.Execute;\r
24import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
25import org.apache.tools.ant.types.Commandline;\r
26\r
27/**\r
28 GenCRC32SectionTask\r
29 \r
30 GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section. \r
31 \r
32**/\r
33public class GenCRC32SectionTask extends Task implements EfiDefine{\r
34 ///\r
35 /// output file\r
36 ///\r
37 private String outputFile;\r
38 ///\r
39 /// inputFile list\r
40 ///\r
41 private List<Object> inputFileList = new ArrayList<Object>();\r
42 \r
43 ///\r
44 /// Project\r
45 ///\r
46 static private Project project;\r
47 \r
48 /**\r
49 execute\r
50 \r
51 GenCRC32SectionTask execute is to assemble tool command line & execute\r
52 tool command line\r
53 \r
54 @throws BuildException\r
55 **/\r
56 public void execute() throws BuildException {\r
57 \r
58 project = this.getOwningTarget().getProject(); \r
59 ///\r
60 /// absolute path of efi tools\r
61 ///\r
2da8968b 62 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r
878ddf1f 63 String command;\r
64 if (path == null) {\r
fad77353 65 command = "GenCRC32Section";\r
878ddf1f 66 } else {\r
fad77353 67 command = path + "/" + "GenCRC32Section" ;\r
878ddf1f 68 }\r
69 // \r
70 // string line of input files \r
71 // \r
72 String inputFiles = list2Str(inputFileList, ""); \r
73 // \r
74 // assemble argument \r
75 //\r
76 String argument = inputFiles + outputFile; \r
77 // \r
78 // return value of fwimage execution \r
79 //\r
80 int revl = -1; \r
81 \r
82 try {\r
83 Commandline cmdline = new Commandline();\r
84 cmdline.setExecutable(command);\r
85 cmdline.createArgument().setLine(argument);\r
86 \r
87 LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);\r
88 Execute runner = new Execute(streamHandler, null);\r
89 \r
90 runner.setAntRun(project);\r
91 runner.setCommandline(cmdline.getCommandline());\r
219e2247 92 log(Commandline.toString(cmdline.getCommandline()), Project.MSG_VERBOSE);\r
93 log(" ");\r
878ddf1f 94 revl = runner.execute();\r
95 if (EFI_SUCCESS == revl){\r
96 //\r
97 // command execution success \r
98 //\r
3f7b510e 99 log("GenCRC32Section succeeded!", Project.MSG_VERBOSE);\r
219e2247 100 } else {\r
878ddf1f 101 // \r
102 // command execution fail\r
103 //\r
219e2247 104 log("ERROR = " + Integer.toHexString(revl));\r
c59963f5 105 // LAH Added This Line\r
3f7b510e 106 throw new BuildException("GenCRC32Section failed!");\r
878ddf1f 107 }\r
108 } catch (Exception e) {\r
109 throw new BuildException(e.getMessage());\r
219e2247 110 } \r
878ddf1f 111 }\r
112\r
113 /**\r
114 addInputFile\r
115 \r
116 This function is to add a inputFile element into list\r
117 @param inputFile : inputFile element\r
118 **/\r
119 public void addInputfile(InputFile inputFile) {\r
120 inputFileList.add(inputFile);\r
121 }\r
122 \r
123 /**\r
124 get class member "outputFile"\r
125 * @return name of output file\r
126 */\r
127 public String getOutputFile() {\r
128 return this.outputFile;\r
129 }\r
130 /**\r
131 * set class member "outputFile"\r
132 * @param outputFile : outputFile parameter \r
133 */\r
134 public void setOutputFile(String outputFile) {\r
135 this.outputFile = " -o " + outputFile;\r
136 };\r
137 \r
138 /**\r
139 * transfer List to String\r
140 * @param list : nested element list\r
141 * @param tag : interval tag of parameter\r
142 * @return string line of parameters \r
143 */\r
144 private String list2Str(List list, String tag) {\r
145 /*\r
146 * string line for return\r
147 */\r
148 String paraStr = " -i"; \r
149 /*\r
150 * nested element in list\r
151 */\r
152 NestElement element; \r
153 /*\r
154 * iterator of nested element list\r
155 */\r
156 Iterator elementIter = list.iterator(); \r
157 /*\r
158 * string parameter list\r
159 */\r
160 List<Object> strList = new ArrayList<Object>(); \r
161 \r
162 while (elementIter.hasNext()) {\r
163 element = (NestElement) elementIter.next();\r
164 if (null != element.getFile()) {\r
165 FileParser.loadFile(project, strList, element.getFile(), tag);\r
166 } else {\r
167 paraStr = paraStr + element.getName();\r
168 }\r
169 }\r
170 /*\r
171 * iterator of string parameter list\r
172 */\r
173 Iterator strIter = strList.iterator(); \r
174 while (strIter.hasNext()) {\r
175 paraStr = paraStr + " " + strIter.next();\r
176 }\r
177 return paraStr;\r
178 } \r
179}\r