]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCRC32SectionTask.java
6754beb6218ccc9d9a840fc3e9e5246475df5d17
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenCRC32SectionTask.java
1 /** @file
2 GenCRC32SectionTask class.
3
4 GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 package org.tianocore.framework.tasks;
18
19 import java.util.*;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.taskdefs.Execute;
24 import org.apache.tools.ant.taskdefs.LogStreamHandler;
25 import org.apache.tools.ant.types.Commandline;
26
27 /**
28 GenCRC32SectionTask
29
30 GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.
31
32 **/
33 public class GenCRC32SectionTask extends Task implements EfiDefine{
34 ///
35 /// output file
36 ///
37 private String outputFile;
38 ///
39 /// inputFile list
40 ///
41 private List<Object> inputFileList = new ArrayList<Object>();
42
43 ///
44 /// Project
45 ///
46 static private Project project;
47
48 /**
49 execute
50
51 GenCRC32SectionTask execute is to assemble tool command line & execute
52 tool command line
53
54 @throws BuildException
55 **/
56 public void execute() throws BuildException {
57
58 project = this.getOwningTarget().getProject();
59 ///
60 /// absolute path of efi tools
61 ///
62 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
63 String command;
64 if (path == null) {
65 command = "GenCRC32Section";
66 } else {
67 command = path + "/" + "GenCRC32Section" ;
68 }
69 //
70 // string line of input files
71 //
72 String inputFiles = list2Str(inputFileList, "");
73 //
74 // assemble argument
75 //
76 String argument = inputFiles + outputFile;
77 //
78 // return value of fwimage execution
79 //
80 int revl = -1;
81
82 try {
83 Commandline cmdline = new Commandline();
84 cmdline.setExecutable(command);
85 cmdline.createArgument().setLine(argument);
86
87 LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
88 Execute runner = new Execute(streamHandler, null);
89
90 runner.setAntRun(project);
91 runner.setCommandline(cmdline.getCommandline());
92 log(Commandline.toString(cmdline.getCommandline()), Project.MSG_VERBOSE);
93 log(" ");
94 revl = runner.execute();
95 if (EFI_SUCCESS == revl){
96 //
97 // command execution success
98 //
99 log("GenCRC32Section succeeded!", Project.MSG_VERBOSE);
100 } else {
101 //
102 // command execution fail
103 //
104 log("ERROR = " + Integer.toHexString(revl));
105 // LAH Added This Line
106 throw new BuildException("GenCRC32Section failed!");
107 }
108 } catch (Exception e) {
109 throw new BuildException(e.getMessage());
110 }
111 }
112
113 /**
114 addInputFile
115
116 This function is to add a inputFile element into list
117 @param inputFile : inputFile element
118 **/
119 public void addInputfile(InputFile inputFile) {
120 inputFileList.add(inputFile);
121 }
122
123 /**
124 get class member "outputFile"
125 * @return name of output file
126 */
127 public String getOutputFile() {
128 return this.outputFile;
129 }
130 /**
131 * set class member "outputFile"
132 * @param outputFile : outputFile parameter
133 */
134 public void setOutputFile(String outputFile) {
135 this.outputFile = " -o " + outputFile;
136 };
137
138 /**
139 * transfer List to String
140 * @param list : nested element list
141 * @param tag : interval tag of parameter
142 * @return string line of parameters
143 */
144 private String list2Str(List list, String tag) {
145 /*
146 * string line for return
147 */
148 String paraStr = " -i";
149 /*
150 * nested element in list
151 */
152 NestElement element;
153 /*
154 * iterator of nested element list
155 */
156 Iterator elementIter = list.iterator();
157 /*
158 * string parameter list
159 */
160 List<Object> strList = new ArrayList<Object>();
161
162 while (elementIter.hasNext()) {
163 element = (NestElement) elementIter.next();
164 if (null != element.getFile()) {
165 FileParser.loadFile(project, strList, element.getFile(), tag);
166 } else {
167 paraStr = paraStr + element.getName();
168 }
169 }
170 /*
171 * iterator of string parameter list
172 */
173 Iterator strIter = strList.iterator();
174 while (strIter.hasNext()) {
175 paraStr = paraStr + " " + strIter.next();
176 }
177 return paraStr;
178 }
179 }