]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
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 | |
24 | \r | |
25 | import java.io.File;\r | |
26 | import java.io.InputStreamReader;\r | |
27 | import java.lang.ProcessBuilder;\r | |
28 | import java.util.LinkedList;\r | |
29 | \r | |
30 | import org.tianocore.common.logger.EdkLog;\r | |
31 | \r | |
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 | |
39 | //\r | |
40 | // tool name\r | |
41 | //\r | |
42 | static final private String toolName = "GenFvImage";\r | |
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 | |
50 | private String outputDir = ".";\r | |
51 | \r | |
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 | |
60 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
61 | \r | |
62 | String command;\r | |
63 | if (path == null) {\r | |
64 | command = toolName;\r | |
65 | } else {\r | |
66 | command = path + File.separator + toolName;\r | |
67 | }\r | |
68 | \r | |
69 | String argument = "" + infFile;\r | |
70 | //\r | |
71 | // lauch the program\r | |
72 | //\r | |
73 | int exitCode = 0;\r | |
74 | try {\r | |
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 | |
82 | \r | |
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 | |
93 | if (exitCode != 0) {\r | |
94 | EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));\r | |
95 | } else {\r | |
96 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "GenFvImage succeeded!");\r | |
97 | }\r | |
98 | } catch (Exception e) {\r | |
99 | throw new BuildException(e.getMessage());\r | |
100 | } finally {\r | |
101 | if (exitCode != 0) {\r | |
102 | throw new BuildException("GenFvImage: failed to generate FV file!");\r | |
103 | }\r | |
104 | }\r | |
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 | |
113 | return infFile.getValue();\r | |
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 | |
124 | this.infFile.setArg(" -I ", infFile);\r | |
125 | }\r | |
126 | \r | |
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 | |
148 | }\r |