]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
6f3cd7bd7b8c9afe49868547ee633a321af70ef5
[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
18 import org.apache.tools.ant.BuildException;
19 import org.apache.tools.ant.Project;
20 import org.apache.tools.ant.Task;
21 import org.apache.tools.ant.taskdefs.Execute;
22 import org.apache.tools.ant.taskdefs.LogStreamHandler;
23 import org.apache.tools.ant.types.Commandline;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
29 import java.lang.ProcessBuilder;
30 import java.util.ArrayList;
31 import java.util.LinkedList;
32 import java.util.List;
33 import java.util.Map;
34
35 /**
36 GenFvImageTask
37
38 GenFvImageTask is to call GenFvImage.exe to generate the FvImage.
39
40 **/
41 public class GenFvImageTask extends Task implements EfiDefine{
42 ///
43 /// tool name
44 ///
45 static final private String toolName = "GenFvImage";
46 ///
47 /// The name of input inf file
48 ///
49 private String infFile="";
50 ///
51 /// The target architecture.
52 ///
53 private String arch="";
54 ///
55 /// Output directory
56 ///
57 private String outputDir = ".";
58 ///
59 /// argument list
60 ///
61 LinkedList<String> argList = new LinkedList<String>();
62
63 /**
64 execute
65
66 GenFvImageTask execute is to assemble tool command line & execute tool
67 command line.
68 **/
69 public void execute() throws BuildException {
70 Project project = this.getOwningTarget().getProject();
71 String path = project.getProperty("env.Framework_Tools_Path");
72 if (path == null) {
73 path = "";
74 } else {
75 path += File.separatorChar;
76 }
77
78 if (arch != null && arch.length() > 0) {
79 argList.addFirst(path + toolName + "_" + arch);
80 } else {
81 argList.addFirst(path + toolName);
82 }
83
84 ///
85 /// lauch the program
86 ///
87 ProcessBuilder pb = new ProcessBuilder(argList);
88 pb.directory(new File(outputDir));
89 int exitCode = 0;
90 try {
91 Process cmdProc = pb.start();
92 InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());
93 char[] buf = new char[1024];
94
95 exitCode = cmdProc.waitFor();
96 if (exitCode != 0) {
97 int len = cmdOut.read(buf, 0, 1024);
98 log(new String(buf, 0, len), Project.MSG_ERR);
99 } else {
100 log("GenFvImage - DONE!", Project.MSG_VERBOSE);
101 }
102 } catch (Exception e) {
103 throw new BuildException(e.getMessage());
104 } finally {
105 if (exitCode != 0) {
106 throw new BuildException("GenFvImage: failed to generate FV file!");
107 }
108 }
109
110 }
111 /**
112 getInfFile
113
114 This function is to get class member of infFile
115 @return String name of infFile
116 **/
117 public String getInfFile() {
118 return infFile;
119 }
120
121 /**
122 setInfFile
123
124 This function is to set class member of infFile.
125
126 @param infFile name of infFile
127 **/
128 public void setInfFile(String infFile) {
129 this.infFile = infFile;
130 argList.add("-I");
131 argList.add(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
155 /**
156 getOutputDir
157
158 This function is to get output directory.
159
160 @return Path of output directory.
161 **/
162 public String getOutputDir() {
163 return outputDir;
164 }
165
166 /**
167 setOutputDir
168
169 This function is to set output directory.
170
171 @param outputDir The output direcotry.
172 **/
173 public void setOutputDir(String outputDir) {
174 this.outputDir = outputDir;
175 }
176 }