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