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