org.codehaus.groovy.control
Class CompilerConfiguration

java.lang.Object
  extended by org.codehaus.groovy.control.CompilerConfiguration

public class CompilerConfiguration
extends java.lang.Object

Compilation control flags and coordination stuff.

Version:
$Id: CompilerConfiguration.java 14451 2008-12-16 16:59:00Z blackdrag $
Author:
Chris Poirier, Jochen Theodorou, Jim White

Field Summary
private  java.util.LinkedList classpath
          Classpath for use during compilation
static java.lang.String currentJVMVersion
           
private  boolean debug
          If true, debugging code should be activated
static CompilerConfiguration DEFAULT
          A convenience for getting a default configuration.
private  java.lang.String defaultScriptExtension
          extension used to find a groovy file
private static java.lang.String JDK5_CLASSNAME_CHECK
           
private  java.util.Map jointCompilationOptions
          options for joint compilation (null by default == no joint compilation)
private  int minimumRecompilationInterval
          sets the minimum of time after a script can be recompiled.
private  java.io.PrintWriter output
          A PrintWriter for communicating with the user
private  ParserPluginFactory pluginFactory
           
static java.lang.String POST_JDK5
          This ("1.5") is the value for targetBytecode to compile for a JDK 1.5 or later JVM.
static java.lang.String PRE_JDK5
          This ("1.4") is the value for targetBytecode to compile for a JDK 1.4 JVM.
private  boolean recompileGroovySource
          if set to true recompilation is enabled
private  java.lang.String scriptBaseClass
          Base class name for scripts (must derive from Script)
private  java.lang.String sourceEncoding
          Encoding for source files
private  java.lang.String targetBytecode
          sets the bytecode version target
private  java.io.File targetDirectory
          Directory into which to write classes
private  int tolerance
          The number of non-fatal errors to allow before bailing
private  boolean verbose
          If true, the compiler should produce action information
private  int warningLevel
          See WarningMessage for levels.
 
Constructor Summary
CompilerConfiguration()
          Sets the Flags to defaults.
CompilerConfiguration(CompilerConfiguration configuration)
          Copy constructor.
CompilerConfiguration(java.util.Properties configuration)
          Sets the Flags to the specified configuration, with defaults for those not supplied.
 
Method Summary
 void configure(java.util.Properties configuration)
          Method to configure a this CompilerConfiguration by using Properties.
 java.util.List getClasspath()
          Gets the classpath.
 boolean getDebug()
          Returns true if debugging operation has been requested.
 java.lang.String getDefaultScriptExtension()
           
 java.util.Map getJointCompilationOptions()
          Gets the joint compilation options for this configuration.
 int getMinimumRecompilationInterval()
           
 java.io.PrintWriter getOutput()
          Gets the currently configured output writer.
 ParserPluginFactory getPluginFactory()
           
 boolean getRecompileGroovySource()
           
 java.lang.String getScriptBaseClass()
          Gets the name of the base class for scripts.
 java.lang.String getSourceEncoding()
          Gets the currently configured source file encoding.
 java.lang.String getTargetBytecode()
          Retrieves the compiler bytecode compatibility mode.
 java.io.File getTargetDirectory()
          Gets the target directory for writing classes.
 int getTolerance()
          Returns the requested error tolerance.
 boolean getVerbose()
          Returns true if verbose operation has been requested.
private static java.lang.String getVMVersion()
           
 int getWarningLevel()
          Gets the currently configured warning level.
 void setClasspath(java.lang.String classpath)
          Sets the classpath.
 void setClasspathList(java.util.List l)
          sets the classpath using a list of Strings
 void setDebug(boolean debug)
          Turns debugging operation on or off.
 void setDefaultScriptExtension(java.lang.String defaultScriptExtension)
           
 void setJointCompilationOptions(java.util.Map options)
          Sets the joint compilation options for this configuration.
 void setMinimumRecompilationInterval(int time)
           
 void setOutput(java.io.PrintWriter output)
          Sets the output writer.
 void setPluginFactory(ParserPluginFactory pluginFactory)
           
 void setRecompileGroovySource(boolean recompile)
           
 void setScriptBaseClass(java.lang.String scriptBaseClass)
          Sets the name of the base class for scripts.
 void setSourceEncoding(java.lang.String encoding)
          Sets the encoding to be used when reading source files.
 void setTargetBytecode(java.lang.String version)
          Allow setting the bytecode compatibility.
 void setTargetDirectory(java.io.File directory)
          Sets the target directory.
 void setTargetDirectory(java.lang.String directory)
          Sets the target directory.
 void setTolerance(int tolerance)
          Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.
 void setVerbose(boolean verbose)
          Turns verbose operation on or off.
 void setWarningLevel(int level)
          Sets the warning level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDK5_CLASSNAME_CHECK

