]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | GenSectionTask class.\r | |
3 | \r | |
4 | GenSectionTask is to call GenSection.exe to generate Section.\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 | \r | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import org.apache.tools.ant.Project;\r | |
20 | import org.apache.tools.ant.Task;\r | |
21 | import org.apache.tools.ant.BuildException;\r | |
22 | import org.apache.tools.ant.taskdefs.Execute;\r | |
23 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
24 | import org.apache.tools.ant.types.Commandline;\r | |
25 | \r | |
26 | public class GenSectionTask extends Task implements EfiDefine {\r | |
27 | ///\r | |
28 | /// inputfile name\r | |
29 | ///\r | |
30 | private String inputFile = "";\r | |
31 | ///\r | |
32 | /// outputfile name\r | |
33 | ///\r | |
34 | private String outputFile = "";\r | |
35 | ///\r | |
36 | /// section type\r | |
37 | ///\r | |
38 | private String sectionType = "";\r | |
39 | ///\r | |
40 | /// version number\r | |
41 | ///\r | |
42 | private String versionNum = "";\r | |
43 | ///\r | |
44 | /// interface string\r | |
45 | ///\r | |
46 | private String interfaceString = "";\r | |
47 | \r | |
48 | /**\r | |
49 | execute\r | |
50 | \r | |
51 | GenSectionTaks execute is to assemble tool command line & execute tool\r | |
52 | command line.\r | |
53 | \r | |
54 | @throws BuildException\r | |
55 | **/\r | |
56 | public void execute() throws BuildException {\r | |
57 | String command;\r | |
58 | Project project = this.getOwningTarget().getProject();\r | |
59 | //\r | |
60 | // absolute path of efi tools\r | |
61 | //\r | |
62 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
63 | if (path == null) {\r | |
64 | command = "gensection";\r | |
65 | } else {\r | |
66 | command = path + "/" + "gensection";\r | |
67 | }\r | |
68 | //\r | |
69 | // argument of tools\r | |
70 | //\r | |
71 | String argument = inputFile + outputFile + sectionType + versionNum\r | |
72 | + interfaceString;\r | |
73 | //\r | |
74 | // return value of gensection execution\r | |
75 | //\r | |
76 | int revl = -1;\r | |
77 | \r | |
78 | try {\r | |
79 | Commandline cmdline = new Commandline();\r | |
80 | cmdline.setExecutable(command);\r | |
81 | cmdline.createArgument().setLine(argument);\r | |
82 | \r | |
83 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
84 | Project.MSG_INFO, Project.MSG_WARN);\r | |
85 | Execute runner = new Execute(streamHandler, null);\r | |
86 | \r | |
87 | runner.setAntRun(project);\r | |
88 | runner.setCommandline(cmdline.getCommandline());\r | |
89 | System.out.println(Commandline.toString(cmdline.getCommandline()));\r | |
90 | \r | |
91 | revl = runner.execute();\r | |
92 | if (EFI_SUCCESS == revl) {\r | |
93 | //\r | |
94 | // command execution success\r | |
95 | //\r | |
96 | System.out.println("gensection succeeded!");\r | |
97 | } else {\r | |
98 | //\r | |
99 | // command execution fail\r | |
100 | //\r | |
101 | System.out.println("gensection failed. (error="\r | |
102 | + Integer.toHexString(revl) + ")");\r | |
103 | throw new BuildException("gensection failed. (error="\r | |
104 | + Integer.toHexString(revl) + ")");\r | |
105 | }\r | |
106 | } catch (Exception e) {\r | |
107 | throw new BuildException(e.getMessage());\r | |
108 | }\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | getInputFile\r | |
113 | \r | |
114 | This function is to get class member "inputFile".\r | |
115 | \r | |
116 | @return name of input file\r | |
117 | **/\r | |
118 | public String getInputFile() {\r | |
119 | return this.inputFile;\r | |
120 | }\r | |
121 | \r | |
122 | /**\r | |
123 | setInputFile\r | |
124 | \r | |
125 | This function is to set class member "inputFile".\r | |
126 | \r | |
127 | @param inputFile name of input file\r | |
128 | **/\r | |
129 | public void setInputFile(String inputFile) {\r | |
130 | this.inputFile = " -i " + inputFile;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | getOutputFile\r | |
135 | \r | |
136 | This function is to get class member "outputFile".\r | |
137 | \r | |
138 | @return name of output file\r | |
139 | **/\r | |
140 | public String getOutputFile() {\r | |
141 | return this.outputFile;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | setOutputfile\r | |
146 | \r | |
147 | This function is to set class member "outputFile".\r | |
148 | @param outputFile name of output file\r | |
149 | **/\r | |
150 | public void setOutputfile(String outputFile) {\r | |
151 | this.outputFile = " -o " + outputFile;\r | |
152 | }\r | |
153 | \r | |
154 | /**\r | |
155 | getSectionType\r | |
156 | \r | |
157 | This function is to get class member "sectionType".\r | |
158 | \r | |
159 | @return sectoin type\r | |
160 | **/\r | |
161 | public String getSectionType() {\r | |
162 | return this.sectionType;\r | |
163 | }\r | |
164 | \r | |
165 | /**\r | |
166 | setSectionType\r | |
167 | \r | |
168 | This function is to set class member "sectionType".\r | |
169 | \r | |
170 | @param sectionType section type\r | |
171 | **/\r | |
172 | public void setSectionType(String sectionType) {\r | |
173 | this.sectionType = " -s " + sectionType;\r | |
174 | }\r | |
175 | \r | |
176 | /**\r | |
177 | getVersionNum\r | |
178 | \r | |
179 | This function is to get class member "versionNum".\r | |
180 | @return version number\r | |
181 | **/\r | |
182 | public String getVersionNum() {\r | |
183 | return this.versionNum;\r | |
184 | }\r | |
185 | \r | |
186 | /**\r | |
187 | setVersionNume\r | |
188 | \r | |
189 | This function is to set class member "versionNum".\r | |
190 | @param versionNum version number\r | |
191 | **/\r | |
192 | public void setVersionNum(String versionNum) {\r | |
193 | this.versionNum = " -v " + versionNum;\r | |
194 | }\r | |
195 | \r | |
196 | /**\r | |
197 | getInterfaceString\r | |
198 | \r | |
199 | This function is to get class member "interfaceString".\r | |
200 | @return interface string\r | |
201 | **/\r | |
202 | public String getInterfaceString() {\r | |
203 | return this.interfaceString;\r | |
204 | }\r | |
205 | \r | |
206 | /**\r | |
207 | setInterfaceString\r | |
208 | \r | |
209 | This funcion is to set class member "interfaceString".\r | |
210 | @param interfaceString interface string\r | |
211 | **/\r | |
212 | public void setInterfaceString(String interfaceString) {\r | |
213 | this.interfaceString = " -a " + "\"" + interfaceString + "\"";\r | |
214 | }\r | |
215 | }\r |