KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > dotnet > VisualBasicCompile


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.optional.dotnet;
20
21 import org.apache.tools.ant.BuildException;
22
23
24 /**
25  * This task compiles Visual Basic.NET source into executables or modules.
26  * The task requires vbc.exe on the execute path, unless it or an equivalent
27  * program is specified in the <tt>executable</tt> parameter
28  *
29  * <p>
30  * All parameters are optional: &lt;vbc/&gt; should suffice to produce a debug
31  * build of all *.vb files.
32  *
33  * <p>
34
35  * The task is a directory based task, so attributes like
36  * <tt>includes=&quot;**\/*.vb&quot;</tt> and
37  * <tt>excludes=&quot;broken.vb&quot;</tt> can be used to control
38  * the files pulled in. By default,
39  * all *.vb files from the project folder down are included in the command.
40  * When this happens the destFile -if not specified-
41  * is taken as the first file in the list, which may be somewhat hard to control.
42    Specifying the output file with <tt>destfile</tt> is prudent.
43  </p>
44  <p>
45  * Also, dependency checking only works if destfile is set.
46  *
47  * <p>For historical reasons the pattern
48  * <code>**</code><code>/*.vb</code> is preset as includes list and
49  * you can not override it with an explicit includes attribute. Use
50  * nested <code>&lt;src&gt;</code> elements instead of the basedir
51  * attribute if you need more control.</p>
52  *
53  * As with &lt;csc&gt; nested <tt>src</tt> filesets of source,
54  * reference filesets, definitions and resources can be provided.
55  *
56  * <p>
57  * Example
58  * </p>
59  * <pre>&lt;vbc
60  * optimize=&quot;true&quot;
61  * debug=&quot;false&quot;
62  * warnLevel=&quot;4&quot;
63  * targetType=&quot;exe&quot;
64  * definitions=&quot;RELEASE&quot;
65  * excludes=&quot;src/unicode_class.vb&quot;
66  * mainClass = &quot;MainApp&quot;
67  * destFile=&quot;NetApp.exe&quot;
68  * optionExplicit=&quot;true&quot;
69  * optionCompare=&quot;text&quot;
70  * references="System.Xml,System.Web.Xml"
71  * &gt;
72  * &lt;reference file="${testCSC.dll}" /&gt;
73  * &lt;define name="RELEASE" /&gt;
74  * &lt;define name="DEBUG" if="debug.property"/&gt;
75  * &lt;define name="def3" unless="def2.property"/&gt;
76  * &lt;/vbc&gt;
77  </pre>
78  * @ant.task name="vbc" category="dotnet"
79  */

