]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
90a613f3aa6923e0e284ab0860302eb87aa391c5
[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 /// Output directory
52 ///
53 private String outputDir = ".";
54 ///
55 /// argument list
56 ///
57 LinkedList<String> argList = new LinkedList<String>();
58
59 /**
60 execute
61
62 GenFvImageTask execute is to assemble tool command line & execute tool
63 command line.
64 **/
65 public void execute() throws BuildException {
66 Project project = this.getOwningTarget().getProject();
67 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
68
69 if (path == null) {
70 path = "";
71 } else {
72 path += File.separatorChar;
73 }
74 argList.addFirst(path + toolName);
75
76 /// lauch the program
77 ///
78 ProcessBuilder pb = new ProcessBuilder(argList);
79 pb.directory(new File(outputDir));
80 int exitCode = 0;
81 log((new File(this.infFile)).getName());
82 try {
83 Process cmdProc = pb.start();
84 InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());
85 char[] buf = new char[1024];
86
87 exitCode = cmdProc.waitFor();
88 if (exitCode != 0) {
89 int len = cmdOut.read(buf, 0, 1024);
90 log(new String(buf, 0, len));
91 } else {
92 log("GenFvImage succeeded!", Project.MSG_VERBOSE);
93 }
94 } catch (Exception e) {
95 throw new BuildException(e.getMessage());
96 } finally {
97 if (exitCode != 0) {
98 //throw new BuildException("GenFvImage: failed to generate FV file!");
99 }
100 }
101
102 }
103 /**
104 getInfFile
105
106 This function is to get class member of infFile
107 @return String name of infFile
108 **/
109 public String getInfFile() {
110 return infFile;
111 }
112
113 /**
114 setInfFile
115
116 This function is to set class member of infFile.
117
118 @param infFile name of infFile
119 **/
120 public void setInfFile(String infFile) {
121 this.infFile = infFile;
122 argList.add("-I");
123 argList.add(infFile);
124 }
125
126 /**
127 getOutputDir
128
129 This function is to get output directory.
130
131 @return Path of output directory.
132 **/
133 public String getOutputDir() {
134 return outputDir;
135 }
136
137 /**
138 setOutputDir
139
140 This function is to set output directory.
141
142 @param outputDir The output direcotry.
143 **/
144 public void setOutputDir(String outputDir) {
145 this.outputDir = outputDir;
146 }
147 }