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