80
81 public class VisualBasicCompile extends DotnetCompile {
82
83     /**
84      * Compiler option to remove integer checks. Default: false.
85      */

86     private boolean removeIntChecks = false;
87
88     /**
89      * Require explicit declaration of variables? Default: false.
90      */

91     private boolean optionExplicit = false;
92
93     /**
94      * Enforce strict language semantics? Default: false.
95      */

96     private boolean optionStrict = false;
97
98     /**
99      * Whether to compare strings as "text" or "binary". Default: "binary".
100      */

101     private String JavaDoc optionCompare;
102
103     /**
104      * Root namespace for all type declarations.
105      */

106     private String JavaDoc rootNamespace;
107
108     /**
109      * Declare global imports fornamespaces in referenced metadata files.
110      */

111     private String JavaDoc imports;
112
113     /**
114      * Constructor for VisualBasicCompile.
115      */

116     public VisualBasicCompile() {
117         clear();
118     }
119
120     /**
121      * reset all contents.
122      */

123     public void clear() {
124         super.clear();
125         imports = null;
126         rootNamespace = null;
127         optionCompare = null;
128         optionExplicit = false;
129         optionStrict = false;
130         removeIntChecks = false;
131         setExecutable("vbc");
132     }
133
134     /**
135      * get the argument or null for no argument needed
136      * This is overridden from DotnetCompile.java because VBC uses
137      * "/win32resource:" rather than "/win32res:"
138      *
139      *@return The Win32Res Parameter to CSC
140      */

141     protected String JavaDoc getWin32ResParameter() {
142         if (getWin32Res() != null) {
143             return "/win32resource:" + getWin32Res().toString();
144         } else {
145             return null;
146         }
147     }
148
149     /**
150      * Whether to remove integer checks. Default false.
151      * @param flag on/off flag
152      */

153     public void setRemoveIntChecks(boolean flag) {
154         removeIntChecks = flag;
155     }
156
157     /**
158      * Get the flag for removing integer checks.
159      * @return true if flag is turned on
160      */

161     public boolean getRemoveIntChecks() {
162         return removeIntChecks;
163     }
164
165     /**
166      * Form the option string for removeIntChecks.
167      * @return The parameter string.
168      */

169     public String JavaDoc getRemoveIntChecksParameter() {
170         return "/removeintchecks" + (removeIntChecks ? "+" : "-");
171     }
172
173     /**
174      * Whether to require explicit declaration of variables.
175      * @param flag on/off flag
176      */

177     public void setOptionExplicit(boolean flag) {
178         optionExplicit = flag;
179     }
180
181     /**
182      * Get the flag for whether to require explicit declaration of variables.
183      *@return true if flag is turned on
184      */

185     public boolean getOptionExplicit() {
186         return optionExplicit;
187     }
188
189     /**
190      * Form the option string for optionExplicit..
191      * @return The parameter string.
192      */

193     public String JavaDoc getOptionExplicitParameter() {
194         return "/optionexplicit" + (optionExplicit ? "+" : "-");
195     }
196
197     /**
198      * Enforce strict language semantics.
199      * @param flag on/off flag
200      */

201     public void setOptionStrict(boolean flag) {
202         optionStrict = flag;
203     }
204
205     /**
206      * Get the flag for whether to enforce strict language semantics.
207      * @return true if flag is turned on
208      */

209     public boolean getOptionStrict() {
210         return optionStrict;
211     }
212
213     /**
214      * For the option string for optionStrict.
215      * @return The parameter string.
216      */

217     public String JavaDoc getOptionStrictParameter() {
218         return "/optionstrict" + (optionStrict ? "+" : "-");
219     }
220
221
222     /**
223      * Specifies the root namespace for all type declarations.
224      * @param rootNamespace a root namespace.
225      */

226     public void setRootNamespace(String JavaDoc rootNamespace) {
227         this.rootNamespace = rootNamespace;
228     }
229
230
231     /**
232      * Get the root namespace.
233      * @return the root namespace.
234      */

235     public String JavaDoc getRootNamespace() {
236         return this.rootNamespace;
237     }
238
239
240     /**
241      * Form the option string for rootNamespace.
242      * @return the root namespace option string.
243      */

244     protected String JavaDoc getRootNamespaceParameter() {
245         if (rootNamespace != null && rootNamespace.length() != 0) {
246             return "/rootnamespace:" + rootNamespace;
247         } else {
248             return null;
249         }
250     }
251
252
253     /**
254      * Declare global imports for namespaces in referenced metadata files.
255      * @param imports the imports string
256      */

257     public void setImports(String JavaDoc imports) {
258         this.imports = imports;
259     }
260
261
262     /**
263      * Get global imports for namespaces in referenced metadata files.
264      * @return the imports string.
265      */

266     public String JavaDoc getImports() {
267         return this.imports;
268     }
269
270
271     /**
272      * Format the option for imports.
273      * @return the formatted import option.
274      */

275     protected String JavaDoc getImportsParameter() {
276         if (imports != null && imports.length() != 0) {
277             return "/imports:" + imports;
278         } else {
279             return null;
280         }
281     }
282
283
284     /**
285      * Specify binary- or text-style string comparisons. Defaults
286      * to "binary"
287      * @param optionCompare the option compare style. "text" | "binary".
288      */

289     public void setOptionCompare(String JavaDoc optionCompare) {
290         if ("text".equalsIgnoreCase(optionCompare)) {
291             this.optionCompare = "text";
292         } else {
293             this.optionCompare = "binary";
294         }
295     }
296
297
298     /**
299      * "binary" or "text" for the string-comparison style.
300      * @return the option compare style.
301      */

302     public String JavaDoc getOptionCompare() {
303         return this.optionCompare;
304     }
305
306     /**
307      * Format the option for string comparison style.
308      * @return The formatted option.
309      */

310     protected String JavaDoc getOptionCompareParameter() {
311         if (optionCompare != null && "text".equalsIgnoreCase(optionCompare)) {
312             return "/optioncompare:text";
313         } else {
314             return "/optioncompare:binary";
315         }
316     }
317
318     /**
319      * implement VBC commands
320      * @param command the command to set arguements on.
321      */

322     protected void addCompilerSpecificOptions(NetCommand command) {
323         command.addArgument(getRemoveIntChecksParameter());
324         command.addArgument(getImportsParameter());
325         command.addArgument(getOptionExplicitParameter());
326         command.addArgument(getOptionStrictParameter());
327         command.addArgument(getRootNamespaceParameter());
328         command.addArgument(getOptionCompareParameter());
329     }
330
331     /**
332      * Get the delimiter that the compiler uses between references.
333      * For example, c# will return ";"; VB.NET will return ","
334      * @return The string delimiter for the reference string.
335      */

336     public String JavaDoc getReferenceDelimiter() {
337         return ",";
338     }
339
340
341
342     /**
343      * Get the extension of filenames to compile.
344      * @return The string extension of files to compile.
345      */

346     public String JavaDoc getFileExtension() {
347         return "vb";
348     }
349
350     /** {@inheritDoc} */
351     protected void createResourceParameter(NetCommand command, DotnetResource resource) {
352         resource.getParameters(getProject(), command, false);
353     }
354
355     /**
356      * validation code
357      * @throws BuildException if validation failed
358      */

359     protected void validate()
360             throws BuildException {
361         super.validate();
362         if (getDestFile() == null) {
363             throw new BuildException("DestFile was not specified");
364         }
365     }
366 }
367
Popular Tags