|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CompilerConfiguration.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
$Id: CompilerConfiguration.java,v 1.2 2004/04/20 01:32:07 cpoirier Exp $
|
|
3 |
|
|
4 |
Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
|
|
5 |
|
|
6 |
Redistribution and use of this software and associated documentation
|
|
7 |
("Software"), with or without modification, are permitted provided
|
|
8 |
that the following conditions are met:
|
|
9 |
|
|
10 |
1. Redistributions of source code must retain copyright
|
|
11 |
statements and notices. Redistributions must also contain a
|
|
12 |
copy of this document.
|
|
13 |
|
|
14 |
2. Redistributions in binary form must reproduce the
|
|
15 |
above copyright notice, this list of conditions and the
|
|
16 |
following disclaimer in the documentation and/or other
|
|
17 |
materials provided with the distribution.
|
|
18 |
|
|
19 |
3. The name "groovy" must not be used to endorse or promote
|
|
20 |
products derived from this Software without prior written
|
|
21 |
permission of The Codehaus. For written permission,
|
|
22 |
please contact info@codehaus.org.
|
|
23 |
|
|
24 |
4. Products derived from this Software may not be called "groovy"
|
|
25 |
nor may "groovy" appear in their names without prior written
|
|
26 |
permission of The Codehaus. "groovy" is a registered
|
|
27 |
trademark of The Codehaus.
|
|
28 |
|
|
29 |
5. Due credit should be given to The Codehaus -
|
|
30 |
http://groovy.codehaus.org/
|
|
31 |
|
|
32 |
THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
|
|
33 |
``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
|
|
34 |
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
35 |
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
36 |
THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
37 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
38 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
39 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
40 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
41 |
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
42 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
43 |
OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
44 |
|
|
45 |
*/
|
|
46 |
|
|
47 |
package org.codehaus.groovy.control;
|
|
48 |
|
|
49 |
import java.io.File;
|
|
50 |
import java.io.PrintWriter;
|
|
51 |
import java.util.LinkedList;
|
|
52 |
import java.util.List;
|
|
53 |
import java.util.Properties;
|
|
54 |
import java.util.StringTokenizer;
|
|
55 |
|
|
56 |
import org.codehaus.groovy.control.io.NullWriter;
|
|
57 |
import org.codehaus.groovy.control.messages.WarningMessage;
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Compilation control flags and coordination stuff.
|
|
64 |
*
|
|
65 |
* @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
|
|
66 |
*
|
|
67 |
* @version $Id: CompilerConfiguration.java,v 1.2 2004/04/20 01:32:07 cpoirier Exp $
|
|
68 |
*/
|
|
69 |
|
|
70 |
public class CompilerConfiguration |
|
71 |
{ |
|
72 |
public static final CompilerConfiguration DEFAULT = new CompilerConfiguration(); |
|
73 |
|
|
74 |
private int warningLevel; // See WarningMessage for levels |
|
75 |
private String sourceEncoding; // Encoding for source files |
|
76 |
private PrintWriter output; // A PrintWriter for communicating with the user |
|
77 |
private File targetDirectory; // Directory into which to write classes |
|
78 |
private LinkedList classpath; // Classpath for use during compilation |
|
79 |
private boolean verbose; // If true, the compiler should produce action information |
|
80 |
private boolean debug; // If true, debugging code should be activated |
|
81 |
private int tolerance; // The number of non-fatal errors to allow before bailing |
|
82 |
private String scriptBaseClass; // Base class name for scripts (must derive from Script) |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Sets the Flags to defaults.
|
|
88 |
*/
|
|
89 |
|
|
90 | 0 |
public CompilerConfiguration()
|
91 |
{ |
|
92 |
//
|
|
93 |
// Set in safe defaults
|
|
94 |
|
|
95 | 0 |
setWarningLevel( WarningMessage.LIKELY_ERRORS ); |
96 | 0 |
setSourceEncoding( "US-ASCII" );
|
97 | 0 |
setOutput( null );
|
98 | 0 |
setTargetDirectory( (File)null );
|
99 | 0 |
setClasspath( "" );
|
100 | 0 |
setVerbose( false );
|
101 | 0 |
setDebug( false );
|
102 | 0 |
setTolerance( 10 ); |
103 | 0 |
setScriptBaseClass( null );
|
104 |
|
|
105 |
|
|
106 |
//
|
|
107 |
// Try for better defaults, ignore errors.
|
|
108 |
|
|
109 | 0 |
try { setSourceEncoding( System.getProperty("file.encoding", "US-ASCII") ); } catch( Exception e ) {} |
110 | 0 |
try { setOutput( new PrintWriter(System.err) ); } catch( Exception e ) {} |
111 | 0 |
try { setClasspath( System.getProperty("java.class.path") ); } catch( Exception e ) {} |
112 |
|
|
113 | 0 |
try
|
114 |
{ |
|
115 | 0 |
String target = System.getProperty( "groovy.target.directory" );
|
116 | 0 |
if( target != null ) |
117 |
{ |
|
118 | 0 |
setTargetDirectory( target ); |
119 |
} |
|
120 |
} |
|
121 |
catch( Exception e ) {}
|
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
/**
|
|
126 |
* Sets the Flags to the specified configuration, with defaults
|
|
127 |
* for those not supplied.
|
|
128 |
*/
|
|
129 |
|
|
130 | 0 |
public CompilerConfiguration( Properties configuration ) throws ConfigurationException |
131 |
{ |
|
132 | 0 |
this();
|
133 |
|
|
134 | 0 |
String text = null;
|
135 | 0 |
int numeric = 0;
|
136 |
|
|
137 |
|
|
138 |
//
|
|
139 |
// Warning level
|
|
140 |
|
|
141 | 0 |
numeric = getWarningLevel(); |
142 | 0 |
try
|
143 |
{ |
|
144 | 0 |
text = configuration.getProperty( "groovy.warnings", "likely errors" ); |
145 | 0 |
numeric = Integer.parseInt( text ); |
146 |
} |
|
147 |
catch( NumberFormatException e )
|
|
148 |
{ |
|
149 | 0 |
if( text.equals("none") ) |
150 |
{ |
|
151 | 0 |
numeric = WarningMessage.NONE; |
152 |
} |
|
153 | 0 |
else if( text.startsWith("likely") ) |
154 |
{ |
|
155 | 0 |
numeric = WarningMessage.LIKELY_ERRORS; |
156 |
} |
|
157 | 0 |
else if( text.startsWith("possible") ) |
158 |
{ |
|
159 | 0 |
numeric = WarningMessage.POSSIBLE_ERRORS; |
160 |
} |
|
161 | 0 |
else if( text.startsWith("paranoia") ) |
162 |
{ |
|
163 | 0 |
numeric = WarningMessage.PARANOIA; |
164 |
} |
|
165 |
else
|
|
166 |
{ |
|
167 | 0 |
throw new ConfigurationException( "unrecogized groovy.warnings: " + text ); |
168 |
} |
|
169 |
} |
|
170 |
|
|
171 | 0 |
setWarningLevel( numeric ); |
172 |
|
|
173 |
|
|
174 |
//
|
|
175 |
// Source file encoding
|
|
176 |
|
|
177 | 0 |
text = configuration.getProperty( "groovy.source.encoding" );
|
178 | 0 |
if( text != null ) |
179 |
{ |
|
180 | 0 |
setSourceEncoding( text ); |
181 |
} |
|
182 |
|
|
183 |
|
|
184 |
//
|
|
185 |
// Target directory for classes
|
|
186 |
|
|
187 | 0 |
text = configuration.getProperty( "groovy.target.directory" );
|
188 | 0 |
if( text != null ) |
189 |
{ |
|
190 | 0 |
setTargetDirectory( text ); |
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
//
|
|
195 |
// Classpath
|
|
196 |
|
|
197 | 0 |
text = configuration.getProperty( "groovy.classpath" );
|
198 | 0 |
if( text != null ) |
199 |
{ |
|
200 | 0 |
setClasspath( text ); |
201 |
} |
|
202 |
|
|
203 |
|
|
204 |
//
|
|
205 |
// Verbosity
|
|
206 |
|
|
207 | 0 |
text = configuration.getProperty( "groovy.output.verbose" );
|
208 | 0 |
if( text != null && text.equals("true") ) |
209 |
{ |
|
210 | 0 |
setVerbose( true );
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
//
|
|
215 |
// Debugging
|
|
216 |
|
|
217 | 0 |
text = configuration.getProperty( "groovy.output.debug" );
|
218 | 0 |
if( text != null && text.equals("true") ) |
219 |
{ |
|
220 | 0 |
setDebug( true );
|
221 |
} |
|
222 |
|
|
223 |
|
|
224 |
//
|
|
225 |
// Tolerance
|
|
226 |
|
|
227 | 0 |
numeric = 10; |
228 |
|
|
229 | 0 |
try
|
230 |
{ |
|
231 | 0 |
text = configuration.getProperty( "groovy.errors.tolerance", "10" ); |
232 | 0 |
numeric = Integer.parseInt( text ); |
233 |
} |
|
234 |
catch( NumberFormatException e )
|
|
235 |
{ |
|
236 | 0 |
throw new ConfigurationException( e ); |
237 |
} |
|
238 |
|
|
239 | 0 |
setTolerance( numeric ); |
240 |
|
|
241 |
|
|
242 |
//
|
|
243 |
// Script Base Class
|
|
244 |
|
|
245 | 0 |
text = configuration.getProperty( "groovy.script.base" );
|
246 | 0 |
setScriptBaseClass( text ); |
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
/**
|
|
252 |
* Gets the currently configured warning level. See WarningMessage
|
|
253 |
* for level details.
|
|
254 |
*/
|
|
255 |
|
|
256 | 0 |
public int getWarningLevel() |
257 |
{ |
|
258 | 0 |
return this.warningLevel; |
259 |
} |
|
260 |
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Sets the warning level. See WarningMessage for level details.
|
|
264 |
*/
|
|
265 |
|
|
266 | 0 |
public void setWarningLevel( int level ) |
267 |
{ |
|
268 | 0 |
if( level < WarningMessage.NONE || level > WarningMessage.PARANOIA )
|
269 |
{ |
|
270 | 0 |
this.warningLevel = WarningMessage.LIKELY_ERRORS;
|
271 |
} |
|
272 |
else
|
|
273 |
{ |
|
274 | 0 |
this.warningLevel = level;
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
/**
|
|
281 |
* Gets the currently configured source file encoding.
|
|
282 |
*/
|
|
283 |
|
|
284 | 0 |
public String getSourceEncoding()
|
285 |
{ |
|
286 | 0 |
return this.sourceEncoding; |
287 |
} |
|
288 |
|
|
289 |
|
|
290 |
/**
|
|
291 |
* Sets the encoding to be used when reading source files.
|
|
292 |
*/
|
|
293 |
|
|
294 | 0 |
public void setSourceEncoding( String encoding ) |
295 |
{ |
|
296 | 0 |
this.sourceEncoding = encoding;
|
297 |
} |
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
/**
|
|
302 |
* Gets the currently configured output writer.
|
|
303 |
*/
|
|
304 |
|
|
305 | 0 |
public PrintWriter getOutput()
|
306 |
{ |
|
307 | 0 |
return this.output; |
308 |
} |
|
309 |
|
|
310 |
|
|
311 |
/**
|
|
312 |
* Sets the output writer.
|
|
313 |
*/
|
|
314 |
|
|
315 | 0 |
public void setOutput( PrintWriter output ) |
316 |
{ |
|
317 | 0 |
if( this.output == null ) |
318 |
{ |
|
319 | 0 |
this.output = new PrintWriter( NullWriter.DEFAULT ); |
320 |
} |
|
321 |
else
|
|
322 |
{ |
|
323 | 0 |
this.output = output;
|
324 |
} |
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Gets the target directory for writing classes.
|
|
331 |
*/
|
|
332 |
|
|
333 | 0 |
public File getTargetDirectory()
|
334 |
{ |
|
335 | 0 |
return this.targetDirectory; |
336 |
} |
|
337 |
|
|
338 |
|
|
339 |
/**
|
|
340 |
* Sets the target directory.
|
|
341 |
*/
|
|
342 |
|
|
343 | 0 |
public void setTargetDirectory( String directory ) |
344 |
{ |
|
345 | 0 |
if( directory != null && directory.length() > 0 ) |
346 |
{ |
|
347 | 0 |
this.targetDirectory = new File( directory ); |
348 |
} |
|
349 |
else
|
|
350 |
{ |
|
351 | 0 |
this.targetDirectory = null; |
352 |
} |
|
353 |
} |
|
354 |
|
|
355 |
|
|
356 |
/**
|
|
357 |
* Sets the target directory.
|
|
358 |
*/
|
|
359 |
|
|
360 | 0 |
public void setTargetDirectory( File directory ) |
361 |
{ |
|
362 | 0 |
this.targetDirectory = directory;
|
363 |
} |
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
/**
|
|
370 |
* Gets the classpath.
|
|
371 |
*/
|
|
372 |
|
|
373 | 0 |
public List getClasspath()
|
374 |
{ |
|
375 | 0 |
return this.classpath; |
376 |
} |
|
377 |
|
|
378 |
|
|
379 |
/**
|
|
380 |
* Sets the output writer.
|
|
381 |
*/
|
|
382 |
|
|
383 | 0 |
public void setClasspath( String classpath ) |
384 |
{ |
|
385 | 0 |
this.classpath = new LinkedList(); |
386 |
|
|
387 | 0 |
StringTokenizer tokenizer = new StringTokenizer( classpath, File.pathSeparator );
|
388 | 0 |
while( tokenizer.hasMoreTokens() )
|
389 |
{ |
|
390 | 0 |
this.classpath.add( tokenizer.nextToken() );
|
391 |
} |
|
392 |
} |
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
/**
|
|
397 |
* Returns true if verbose operation has been requested.
|
|
398 |
*/
|
|
399 |
|
|
400 | 0 |
public boolean getVerbose() |
401 |
{ |
|
402 | 0 |
return this.verbose; |
403 |
} |
|
404 |
|
|
405 |
|
|
406 |
/**
|
|
407 |
* Turns verbose operation on or off.
|
|
408 |
*/
|
|
409 |
|
|
410 | 0 |
public void setVerbose( boolean verbose ) |
411 |
{ |
|
412 | 0 |
this.verbose = verbose;
|
413 |
} |
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
/**
|
|
418 |
* Returns true if debugging operation has been requested.
|
|
419 |
*/
|
|
420 |
|
|
421 | 0 |
public boolean getDebug() |
422 |
{ |
|
423 | 0 |
return this.debug; |
424 |
} |
|
425 |
|
|
426 |
|
|
427 |
/**
|
|
428 |
* Turns debugging operation on or off.
|
|
429 |
*/
|
|
430 |
|
|
431 | 0 |
public void setDebug( boolean debug ) |
432 |
{ |
|
433 | 0 |
this.debug = debug;
|
434 |
} |
|
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
/**
|
|
440 |
* Returns the requested error tolerance.
|
|
441 |
*/
|
|
442 |
|
|
443 | 0 |
public int getTolerance() |
444 |
{ |
|
445 | 0 |
return this.tolerance; |
446 |
} |
|
447 |
|
|
448 |
|
|
449 |
/**
|
|
450 |
* Sets the error tolerance, which is the number of
|
|
451 |
* non-fatal errors (per unit) that should be tolerated before
|
|
452 |
* compilation is aborted.
|
|
453 |
*/
|
|
454 |
|
|
455 | 0 |
public void setTolerance( int tolerance ) |
456 |
{ |
|
457 | 0 |
this.tolerance = tolerance;
|
458 |
} |
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
/**
|
|
463 |
* Gets the name of the base class for scripts. It must be a subclass
|
|
464 |
* of Script.
|
|
465 |
*/
|
|
466 |
|
|
467 | 0 |
public String getScriptBaseClass()
|
468 |
{ |
|
469 | 0 |
return this.scriptBaseClass; |
470 |
} |
|
471 |
|
|
472 |
|
|
473 |
/**
|
|
474 |
* Sets the name of the base class for scripts. It must be a subclass
|
|
475 |
* of Script.
|
|
476 |
*/
|
|
477 | 0 |
public void setScriptBaseClass( String scriptBaseClass ) |
478 |
{ |
|
479 | 0 |
this.scriptBaseClass = scriptBaseClass;
|
480 |
} |
|
481 |
|
|
482 |
|
|
483 |
} |
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|