]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenCRC32SectionTask.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / 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
0fdb42ac 19import java.io.File;\r
20\r
21import org.apache.tools.ant.BuildException;\r
878ddf1f 22import org.apache.tools.ant.Project;\r
23import org.apache.tools.ant.Task;\r
878ddf1f 24import org.apache.tools.ant.taskdefs.Execute;\r
25import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
26import org.apache.tools.ant.types.Commandline;\r
27\r
0fdb42ac 28import org.tianocore.common.logger.EdkLog;\r
29\r
878ddf1f 30/**\r
31 GenCRC32SectionTask\r
32 \r
33 GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section. \r
34 \r
35**/\r
82810f3b 36public class GenCRC32SectionTask extends Task implements EfiDefine {\r
0fdb42ac 37 //\r
38 // Tool name\r
39 //\r
40 private static String toolName = "GenCRC32Section";\r
41 //\r
42 // output file\r
43 //\r
44 private FileArg outputFile = new FileArg();\r
45 //\r
46 // inputFile list\r
47 //\r
48 private InputFile inputFileList = new InputFile();\r
878ddf1f 49 \r
0fdb42ac 50 //\r
51 // Project\r
52 //\r
878ddf1f 53 static private Project project;\r
54 \r
55 /**\r
56 execute\r
57 \r
58 GenCRC32SectionTask execute is to assemble tool command line & execute\r
59 tool command line\r
60 \r
61 @throws BuildException\r
62 **/\r
63 public void execute() throws BuildException {\r
64 \r
65 project = this.getOwningTarget().getProject(); \r
66 ///\r
67 /// absolute path of efi tools\r
68 ///\r
2da8968b 69 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r
878ddf1f 70 String command;\r
71 if (path == null) {\r
0fdb42ac 72 command = toolName;\r
878ddf1f 73 } else {\r
0fdb42ac 74 command = path + File.separator + toolName ;\r
82810f3b 75 }\r
878ddf1f 76 // \r
77 // assemble argument \r
78 //\r
0fdb42ac 79 String argument = "" + inputFileList.toStringWithSinglepPrefix(" -i ") + outputFile; \r
878ddf1f 80 // \r
81 // return value of fwimage execution \r
82 //\r
83 int revl = -1; \r
84 \r
85 try {\r
86 Commandline cmdline = new Commandline();\r
87 cmdline.setExecutable(command);\r
88 cmdline.createArgument().setLine(argument);\r
89 \r
90 LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);\r
91 Execute runner = new Execute(streamHandler, null);\r
92 \r
93 runner.setAntRun(project);\r
94 runner.setCommandline(cmdline.getCommandline());\r
0fdb42ac 95\r
96 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
97 EdkLog.log(this, inputFileList.toFileList() + " => " + outputFile.toFileList());\r
98\r
878ddf1f 99 revl = runner.execute();\r
100 if (EFI_SUCCESS == revl){\r
101 //\r
102 // command execution success \r
103 //\r
0fdb42ac 104 EdkLog.log(this, toolName + " succeeded!");\r
219e2247 105 } else {\r
878ddf1f 106 // \r
107 // command execution fail\r
108 //\r
0fdb42ac 109 EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));\r
c59963f5 110 // LAH Added This Line\r
0fdb42ac 111 throw new BuildException(toolName + " failed!");\r
878ddf1f 112 }\r
113 } catch (Exception e) {\r
114 throw new BuildException(e.getMessage());\r
219e2247 115 } \r
878ddf1f 116 }\r
117\r
118 /**\r
119 addInputFile\r
120 \r
121 This function is to add a inputFile element into list\r
122 @param inputFile : inputFile element\r
123 **/\r
0fdb42ac 124 public void addConfiguredInputfile(InputFile inputFile) {\r
125 inputFileList.insert(inputFile);\r
878ddf1f 126 }\r
127 \r
128 /**\r
0fdb42ac 129 get class member "outputFile"\r
130 @return name of output file\r
131 **/\r
878ddf1f 132 public String getOutputFile() {\r
0fdb42ac 133 return this.outputFile.getValue();\r
878ddf1f 134 }\r
135 /**\r
0fdb42ac 136 set class member "outputFile"\r
137 @param outputFile : outputFile parameter \r
138 **/\r
878ddf1f 139 public void setOutputFile(String outputFile) {\r
0fdb42ac 140 this.outputFile.setArg(" -o ", outputFile);\r
82810f3b 141 }\r
878ddf1f 142}\r