]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCRC32SectionTask.java
Updated PeiRebase to produce a map file of the relocations done by this tool. This...
[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
219e2247 99 log("gencrc32section succeeded!", Project.MSG_VERBOSE);\r
100 } else {\r
878ddf1f 101 // \r
102 // command execution fail\r
103 //\r
219e2247 104 log("ERROR = " + Integer.toHexString(revl));\r
878ddf1f 105 }\r
106 } catch (Exception e) {\r
107 throw new BuildException(e.getMessage());\r
219e2247 108 } \r
878ddf1f 109 }\r
110\r
111 /**\r
112 addInputFile\r
113 \r
114 This function is to add a inputFile element into list\r
115 @param inputFile : inputFile element\r
116 **/\r
117 public void addInputfile(InputFile inputFile) {\r
118 inputFileList.add(inputFile);\r
119 }\r
120 \r
121 /**\r
122 get class member "outputFile"\r
123 * @return name of output file\r
124 */\r
125 public String getOutputFile() {\r
126 return this.outputFile;\r
127 }\r
128 /**\r
129 * set class member "outputFile"\r
130 * @param outputFile : outputFile parameter \r
131 */\r
132 public void setOutputFile(String outputFile) {\r
133 this.outputFile = " -o " + outputFile;\r
134 };\r
135 \r
136 /**\r
137 * transfer List to String\r
138 * @param list : nested element list\r
139 * @param tag : interval tag of parameter\r
140 * @return string line of parameters \r
141 */\r
142 private String list2Str(List list, String tag) {\r
143 /*\r
144 * string line for return\r
145 */\r
146 String paraStr = " -i"; \r
147 /*\r
148 * nested element in list\r
149 */\r
150 NestElement element; \r
151 /*\r
152 * iterator of nested element list\r
153 */\r
154 Iterator elementIter = list.iterator(); \r
155 /*\r
156 * string parameter list\r
157 */\r
158 List<Object> strList = new ArrayList<Object>(); \r
159 \r
160 while (elementIter.hasNext()) {\r
161 element = (NestElement) elementIter.next();\r
162 if (null != element.getFile()) {\r
163 FileParser.loadFile(project, strList, element.getFile(), tag);\r
164 } else {\r
165 paraStr = paraStr + element.getName();\r
166 }\r
167 }\r
168 /*\r
169 * iterator of string parameter list\r
170 */\r
171 Iterator strIter = strList.iterator(); \r
172 while (strIter.hasNext()) {\r
173 paraStr = paraStr + " " + strIter.next();\r
174 }\r
175 return paraStr;\r
176 } \r
177}\r