private static final java.lang.String JDK5_CLASSNAME_CHECK
See Also:
Constant Field Values

POST_JDK5

public static final java.lang.String POST_JDK5
This ("1.5") is the value for targetBytecode to compile for a JDK 1.5 or later JVM.

See Also:
Constant Field Values

PRE_JDK5

public static final java.lang.String PRE_JDK5
This ("1.4") is the value for targetBytecode to compile for a JDK 1.4 JVM.

See Also:
Constant Field Values

currentJVMVersion

public static final java.lang.String currentJVMVersion

DEFAULT

public static final CompilerConfiguration DEFAULT
A convenience for getting a default configuration. Do not modify it! See CompilerConfiguration(Properties) for an example on how to make a suitable copy to modify. But if you're really starting from a default context, then you probably just want new CompilerConfiguration().


warningLevel

private int warningLevel
See WarningMessage for levels.


sourceEncoding

private java.lang.String sourceEncoding
Encoding for source files


output

private java.io.PrintWriter output
A PrintWriter for communicating with the user


targetDirectory

private java.io.File targetDirectory
Directory into which to write classes


classpath

private java.util.LinkedList classpath
Classpath for use during compilation


verbose

private boolean verbose
If true, the compiler should produce action information


debug

private boolean debug
If true, debugging code should be activated


tolerance

private int tolerance
The number of non-fatal errors to allow before bailing


scriptBaseClass

private java.lang.String scriptBaseClass
Base class name for scripts (must derive from Script)


pluginFactory

private ParserPluginFactory pluginFactory

defaultScriptExtension

private java.lang.String defaultScriptExtension
extension used to find a groovy file


recompileGroovySource

private boolean recompileGroovySource
if set to true recompilation is enabled


minimumRecompilationInterval

private int minimumRecompilationInterval
sets the minimum of time after a script can be recompiled.


targetBytecode

private java.lang.String targetBytecode
sets the bytecode version target


jointCompilationOptions

private java.util.Map jointCompilationOptions
options for joint compilation (null by default == no joint compilation)

Constructor Detail

CompilerConfiguration

public CompilerConfiguration()
Sets the Flags to defaults.


CompilerConfiguration

public CompilerConfiguration(CompilerConfiguration configuration)
Copy constructor. Use this if you have a mostly correct configuration for your compilation but you want to make a some changes programmatically. An important reason to prefer this approach is that your code will most likely be forward compatible with future changes to this configuration API.
An example of this copy constructor at work:
    // In all likelihood there is already a configuration in your code's context
    // for you to copy, but for the sake of this example we'll use the global default.
    CompilerConfiguration myConfiguration = new CompilerConfiguration(CompilerConfiguration.DEFAULT);
    myConfiguration.setDebug(true);

Parameters:
configuration - The configuration to copy.

CompilerConfiguration

public CompilerConfiguration(java.util.Properties configuration)
                      throws ConfigurationException
Sets the Flags to the specified configuration, with defaults for those not supplied. Note that those "defaults" here do not include checking the settings in System.getProperties() in general, only file.encoding, groovy.target.directory and groovy.source.encoding are.
If you want to set a few flags but keep Groovy's default configuration behavior then be sure to make your settings in a Properties that is backed by System.getProperties() (which is done using the CompilerConfiguration(Properties) constructor).
That might be done like this:
    Properties myProperties = new Properties(System.getProperties());
    myProperties.setProperty("groovy.output.debug", "true");
    myConfiguration = new CompilerConfiguration(myProperties);
 
And you also have to contend with a possible SecurityException when getting the system properties (See System.getProperties()).
An safer method would be to copy a default CompilerConfiguration and make your changes there using the setter.
    // In all likelihood there is already a configuration for you to copy,
    // but for the sake of this example we'll use the global default.
    CompilerConfiguration myConfiguration = new CompilerConfiguration(CompilerConfiguration.DEFAULT);
    myConfiguration.setDebug(true);
 
