source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 10.4 KB
RevLine 
[14982]1/*
2 * Copyright 2001-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.optional.dotnet;
19
20import org.apache.tools.ant.BuildException;
21
22
23/**
24 * This task compiles Visual Basic.NET source into executables or modules.
25 * The task requires vbc.exe on the execute path, unless it or an equivalent
26 * program is specified in the <tt>executable</tt> parameter
27 *
28 * <p>
29 * All parameters are optional: &lt;vbc/&gt; should suffice to produce a debug
30 * build of all *.vb files.
31 *
32 * <p>
33
34 * The task is a directory based task, so attributes like
35 * <tt>includes=&quot;**\/*.vb&quot;</tt> and
36 * <tt>excludes=&quot;broken.vb&quot;</tt> can be used to control
37 * the files pulled in. By default,
38 * all *.vb files from the project folder down are included in the command.
39 * When this happens the destFile -if not specified-
40 * is taken as the first file in the list, which may be somewhat hard to control.
41 Specifying the output file with <tt>destfile</tt> is prudent.
42 </p>
43 <p>
44 * Also, dependency checking only works if destfile is set.
45 *
46 * <p>For historical reasons the pattern
47 * <code>**</code><code>/*.vb</code> is preset as includes list and
48 * you can not override it with an explicit includes attribute. Use
49 * nested <code>&lt;src&gt;</code> elements instead of the basedir
50 * attribute if you need more control.</p>
51 *
52 * As with &lt;csc&gt; nested <tt>src</tt> filesets of source,
53 * reference filesets, definitions and resources can be provided.
54 *
55 * <p>
56 * Example
57 * </p>
58 * <pre>&lt;vbc
59 * optimize=&quot;true&quot;
60 * debug=&quot;false&quot;
61 * warnLevel=&quot;4&quot;
62 * targetType=&quot;exe&quot;
63 * definitions=&quot;RELEASE&quot;
64 * excludes=&quot;src/unicode_class.vb&quot;
65 * mainClass = &quot;MainApp&quot;
66 * destFile=&quot;NetApp.exe&quot;
67 * optionExplicit=&quot;true&quot;
68 * optionCompare=&quot;text&quot;
69 * references="System.Xml,System.Web.Xml"
70 * &gt;
71 * &lt;reference file="${testCSC.dll}" /&gt;
72 * &lt;define name="RELEASE" /&gt;
73 * &lt;define name="DEBUG" if="debug.property"/&gt;
74 * &lt;define name="def3" unless="def2.property"/&gt;
75 * &lt;/vbc&gt;
76 </pre>
77 * @ant.task name="vbc" category="dotnet"
78 */
79
80public class VisualBasicCompile extends DotnetCompile {
81
82 /**
83 * Compiler option to remove integer checks. Default: false.
84 */
85 private boolean removeIntChecks = false;
86
87 /**
88 * Require explicit declaration of variables? Default: false.
89 */
90 private boolean optionExplicit = false;
91
92 /**
93 * Enforce strict language semantics? Default: false.
94 */
95 private boolean optionStrict = false;
96
97 /**
98 * Whether to compare strings as "text" or "binary". Default: "binary".
99 */
100 private String optionCompare;
101
102 /**
103 * Root namespace for all type declarations.
104 */
105 private String rootNamespace;
106
107 /**
108 * Declare global imports fornamespaces in referenced metadata files.
109 */
110 private String imports;
111
112 /**
113 * Constructor for VisualBasicCompile.
114 */
115 public VisualBasicCompile() {
116 clear();
117 }
118
119 /**
120 * reset all contents.
121 */
122 public void clear() {
123 super.clear();
124 imports = null;
125 rootNamespace = null;
126 optionCompare = null;
127 optionExplicit = false;
128 optionStrict = false;
129 removeIntChecks = false;
130 setExecutable("vbc");
131 }
132
133 /**
134 * get the argument or null for no argument needed
135 * This is overridden from DotnetCompile.java because VBC uses
136 * "/win32resource:" rather than "/win32res:"
137 *
138 *@return The Win32Res Parameter to CSC
139 */
140 protected String getWin32ResParameter() {
141 if (getWin32Res() != null) {
142 return "/win32resource:" + getWin32Res().toString();
143 } else {
144 return null;
145 }
146 }
147
148 /**
149 * Whether to remove integer checks. Default false.
150 * @param flag on/off flag
151 */
152 public void setRemoveIntChecks(boolean flag) {
153 removeIntChecks = flag;
154 }
155
156 /**
157 * Get the flag for removing integer checks.
158 * @return true if flag is turned on
159 */
160 public boolean getRemoveIntChecks() {
161 return removeIntChecks;
162 }
163
164 /**
165 * Form the option string for removeIntChecks.
166 * @return The parameter string.
167 */
168 public String getRemoveIntChecksParameter() {
169 return "/removeintchecks" + (removeIntChecks ? "+" : "-");
170 }
171
172 /**
173 * Whether to require explicit declaration of variables.
174 * @param flag on/off flag
175 */
176 public void setOptionExplicit(boolean flag) {
177 optionExplicit = flag;
178 }
179
180 /**
181 * Get the flag for whether to require explicit declaration of variables.
182 *@return true if flag is turned on
183 */
184 public boolean getOptionExplicit() {
185 return optionExplicit;
186 }
187
188 /**
189 * Form the option string for optionExplicit..
190 * @return The parameter string.
191 */
192 public String getOptionExplicitParameter() {
193 return "/optionexplicit" + (optionExplicit ? "+" : "-");
194 }
195
196 /**
197 * Enforce strict language semantics.
198 * @param flag on/off flag
199 */
200 public void setOptionStrict(boolean flag) {
201 optionStrict = flag;
202 }
203
204 /**
205 * Get the flag for whether to enforce strict language semantics.
206 * @return true if flag is turned on
207 */
208 public boolean getOptionStrict() {
209 return optionStrict;
210 }
211
212 /**
213 * For the option string for optionStrict.
214 * @return The parameter string.
215 */
216 public String getOptionStrictParameter() {
217 return "/optionstrict" + (optionStrict ? "+" : "-");
218 }
219
220
221 /**
222 * Specifies the root namespace for all type declarations.
223 * @param rootNamespace a root namespace.
224 */
225 public void setRootNamespace(String rootNamespace) {
226 this.rootNamespace = rootNamespace;
227 }
228
229
230 /**
231 * Get the root namespace.
232 * @return the root namespace.
233 */
234 public String getRootNamespace() {
235 return this.rootNamespace;
236 }
237
238
239 /**
240 * Form the option string for rootNamespace.
241 * @return the root namespace option string.
242 */
243 protected String getRootNamespaceParameter() {
244 if (rootNamespace != null && rootNamespace.length() != 0) {
245 return "/rootnamespace:" + rootNamespace;
246 } else {
247 return null;
248 }
249 }
250
251
252 /**
253 * Declare global imports for namespaces in referenced metadata files.
254 * @param imports the imports string
255 */
256 public void setImports(String imports) {
257 this.imports = imports;
258 }
259
260
261 /**
262 * Get global imports for namespaces in referenced metadata files.
263 * @return the imports string.
264 */
265 public String getImports() {
266 return this.imports;
267 }
268
269
270 /**
271 * Format the option for imports.
272 * @return the formatted import option.
273 */
274 protected String getImportsParameter() {
275 if (imports != null && imports.length() != 0) {
276 return "/imports:" + imports;
277 } else {
278 return null;
279 }
280 }
281
282
283 /**
284 * Specify binary- or text-style string comparisons. Defaults
285 * to "binary"
286 * @param optionCompare the option compare style. "text" | "binary".
287 */
288 public void setOptionCompare(String optionCompare) {
289 if ("text".equalsIgnoreCase(optionCompare)) {
290 this.optionCompare = "text";
291 } else {
292 this.optionCompare = "binary";
293 }
294 }
295
296
297 /**
298 * "binary" or "text" for the string-comparison style.
299 * @return the option compare style.
300 */
301 public String getOptionCompare() {
302 return this.optionCompare;
303 }
304
305 /**
306 * Format the option for string comparison style.
307 * @return The formatted option.
308 */
309 protected String getOptionCompareParameter() {
310 if (optionCompare != null && "text".equalsIgnoreCase(optionCompare)) {
311 return "/optioncompare:text";
312 } else {
313 return "/optioncompare:binary";
314 }
315 }
316
317 /**
318 * implement VBC commands
319 * @param command
320 */
321 protected void addCompilerSpecificOptions(NetCommand command) {
322 command.addArgument(getRemoveIntChecksParameter());
323 command.addArgument(getImportsParameter());
324 command.addArgument(getOptionExplicitParameter());
325 command.addArgument(getOptionStrictParameter());
326 command.addArgument(getRootNamespaceParameter());
327 command.addArgument(getOptionCompareParameter());
328 }
329
330 /**
331 * Get the delimiter that the compiler uses between references.
332 * For example, c# will return ";"; VB.NET will return ","
333 * @return The string delimiter for the reference string.
334 */
335 public String getReferenceDelimiter() {
336 return ",";
337 }
338
339
340
341 /**
342 * Get the extension of filenames to compile.
343 * @return The string extension of files to compile.
344 */
345 public String getFileExtension() {
346 return "vb";
347 }
348
349 /**
350 * from a resource, get the resource param
351 * @param resource
352 * @return a string containing the resource param, or a null string
353 * to conditionally exclude a resource.
354 */
355 protected String createResourceParameter(DotnetResource resource) {
356 return resource.getVbStyleParameter();
357 }
358
359 /**
360 * validation code
361 * @throws BuildException if validation failed
362 */
363 protected void validate()
364 throws BuildException {
365 super.validate();
366 if (getDestFile() == null) {
367 throw new BuildException("DestFile was not specified");
368 }
369 }
370}
Note: See TracBrowser for help on using the repository browser.