]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/FwImageTask.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / FwImageTask.java
1 /** @file
2 FwImageTask class.
3
4 FwImageTask is used to call FwImage.ext to generate the FwImage.
5
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
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 FwImageTask class.
32
33 FwImageTask is used to call FwImage.ext to generate the FwImage.
34 **/
35 public class FwImageTask extends Task implements EfiDefine {
36 //
37 // fwimage tool name
38 //
39 private static String toolName = "FwImage";
40 //
41 // time&data
42 //
43 private ToolArg time = new ToolArg();
44 //
45 // input PE image
46 //
47 private FileArg peImage = new FileArg();
48 //
49 // output EFI image
50 //
51 private FileArg outImage = new FileArg();
52 //
53 // component type
54 //
55 private ToolArg componentType = new ToolArg();
56
57 /**
58 execute
59
60 FwimageTask execute function is to assemble tool command line & execute
61 tool command line
62
63 @throws BuidException
64 **/
65 public void execute() throws BuildException {
66
67 Project project = this.getOwningTarget().getProject();
68 //
69 // absolute path of efi tools
70 //
71 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
72 String command;
73 if (path == null) {
74 command = toolName;
75 } else {
76 command = path + File.separator + toolName;
77 }
78 //
79 // argument of tools
80 //
81 String argument = "" + time + componentType + peImage + outImage;
82 //
83 // return value of fwimage execution
84 //
85 int revl = -1;
86
87 try {
88 Commandline cmdline = new Commandline();
89 cmdline.setExecutable(command);
90 cmdline.createArgument().setLine(argument);
91
92 LogStreamHandler streamHandler = new LogStreamHandler(this,
93 Project.MSG_INFO, Project.MSG_WARN);
94 Execute runner = new Execute(streamHandler, null);
95
96 runner.setAntRun(project);
97 runner.setCommandline(cmdline.getCommandline());
98
99 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
100 EdkLog.log(this, peImage.toFileList() + " => " + outImage.toFileList());
101
102 revl = runner.execute();
103 if (EFI_SUCCESS == revl) {
104 EdkLog.log(this, EdkLog.EDK_VERBOSE, "FwImage succeeded!");
105 } else {
106 //
107 // command execution fail
108 //
109 EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));
110 throw new BuildException("FwImage failed!");
111 }
112 } catch (Exception e) {
113 throw new BuildException(e.getMessage());
114 }
115 }
116
117 /**
118 setTime
119
120 This function is to set operation of class member "time".
121
122 @param time string of time
123 **/
124 public void setTime(String time) {
125 this.time.setArg(" -t ", time);
126 }
127
128 /**
129 getTime
130
131 This function is to get class member "time"
132 @return time string of time
133 **/
134 public String getTime() {
135 return this.time.getValue();
136 }
137
138 /**
139 getPeImage
140
141 This function is to get class member "peImage".
142 @return name of PE image
143 **/
144 public String getPeImage() {
145 return this.peImage.getValue();
146 }
147
148 /**
149 setPeImage
150
151 This function is to set class member "peImage"
152 @param peImage name of PE image
153 **/
154 public void setPeImage(String peImage) {
155 this.peImage.setArg(" ", peImage);
156 }
157
158 /**
159 getOutImage
160
161 This function is to get class member "outImage".
162 @return name of output EFI image
163 **/
164 public String getOutImage() {
165 return this.outImage.getValue();
166 }
167
168 /**
169 setOutImage
170
171 This function is to set class member "outImage".
172 @param outImage name of output EFI image
173 **/
174 public void setOutImage(String outImage) {
175 this.outImage.setArg(" ", outImage);
176 }
177
178 /**
179 getComponentType
180
181 This function is to get class member "componentType".
182
183 @return string of componentType
184 **/
185 public String getComponentType() {
186 return this.componentType.getValue();
187 }
188
189 /**
190 setComponentType
191
192 This function is to set class member "componentType".
193 @param componentType string of component type
194 **/
195 public void setComponentType(String componentType) {
196 this.componentType.setArg(" ", componentType);
197 }
198 }