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