]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
cba7a4e4bc989053f943ac86d6902a37b389103a
[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
27 import org.tianocore.common.logger.EdkLog;
28
29 /**
30 GenFvImageTask
31
32 GenFvImageTask is to call GenFvImage.exe to generate the FvImage.
33
34 **/
35 public class GenFvImageTask extends Task implements EfiDefine{
36 //
37 // tool name
38 //
39 static final private String toolName = "GenFvImage";
40 //
41 // The name of input inf file
42 //
43 private FileArg infFile = new FileArg();
44 //
45 // Output directory
46 //
47 private String outputDir = ".";
48
49 /**
50 execute
51
52 GenFvImageTask execute is to assemble tool command line & execute tool
53 command line.
54 **/
55 public void execute() throws BuildException {
56 Project project = this.getOwningTarget().getProject();
57 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
58
59 String command;
60 if (path == null) {
61 command = toolName;
62 } else {
63 command = path + File.separator + toolName;
64 }
65
66 String argument = "" + infFile;
67 //
68 // lauch the program
69 //
70 int exitCode = 0;
71 try {
72 Commandline cmdline = new Commandline();
73 cmdline.setExecutable(command);
74 cmdline.createArgument().setLine(argument);
75
76 LogStreamHandler streamHandler = new LogStreamHandler(this,
77 Project.MSG_INFO, Project.MSG_WARN);
78 Execute runner = new Execute(streamHandler, null);
79
80 runner.setAntRun(project);
81 runner.setCommandline(cmdline.getCommandline());
82 runner.setWorkingDirectory(new File(outputDir));
83 //
84 // log command line string.
85 //
86 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
87 EdkLog.log(this, infFile.toFileList());
88
89 exitCode = runner.execute();
90 if (exitCode != 0) {
91 EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));
92 } else {
93 EdkLog.log(this, EdkLog.EDK_VERBOSE, "GenFvImage succeeded!");
94 }
95 } catch (Exception e) {
96 throw new BuildException(e.getMessage());
97 } finally {
98 if (exitCode != 0) {
99 throw new BuildException("GenFvImage: failed to generate FV file!");
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.getValue();
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.setArg(" -I ", infFile);
122 }
123
124 /**
125 getOutputDir
126
127 This function is to get output directory.
128
129 @return Path of output directory.
130 **/
131 public String getOutputDir() {
132 return outputDir;
133 }
134
135 /**
136 setOutputDir
137
138 This function is to set output directory.
139
140 @param outputDir The output direcotry.
141 **/
142 public void setOutputDir(String outputDir) {
143 this.outputDir = outputDir;
144 }
145 }