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