Groovy Documentation

org.codehaus.groovy.control
[Java] Class CompilerConfiguration

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

public class CompilerConfiguration
extends java.lang.Object

Compilation control flags and coordination stuff.

Authors:
Chris Poirier
Jochen Theodorou
Jim White
Cedric Champeau
Version:
\$Id\$


Field Summary
static CompilerConfiguration DEFAULT

A convenience for getting a default configuration.

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

static java.lang.String currentJVMVersion

 
Constructor Summary
CompilerConfiguration()

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
CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)

void configure(java.util.Properties configuration)

java.util.List getClasspath()

Returns true if debugging operation has been requested.

java.util.List getCompilationCustomizers()

boolean getDebug()

Sets the name of the base class for scripts.

java.lang.String getDefaultScriptExtension()

java.util.Set getDisabledGlobalASTTransformations()

java.util.Map getJointCompilationOptions()

Adds compilation customizers to the compilation process.

int getMinimumRecompilationInterval()

java.util.Map getOptimizationOptions()

Returns the list of disabled global AST transformation class names.

java.io.PrintWriter getOutput()

Sets the target directory.

ParserPluginFactory getPluginFactory()

boolean getRecompileGroovySource()

java.lang.String getScriptBaseClass()

java.util.Set getScriptExtensions()

java.lang.String getSourceEncoding()

Gets the target directory for writing classes.

java.lang.String getTargetBytecode()

Gets the optimization options for this configuration.

java.io.File getTargetDirectory()

Sets the classpath.

int getTolerance()

boolean getVerbose()

int getWarningLevel()

Gets the currently configured warning level.

void setClasspath(java.lang.String classpath)

Turns debugging operation on or off.

void setClasspathList(java.util.List parts)

Returns the requested error tolerance.

void setDebug(boolean debug)

void setDefaultScriptExtension(java.lang.String defaultScriptExtension)

void setDisabledGlobalASTTransformations(java.util.Set disabledGlobalASTTransformations)

void setJointCompilationOptions(java.util.Map options)

Returns the list of compilation customizers.

void setMinimumRecompilationInterval(int time)

void setOptimizationOptions(java.util.Map options)

void setOutput(java.io.PrintWriter output)

@return the classpath

void setPluginFactory(ParserPluginFactory pluginFactory)

void setRecompileGroovySource(boolean recompile)

void setScriptBaseClass(java.lang.String scriptBaseClass)

void setScriptExtensions(java.util.Set scriptExtensions)

void setSourceEncoding(java.lang.String encoding)

void setTargetBytecode(java.lang.String version)

Sets the joint compilation options for this configuration.

void setTargetDirectory(java.lang.String directory)

void setTargetDirectory(java.io.File directory)

Returns true if verbose operation has been requested.

void setTolerance(int tolerance)

void setVerbose(boolean verbose)

Gets the name of the base class for scripts.

void setWarningLevel(int level)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

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().


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. *


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. *


currentJVMVersion

public static final java.lang.String currentJVMVersion


 
Constructor Detail

CompilerConfiguration

public CompilerConfiguration()


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 programatically. 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)
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 java.lang.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 this 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 java.lang.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. 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.


 
Method Detail

addCompilationCustomizers

public CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)


configure

public void configure(java.util.Properties configuration)


getClasspath

public java.util.List getClasspath()
Returns true if debugging operation has been requested.


getCompilationCustomizers

public java.util.List getCompilationCustomizers()


getDebug

public boolean getDebug()
Sets the name of the base class for scripts. It must be a subclass of Script.


getDefaultScriptExtension

public java.lang.String getDefaultScriptExtension()


getDisabledGlobalASTTransformations

public java.util.Set getDisabledGlobalASTTransformations()


getJointCompilationOptions

public java.util.Map getJointCompilationOptions()
Adds compilation customizers to the compilation process. A compilation customizer is a class node operation which performs various operations going from adding imports to access control.
Parameters:
customizers - the list of customizers to be added
Returns:
this configuration instance


getMinimumRecompilationInterval

public int getMinimumRecompilationInterval()


getOptimizationOptions

public java.util.Map getOptimizationOptions()
Returns the list of disabled global AST transformation class names.
Returns:
a list of global AST transformation fully qualified class names


getOutput

public java.io.PrintWriter getOutput()
Sets the target directory.


getPluginFactory

public ParserPluginFactory getPluginFactory()


getRecompileGroovySource

public boolean getRecompileGroovySource()


getScriptBaseClass

public java.lang.String getScriptBaseClass()


getScriptExtensions

public java.util.Set getScriptExtensions()


getSourceEncoding

public java.lang.String getSourceEncoding()
Gets the target directory for writing classes.


getTargetBytecode

public java.lang.String getTargetBytecode()
Gets the optimization options for this configuration.
Returns:
the options (always not null)


getTargetDirectory

public java.io.File getTargetDirectory()
Sets the classpath.


getTolerance

public int getTolerance()


getVerbose

public boolean getVerbose()


getWarningLevel

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


setClasspath

public void setClasspath(java.lang.String classpath)
Turns debugging operation on or off.


setClasspathList

public void setClasspathList(java.util.List parts)
Returns the requested error tolerance.


setDebug

public void setDebug(boolean debug)


setDefaultScriptExtension

public void setDefaultScriptExtension(java.lang.String defaultScriptExtension)


setDisabledGlobalASTTransformations

public void setDisabledGlobalASTTransformations(java.util.Set disabledGlobalASTTransformations)


setJointCompilationOptions

public void setJointCompilationOptions(java.util.Map options)
Returns the list of compilation customizers.
Returns:
the customizers (always not null)


setMinimumRecompilationInterval

public void setMinimumRecompilationInterval(int time)


setOptimizationOptions

public void setOptimizationOptions(java.util.Map options)


setOutput

public void setOutput(java.io.PrintWriter output)
Returns:
the classpath


setPluginFactory

public void setPluginFactory(ParserPluginFactory pluginFactory)


setRecompileGroovySource

public void setRecompileGroovySource(boolean recompile)


setScriptBaseClass

public void setScriptBaseClass(java.lang.String scriptBaseClass)


setScriptExtensions

public void setScriptExtensions(java.util.Set scriptExtensions)


setSourceEncoding

public void setSourceEncoding(java.lang.String encoding)


setTargetBytecode

public void setTargetBytecode(java.lang.String version)
Sets the joint compilation options for this configuration. Using null will disable joint compilation.
Parameters:
options - the options


setTargetDirectory

public void setTargetDirectory(java.lang.String directory)


setTargetDirectory

public void setTargetDirectory(java.io.File directory)
Returns true if verbose operation has been requested.


setTolerance

public void setTolerance(int tolerance)


setVerbose

public void setVerbose(boolean verbose)
Gets the name of the base class for scripts. It must be a subclass of Script.


setWarningLevel

public void setWarningLevel(int level)


 

Groovy Documentation