Another reason to use the copy constructor rather than this one is that you must call setOutput(java.io.PrintWriter). Calling setOutput(null) is valid and will set up a PrintWriter to a bit bucket. The copy constructor will of course set the same one as the original.
Property KeyGet/Set Property Name
"groovy.warnings"getWarningLevel()
"groovy.source.encoding"getSourceEncoding()
"groovy.target.directory"getTargetDirectory()
"groovy.target.bytecode"getTargetBytecode()
"groovy.classpath"getClasspath()
"groovy.output.verbose"getVerbose()
"groovy.output.debug"getDebug()
"groovy.errors.tolerance"getTolerance()
"groovy.script.extension"getDefaultScriptExtension()
"groovy.script.base"getScriptBaseClass()
"groovy.recompile"getRecompileGroovySource()
"groovy.recompile.minimumInterval"getMinimumRecompilationInterval()

Parameters:
configuration - The properties to get flag values from.
Throws:
ConfigurationException
Method Detail

configure

public void configure(java.util.Properties configuration)
               throws ConfigurationException
Method to configure a this CompilerConfiguration by using Properties. For a list of available properties look at {link CompilerConfiguration(Properties).

Parameters:
configuration - The properties to get flag values from.
Throws:
ConfigurationException

getWarningLevel

public int getWarningLevel()
Gets the currently configured warning level. See WarningMessage for level details.


setWarningLevel

public void setWarningLevel(int level)
Sets the warning level. See WarningMessage for level details.


getSourceEncoding

public java.lang.String getSourceEncoding()
Gets the currently configured source file encoding.


setSourceEncoding

public void setSourceEncoding(java.lang.String encoding)
Sets the encoding to be used when reading source files.


getOutput

public java.io.PrintWriter getOutput()
Gets the currently configured output writer.


setOutput

public void setOutput(java.io.PrintWriter output)
Sets the output writer.


getTargetDirectory

public java.io.File getTargetDirectory()
Gets the target directory for writing classes.


setTargetDirectory

public void setTargetDirectory(java.lang.String directory)
Sets the target directory.


setTargetDirectory

public void setTargetDirectory(java.io.File directory)
Sets the target directory.


getClasspath

public java.util.List getClasspath()
Gets the classpath.


setClasspath

public void setClasspath(java.lang.String classpath)
Sets the classpath.


setClasspathList

public void setClasspathList(java.util.List l)
sets the classpath using a list of Strings

Parameters:
l - list of strings containg the classpathparts

getVerbose

public boolean getVerbose()
Returns true if verbose operation has been requested.


setVerbose

public void setVerbose(boolean verbose)
Turns verbose operation on or off.


getDebug

public boolean getDebug()
Returns true if debugging operation has been requested.


setDebug

public void setDebug(boolean debug)
Turns debugging operation on or off.


getTolerance

public int getTolerance()
Returns the requested error tolerance.


setTolerance

public void setTolerance(int tolerance)
Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.


getScriptBaseClass

public java.lang.String getScriptBaseClass()
Gets the name of the base class for scripts. It must be a subclass of Script.


setScriptBaseClass

public void setScriptBaseClass(java.lang.String scriptBaseClass)
Sets the name of the base class for scripts. It must be a subclass of Script.


getPluginFactory

public ParserPluginFactory getPluginFactory()

setPluginFactory

public void setPluginFactory(ParserPluginFactory pluginFactory)

getDefaultScriptExtension

public java.lang.String getDefaultScriptExtension()

setDefaultScriptExtension

public void setDefaultScriptExtension(java.lang.String defaultScriptExtension)

setRecompileGroovySource

public void setRecompileGroovySource(boolean recompile)

getRecompileGroovySource

public boolean getRecompileGroovySource()

setMinimumRecompilationInterval

public void setMinimumRecompilationInterval(int time)

getMinimumRecompilationInterval

public int getMinimumRecompilationInterval()

setTargetBytecode

public void setTargetBytecode(java.lang.String version)
Allow setting the bytecode compatibility. The parameter can take one of the values 1.5 or 1.4. If wrong parameter then the value will default to VM determined version.

Parameters:
version - the bytecode compatibility mode

getTargetBytecode

public java.lang.String getTargetBytecode()
Retrieves the compiler bytecode compatibility mode.

Returns:
bytecode compatibility mode. Can be either 1.5 or 1.4.

getVMVersion

private static java.lang.String getVMVersion()

getJointCompilationOptions

public java.util.Map getJointCompilationOptions()
Gets the joint compilation options for this configuration.

Returns:
the options

setJointCompilationOptions

public void setJointCompilationOptions(java.util.Map options)
Sets the joint compilation options for this configuration. Using null will disable joint compilation.

Parameters:
options - the options


Copyright © ${year} The Codehaus. All Rights Reserved.