]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | GenFvImageTask class.\r | |
3 | \r | |
4 | GenFvImageTask is to call GenFvImage.exe to generate FvImage.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | package org.tianocore.framework.tasks;\r | |
878ddf1f | 17 | \r |
18 | import org.apache.tools.ant.BuildException;\r | |
19 | import org.apache.tools.ant.Project;\r | |
20 | import org.apache.tools.ant.Task;\r | |
93f5dd0a | 21 | import org.apache.tools.ant.taskdefs.Execute;\r |
22 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
23 | import org.apache.tools.ant.types.Commandline;\r | |
878ddf1f | 24 | \r |
a236f1a1 | 25 | import java.io.File;\r |
a236f1a1 | 26 | import java.io.InputStreamReader;\r |
27 | import java.lang.ProcessBuilder;\r | |
a236f1a1 | 28 | import java.util.LinkedList;\r |
a236f1a1 | 29 | \r |
93f5dd0a | 30 | import org.tianocore.common.logger.EdkLog;\r |
31 | \r | |
878ddf1f | 32 | /**\r |
33 | GenFvImageTask\r | |
34 | \r | |
35 | GenFvImageTask is to call GenFvImage.exe to generate the FvImage.\r | |
36 | \r | |
37 | **/\r | |
38 | public class GenFvImageTask extends Task implements EfiDefine{\r | |
93f5dd0a | 39 | //\r |
40 | // tool name\r | |
41 | //\r | |
a236f1a1 | 42 | static final private String toolName = "GenFvImage";\r |
93f5dd0a | 43 | //\r |
44 | // The name of input inf file\r | |
45 | //\r | |
46 | private FileArg infFile = new FileArg();\r | |
47 | //\r | |
48 | // Output directory\r | |
49 | //\r | |
a236f1a1 | 50 | private String outputDir = ".";\r |
a236f1a1 | 51 | \r |
878ddf1f | 52 | /**\r |
53 | execute\r | |
54 | \r | |
55 | GenFvImageTask execute is to assemble tool command line & execute tool\r | |
56 | command line.\r | |
57 | **/\r | |
58 | public void execute() throws BuildException {\r | |
59 | Project project = this.getOwningTarget().getProject();\r | |
2da8968b | 60 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r |
a236f1a1 | 61 | \r |
93f5dd0a | 62 | String command;\r |
a236f1a1 | 63 | if (path == null) {\r |
93f5dd0a | 64 | command = toolName;\r |
a236f1a1 | 65 | } else {\r |
93f5dd0a | 66 | command = path + File.separator + toolName;\r |
878ddf1f | 67 | }\r |
8742c000 | 68 | \r |
93f5dd0a | 69 | String argument = "" + infFile;\r |
70 | //\r | |
71 | // lauch the program\r | |
72 | //\r | |
a236f1a1 | 73 | int exitCode = 0;\r |
878ddf1f | 74 | try {\r |
93f5dd0a | 75 | Commandline cmdline = new Commandline();\r |
76 | cmdline.setExecutable(command);\r | |
77 | cmdline.createArgument().setLine(argument);\r | |
78 | \r | |
79 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
80 | Project.MSG_INFO, Project.MSG_WARN);\r | |
81 | Execute runner = new Execute(streamHandler, null);\r | |
a236f1a1 | 82 | \r |
93f5dd0a | 83 | runner.setAntRun(project);\r |
84 | runner.setCommandline(cmdline.getCommandline());\r | |
85 | runner.setWorkingDirectory(new File(outputDir)); \r | |
86 | //\r | |
87 | // log command line string.\r | |
88 | //\r | |
89 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r | |
90 | EdkLog.log(this, infFile.toFileList());\r | |
91 | \r | |
92 | exitCode = runner.execute();\r | |
a236f1a1 | 93 | if (exitCode != 0) {\r |
93f5dd0a | 94 | EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));\r |
878ddf1f | 95 | } else {\r |
93f5dd0a | 96 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "GenFvImage succeeded!");\r |
878ddf1f | 97 | }\r |
878ddf1f | 98 | } catch (Exception e) {\r |
a236f1a1 | 99 | throw new BuildException(e.getMessage());\r |
100 | } finally {\r | |
101 | if (exitCode != 0) {\r | |
c59963f5 | 102 | throw new BuildException("GenFvImage: failed to generate FV file!");\r |
a236f1a1 | 103 | }\r |
104 | }\r | |
878ddf1f | 105 | }\r |
106 | /**\r | |
107 | getInfFile\r | |
108 | \r | |
109 | This function is to get class member of infFile\r | |
110 | @return String name of infFile\r | |
111 | **/\r | |
112 | public String getInfFile() {\r | |
93f5dd0a | 113 | return infFile.getValue();\r |
878ddf1f | 114 | }\r |
115 | \r | |
116 | /**\r | |
117 | setInfFile\r | |
118 | \r | |
119 | This function is to set class member of infFile.\r | |
120 | \r | |
121 | @param infFile name of infFile\r | |
122 | **/\r | |
123 | public void setInfFile(String infFile) {\r | |
93f5dd0a | 124 | this.infFile.setArg(" -I ", infFile);\r |
878ddf1f | 125 | }\r |
126 | \r | |
a236f1a1 | 127 | /**\r |
128 | getOutputDir\r | |
129 | \r | |
130 | This function is to get output directory.\r | |
131 | \r | |
132 | @return Path of output directory.\r | |
133 | **/\r | |
134 | public String getOutputDir() {\r | |
135 | return outputDir;\r | |
136 | }\r | |
137 | \r | |
138 | /**\r | |
139 | setOutputDir\r | |
140 | \r | |
141 | This function is to set output directory.\r | |
142 | \r | |
143 | @param outputDir The output direcotry.\r | |
144 | **/\r | |
145 | public void setOutputDir(String outputDir) {\r | |
146 | this.outputDir = outputDir;\r | |
147 | }\r | |
8742c000 | 148 | }\r |