Package org.codehaus.groovy.control
Class CompilerConfiguration
java.lang.Object
org.codehaus.groovy.control.CompilerConfiguration
Compilation control flags and coordination stuff.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String[]
The valid targetBytecode values.static final String
Deprecated.static final CompilerConfiguration
A convenience for getting a default configuration.static final String
This ("indy"
) is the Optimization Option value for enablinginvokedynamic
complilation.static final String
This ("1.4"
) is the value for targetBytecode to compile for a JDK 1.4.static final String
This ("1.5"
) is the value for targetBytecode to compile for a JDK 1.5.static final String
This ("1.6"
) is the value for targetBytecode to compile for a JDK 1.6.static final String
This ("1.7"
) is the value for targetBytecode to compile for a JDK 1.7.static final String
This ("1.8"
) is the value for targetBytecode to compile for a JDK 1.8.static final String
This ("1.5"
) is the value for targetBytecode to compile for a JDK 1.5 or later JVM.static final String
This ("1.4"
) is the value for targetBytecode to compile for a JDK 1.4 JVM. -
Constructor Summary
ConstructorDescriptionSets the Flags to defaults.CompilerConfiguration
(Properties configuration) Sets the Flags to the specified configuration, with defaults for those not supplied.CompilerConfiguration
(CompilerConfiguration configuration) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddCompilationCustomizers
(CompilationCustomizer... customizers) Adds compilation customizers to the compilation process.void
configure
(Properties configuration) Method to configure a CompilerConfiguration by using Properties.Returns the list of compilation customizers.boolean
getDebug()
Returns true if debugging operation has been requested.Returns the list of disabled global AST transformation class names.Gets the joint compilation options for this configuration.int
Gets the optimization options for this configuration.Deprecated.not used anymoreboolean
Gets the name of the base class for scripts.Gets the currently configured source file encoding.Retrieves the compiler bytecode compatibility level.Gets the target directory for writing classes.int
Returns the requested error tolerance.boolean
Returns true if verbose operation has been requested.int
Gets the currently configured warning level.static boolean
isPostJDK5
(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.static boolean
isPostJDK7
(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.void
setBytecodePostprocessor
(BytecodeProcessor bytecodePostprocessor) void
setClasspath
(String classpath) Sets the classpath.void
setClasspathList
(List<String> parts) sets the classpath using a list of Stringsvoid
setDebug
(boolean debug) Turns debugging operation on or off.void
setDefaultScriptExtension
(String defaultScriptExtension) void
setDisabledGlobalASTTransformations
(Set<String> disabledGlobalASTTransformations) Disables global AST transformations.void
setJointCompilationOptions
(Map<String, Object> options) Sets the joint compilation options for this configuration.void
setMinimumRecompilationInterval
(int time) void
setOptimizationOptions
(Map<String, Boolean> options) Sets the optimization options for this configuration.void
setOutput
(PrintWriter output) Deprecated.not used anymore, has no effectvoid
setPluginFactory
(ParserPluginFactory pluginFactory) void
setRecompileGroovySource
(boolean recompile) void
setScriptBaseClass
(String scriptBaseClass) Sets the name of the base class for scripts.void
setScriptExtensions
(Set<String> scriptExtensions) void
setSourceEncoding
(String encoding) Sets the encoding to be used when reading source files.void
setTargetBytecode
(String version) Allow setting the bytecode compatibility level.void
setTargetDirectory
(File directory) Sets the target directory.void
setTargetDirectory
(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.
-
Field Details
-
INVOKEDYNAMIC
This ("indy"
) is the Optimization Option value for enablinginvokedynamic
complilation.- See Also:
-
JDK4
This ("1.4"
) is the value for targetBytecode to compile for a JDK 1.4.- See Also:
-
JDK5
This ("1.5"
) is the value for targetBytecode to compile for a JDK 1.5.- See Also:
-
JDK6
This ("1.6"
) is the value for targetBytecode to compile for a JDK 1.6.- See Also:
-
JDK7
This ("1.7"
) is the value for targetBytecode to compile for a JDK 1.7.- See Also:
-
JDK8
This ("1.8"
) is the value for targetBytecode to compile for a JDK 1.8.- See Also:
-
ALLOWED_JDKS
The valid targetBytecode values. -
POST_JDK5
This ("1.5"
) is the value for targetBytecode to compile for a JDK 1.5 or later JVM.- See Also:
-
PRE_JDK5
This ("1.4"
) is the value for targetBytecode to compile for a JDK 1.4 JVM.- See Also:
-
CURRENT_JVM_VERSION
Deprecated. -
DEFAULT
A convenience for getting a default configuration. Do not modify it! SeeCompilerConfiguration(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 wantnew CompilerConfiguration()
.
-
-
Constructor Details
-
CompilerConfiguration
public CompilerConfiguration()Sets the Flags to defaults. -
CompilerConfiguration
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
Sets the Flags to the specified configuration, with defaults for those not supplied. Note that those "defaults" here do not include checking the settings inSystem.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 (SeeSystem.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);
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()
- Parameters:
configuration
- The properties to get flag values from.- Throws:
ConfigurationException
-
-
Method Details
-
isPostJDK5
Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.- Parameters:
bytecodeVersion
- the bytecode version string (1.4, 1.5, 1.6, 1.7 or 1.8)- Returns:
- true if the bytecode version is JDK 1.5+
-
isPostJDK7
Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.- Parameters:
bytecodeVersion
- the bytecode version string (1.4, 1.5, 1.6, 1.7 or 1.8)- Returns:
- true if the bytecode version is JDK 1.7+
-
configure
Method to configure a CompilerConfiguration by using Properties. For a list of available properties look atCompilerConfiguration(Properties)
.- Parameters:
configuration
- The properties to get flag values from.- Throws:
ConfigurationException
-
getWarningLevel
public int getWarningLevel()Gets the currently configured warning level. SeeWarningMessage
for level details. -
setWarningLevel
public void setWarningLevel(int level) Sets the warning level. SeeWarningMessage
for level details. -
getSourceEncoding
Gets the currently configured source file encoding. -
setSourceEncoding
Sets the encoding to be used when reading source files. -
getOutput
Deprecated.not used anymoreGets the currently configured output writer. -
setOutput
Deprecated.not used anymore, has no effectSets the output writer. -
getTargetDirectory
Gets the target directory for writing classes. -
setTargetDirectory
Sets the target directory. -
setTargetDirectory
Sets the target directory. -
getClasspath
- Returns:
- the classpath
-
setClasspath
Sets the classpath. -
setClasspathList
sets the classpath using a list of Strings- Parameters:
parts
- list of strings containing the classpath parts
-
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
Gets the name of the base class for scripts. It must be a subclass of Script. -
setScriptBaseClass
Sets the name of the base class for scripts. It must be a subclass of Script. -
getPluginFactory
-
setPluginFactory
-
setScriptExtensions
-
getScriptExtensions
-
getDefaultScriptExtension
-
setDefaultScriptExtension
-
setRecompileGroovySource
public void setRecompileGroovySource(boolean recompile) -
getRecompileGroovySource
public boolean getRecompileGroovySource() -
setMinimumRecompilationInterval
public void setMinimumRecompilationInterval(int time) -
getMinimumRecompilationInterval
public int getMinimumRecompilationInterval() -
setTargetBytecode
Allow setting the bytecode compatibility level. The parameter can take one of the values inALLOWED_JDKS
.- Parameters:
version
- the bytecode compatibility level
-
getTargetBytecode
Retrieves the compiler bytecode compatibility level. Defaults to the minimum officially supported bytecode version for any particular Groovy version.- Returns:
- bytecode compatibility level
-
getJointCompilationOptions
Gets the joint compilation options for this configuration.- Returns:
- the options
-
setJointCompilationOptions
Sets the joint compilation options for this configuration. Using null will disable joint compilation.- Parameters:
options
- the options
-
getOptimizationOptions
Gets the optimization options for this configuration.- Returns:
- the options (always not null)
-
setOptimizationOptions
Sets the optimization options for this configuration. No entry or a true for that entry means to enable that optimization, a false means the optimization is disabled. Valid keys are "all" and "int".- Parameters:
options
- the options.- Throws:
IllegalArgumentException
- if the options are null
-
addCompilationCustomizers
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
-
getCompilationCustomizers
Returns the list of compilation customizers.- Returns:
- the customizers (always not null)
-
getDisabledGlobalASTTransformations
Returns the list of disabled global AST transformation class names.- Returns:
- a list of global AST transformation fully qualified class names
-
setDisabledGlobalASTTransformations
Disables global AST transformations. In order to avoid class loading side effects, it is not recommended to use MyASTTransformation.class.getName() by directly use the class name as a string. Disabled AST transformations only apply to automatically loaded global AST transformations, that is to say transformations defined in a META-INF/org.codehaus.groovy.transform.ASTTransformation file. If you explicitly add a global AST transformation in your compilation process, for example using theASTTransformationCustomizer
or using aCompilationUnit.PrimaryClassNodeOperation
, then nothing will prevent the transformation from being loaded.- Parameters:
disabledGlobalASTTransformations
- a set of fully qualified class names of global AST transformations which should not be loaded.
-
getBytecodePostprocessor
-
setBytecodePostprocessor
-