]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FwImageTask.java
1.Change environment variable from "Framework_Tools_Path" to "FRAMEWORK_TOOLS_PATH".
[mirror_edk2.git] / Tools / 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 org.apache.tools.ant.Task;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.taskdefs.Execute;
23 import org.apache.tools.ant.taskdefs.LogStreamHandler;
24 import org.apache.tools.ant.types.Commandline;
25 import org.tianocore.build.*;
26
27 /**
28 FwImageTask class.
29
30 FwImageTask is used to call FwImage.ext to generate the FwImage.
31 **/
32 public class FwImageTask extends Task implements EfiDefine{
33 ///
34 /// time&data
35 ///
36 private String time = "";
37 ///
38 /// input PE image
39 ///
40 private String peImage = "";
41 ///
42 /// output EFI image
43 ///
44 private String outImage = "";
45 ///
46 /// component type
47 ///
48 private String componentType = "";
49
50 /**
51 * assemble tool command line & execute tool command line
52 *
53 * @throws BuildException
54 */
55 /**
56 execute
57
58 FwimageTask execute function is to assemble tool command line & execute
59 tool command line
60
61 @throws BuidException
62 **/
63 public void execute() throws BuildException {
64
65 Project 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 = "fwimage";
73 } else {
74 command = path + "/" + "fwimage";
75 }
76 //
77 // argument of tools
78 //
79 String argument = time + componentType + peImage + outImage;
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,
91 Project.MSG_INFO, Project.MSG_WARN);
92 Execute runner = new Execute(streamHandler, null);
93
94 runner.setAntRun(project);
95 runner.setCommandline(cmdline.getCommandline());
96 //System.out.println(Commandline.toString(cmdline.getCommandline()));
97 //GenBuildTask.myLogger.log(Commandline.toString(cmdline.getCommandline()),0);
98 //getProject().log(Commandline.toString(cmdline.getCommandline()));
99 revl = runner.execute();
100 if (EFI_SUCCESS == revl) {
101 //
102 // command execution success
103 //
104 System.out.println("fwimage successed!");
105 } else {
106 //
107 // command execution fail
108 //
109 System.out.println("fwimage failed. (error="
110 + Integer.toHexString(revl) + ")");
111 throw new BuildException("fwimage failed. (error="
112 + Integer.toHexString(revl) + ")");
113
114 }
115 } catch (Exception e) {
116 throw new BuildException(e.getMessage());
117 }
118 }
119
120 /**
121 setTime
122
123 This function is to set operation of class member "time".
124
125 @param time string of time
126 **/
127 public void setTime(String time) {
128 this.time = " -t " + time;
129 }
130
131 /**
132 getTime
133
134 This function is to get class member "time"
135 @return time string of time
136 **/
137 public String getTime() {
138 return this.time;
139 }
140
141 /**
142 getPeImage
143
144 This function is to get class member "peImage".
145 @return name of PE image
146 **/
147 public String getPeImage() {
148 return this.peImage;
149 }
150
151 /**
152 setPeImage
153
154 This function is to set class member "peImage"
155 @param peImage name of PE image
156 **/
157 public void setPeImage(String peImage) {
158 this.peImage = " " + peImage;
159 }
160
161 /**
162 getOutImage
163
164 This function is to get class member "outImage".
165 @return name of output EFI image
166 **/
167 public String getOutImage() {
168 return this.outImage;
169 }
170
171 /**
172 setOutImage
173
174 This function is to set class member "outImage".
175 @param outImage name of output EFI image
176 **/
177 public void setOutImage(String outImage) {
178 this.outImage = " " + outImage;
179 }
180
181 /**
182 getComponentType
183
184 This function is to get class member "componentType".
185
186 @return string of componentType
187 **/
188 public String getComponentType() {
189 return this.componentType;
190 }
191
192 /**
193 setComponentType
194
195 This function is to set class member "componentType".
196 @param componentType string of component type
197 **/
198 public void setComponentType(String componentType) {
199 this.componentType = " " + componentType;
200 }
201 }