]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
1f5e4ecf6d8e362e9eae18a7935a2a135c5234ac
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFvImageTask.java
1 /** @file
2 GenFvImageTask class.
3
4 GenFvImageTask is to call GenFvImage.exe to generate FvImage.
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 package org.tianocore.framework.tasks;
17 import java.io.File;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
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
26 /**
27 GenFvImageTask
28
29 GenFvImageTask is to call GenFvImage.exe to generate the FvImage.
30
31 **/
32 public class GenFvImageTask extends Task implements EfiDefine{
33 ///
34 /// The name of input inf file
35 ///
36 private String infFile="";
37 ///
38 /// The target architecture.
39 ///
40 private String arch="";
41
42 /**
43 execute
44
45 GenFvImageTask execute is to assemble tool command line & execute tool
46 command line.
47 **/
48 public void execute() throws BuildException {
49 Project project = this.getOwningTarget().getProject();
50 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
51 String command = "";
52
53 if (path == null){
54 path = "";
55 }else {
56 path = path + File.separatorChar;
57 }
58
59 if (arch.equalsIgnoreCase("")){
60 command = path + "GenFvImage";
61 }
62 if (arch.equalsIgnoreCase("ia32")){
63 command = path + "GenFvImage_IA32";
64 }
65 if (arch.equalsIgnoreCase("x64")){
66 command = path + "GenFvImage_X64";
67 }
68 if (arch.equalsIgnoreCase("ipf")){
69 command = path + "GenFvImage_IPF";
70 }
71 String argument = infFile;
72
73 try {
74
75 Commandline commandLine = new Commandline();
76 commandLine.setExecutable(command);
77 commandLine.createArgument().setLine(argument);
78
79 LogStreamHandler streamHandler = new LogStreamHandler(this,
80 Project.MSG_INFO,
81 Project.MSG_WARN);
82 //
83 // create a execute object and set it's commandline
84 //
85 Execute runner = new Execute(streamHandler,null);
86 runner.setAntRun(project);
87 runner.setCommandline(commandLine.getCommandline());
88 System.out.println(Commandline.toString(commandLine.getCommandline()));
89
90 int revl = -1;
91 //
92 // user execute class call external programs - GenFvImage
93 //
94 revl = runner.execute();
95 //
96 // execute command line success!
97 //
98 if (EFI_SUCCESS == revl){
99 System.out.println("GenFvImage succeeded!");
100 } else {
101
102 //
103 // execute command line failed!
104 //
105 throw new BuildException("GenFvImage failed !(error =" +
106 Integer.toHexString(revl) + ")");
107 }
108
109 } catch (Exception e) {
110 System.out.println(e.getMessage());
111 }
112 }
113 /**
114 getInfFile
115
116 This function is to get class member of infFile
117 @return String name of infFile
118 **/
119 public String getInfFile() {
120 return infFile;
121 }
122
123 /**
124 setInfFile
125
126 This function is to set class member of infFile.
127
128 @param infFile name of infFile
129 **/
130 public void setInfFile(String infFile) {
131 this.infFile = "-I " + infFile;
132 }
133
134 /**
135 getArch
136
137 This function is to get class member of arch.
138 @return The target architecture.
139 **/
140 public String getArch() {
141 return arch;
142 }
143
144 /**
145 setArch
146
147 This function is to set class member of arch.
148
149 @param arch The target architecture.
150 **/
151 public void setArch(String arch) {
152 this.arch = arch;
153 }
154 }