public class CompilerConfiguration
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
currentJVMVersion |
static CompilerConfiguration |
DEFAULT
A convenience for getting a default configuration.
|
static java.lang.String |
JDK4
This (
"1.4" ) is the value for targetBytecode to compile for a JDK 1.4. |
static java.lang.String |
JDK5
This (
"1.5" ) is the value for targetBytecode to compile for a JDK 1.5. |
static java.lang.String |
JDK6
This (
"1.6" ) is the value for targetBytecode to compile for a JDK 1.6. |
static java.lang.String |
JDK7
This (
"1.7" ) is the value for targetBytecode to compile for a JDK 1.7. |
static java.lang.String |
JDK8
This (
"1.8" ) is the value for targetBytecode to compile for a JDK 1.8. |
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" |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
CompilerConfiguration |
addCompilationCustomizers(CompilationCustomizer... customizers)
Adds compilation customizers to the compilation process.
|
void |
configure(java.util.Properties configuration)
Method to configure a this CompilerConfiguration by using Properties.
|
java.util.List<java.lang.String> |
getClasspath() |
java.util.List<CompilationCustomizer> |
getCompilationCustomizers()
Returns the list of compilation customizers.
|
boolean |
getDebug()
Returns true if debugging operation has been requested.
|
java.lang.String |
getDefaultScriptExtension() |
java.util.Set<java.lang.String> |
getDisabledGlobalASTTransformations()
Returns the list of disabled global AST transformation class names.
|
java.util.Map<java.lang.String,java.lang.Object> |
getJointCompilationOptions()
Gets the joint compilation options for this configuration.
|
int |
getMinimumRecompilationInterval() |
java.util.Map<java.lang.String,java.lang.Boolean> |
getOptimizationOptions()
Gets the optimization options for this configuration.
|
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.util.Set<java.lang.String> |
getScriptExtensions() |
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.
|
int |
getWarningLevel()
Gets the currently configured warning level.
|
static boolean |
isPostJDK5(java.lang.String bytecodeVersion)
Checks if the specified bytecode version string represents a JDK 1.5+ compatible
bytecode version.
|
static boolean |
isPostJDK7(java.lang.String bytecodeVersion)
Checks if the specified bytecode version string represents a JDK 1.7+ compatible
bytecode version.
|
void |
setClasspath(java.lang.String classpath)
Sets the classpath.
|
void |
setClasspathList(java.util.List<java.lang.String> parts)
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 |
setDisabledGlobalASTTransformations(java.util.Set<java.lang.String> disabledGlobalASTTransformations)
Disables global AST transformations.
|
void |
setJointCompilationOptions(java.util.Map<java.lang.String,java.lang.Object> options)
Sets the joint compilation options for this configuration.
|
void |
setMinimumRecompilationInterval(int time) |
void |
setOptimizationOptions(java.util.Map<java.lang.String,java.lang.Boolean> options)
Sets the optimization options for this configuration.
|
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 |
setScriptExtensions(java.util.Set<java.lang.String> scriptExtensions) |
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.
|
public static final java.lang.String JDK4
"1.4"
) is the value for targetBytecode to compile for a JDK 1.4.public static final java.lang.String JDK5
"1.5"
) is the value for targetBytecode to compile for a JDK 1.5.public static final java.lang.String JDK6
"1.6"
) is the value for targetBytecode to compile for a JDK 1.6.public static final java.lang.String JDK7
"1.7"
) is the value for targetBytecode to compile for a JDK 1.7.public static final java.lang.String JDK8
"1.8"
) is the value for targetBytecode to compile for a JDK 1.8.public static final java.lang.String POST_JDK5
"1.5"
) is the value for targetBytecode to compile for a JDK 1.5 or later JVM.public static final java.lang.String PRE_JDK5
"1.4"
) is the value for targetBytecode to compile for a JDK 1.4 JVM.
public static final java.lang.String currentJVMVersion
public static final CompilerConfiguration DEFAULT
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()
.public CompilerConfiguration()
public CompilerConfiguration(CompilerConfiguration configuration)
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);
configuration
- The configuration to copy.public CompilerConfiguration(java.util.Properties configuration) throws ConfigurationException
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
System.getProperties()
).
A safer approach 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 Key | Get/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() |
configuration
- The properties to get flag values from.ConfigurationException
public static boolean isPostJDK5(java.lang.String bytecodeVersion)
bytecodeVersion
- the bytecode version string (1.4, 1.5, 1.6, 1.7 or 1.8)public static boolean isPostJDK7(java.lang.String bytecodeVersion)
bytecodeVersion
- the bytecode version string (1.4, 1.5, 1.6, 1.7 or 1.8)public void configure(java.util.Properties configuration) throws ConfigurationException
CompilerConfiguration(Properties)
.configuration
- The properties to get flag values from.ConfigurationException
public int getWarningLevel()
public void setWarningLevel(int level)
public java.lang.String getSourceEncoding()
public void setSourceEncoding(java.lang.String encoding)
public java.io.PrintWriter getOutput()
public void setOutput(java.io.PrintWriter output)
public java.io.File getTargetDirectory()
public void setTargetDirectory(java.lang.String directory)
public void setTargetDirectory(java.io.File directory)
public java.util.List<java.lang.String> getClasspath()
public void setClasspath(java.lang.String classpath)
public void setClasspathList(java.util.List<java.lang.String> parts)
parts
- list of strings containing the classpath partspublic boolean getVerbose()
public void setVerbose(boolean verbose)
public boolean getDebug()
public void setDebug(boolean debug)
public int getTolerance()
public void setTolerance(int tolerance)
public java.lang.String getScriptBaseClass()
public void setScriptBaseClass(java.lang.String scriptBaseClass)
public ParserPluginFactory getPluginFactory()
public void setPluginFactory(ParserPluginFactory pluginFactory)
public void setScriptExtensions(java.util.Set<java.lang.String> scriptExtensions)
public java.util.Set<java.lang.String> getScriptExtensions()
public java.lang.String getDefaultScriptExtension()
public void setDefaultScriptExtension(java.lang.String defaultScriptExtension)
public void setRecompileGroovySource(boolean recompile)
public boolean getRecompileGroovySource()
public void setMinimumRecompilationInterval(int time)
public int getMinimumRecompilationInterval()
public void setTargetBytecode(java.lang.String version)
version
- the bytecode compatibility modepublic java.lang.String getTargetBytecode()
public java.util.Map<java.lang.String,java.lang.Object> getJointCompilationOptions()
public void setJointCompilationOptions(java.util.Map<java.lang.String,java.lang.Object> options)
options
- the optionspublic java.util.Map<java.lang.String,java.lang.Boolean> getOptimizationOptions()
public void setOptimizationOptions(java.util.Map<java.lang.String,java.lang.Boolean> options)
options
- the options.java.lang.IllegalArgumentException
- if the options are nullpublic CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)
customizers
- the list of customizers to be addedpublic java.util.List<CompilationCustomizer> getCompilationCustomizers()
public java.util.Set<java.lang.String> getDisabledGlobalASTTransformations()
public void setDisabledGlobalASTTransformations(java.util.Set<java.lang.String> disabledGlobalASTTransformations)
ASTTransformationCustomizer
or
using a CompilationUnit.PrimaryClassNodeOperation
, then nothing will prevent
the transformation from being loaded.disabledGlobalASTTransformations
- a set of fully qualified class names of global AST transformations
which should not be loaded.