public class CompilerConfiguration extends Object
Compilation control flags and coordination stuff.
Modifiers | Name | Description |
---|---|---|
static String[] |
ALLOWED_JDKS |
The valid targetBytecode values. |
static int |
ASM_API_VERSION |
The ASM API version used when loading/parsing classes and generating proxy adapter classes. |
static CompilerConfiguration |
DEFAULT |
A convenience for getting a default configuration. |
static String |
DEFAULT_SOURCE_ENCODING |
|
static String |
GROOVYDOC |
Optimization Option for enabling attaching groovydoc as AST node metadata. |
static String |
INVOKEDYNAMIC |
Optimization Option for enabling invokedynamic compilation. |
static String |
JDK10 |
This ("10" ) is the value for targetBytecode to compile for a JDK 10. |
static String |
JDK11 |
This ("11" ) is the value for targetBytecode to compile for a JDK 11. |
static String |
JDK12 |
This ("12" ) is the value for targetBytecode to compile for a JDK 12. |
static String |
JDK13 |
This ("13" ) is the value for targetBytecode to compile for a JDK 13. |
static String |
JDK14 |
This ("14" ) is the value for targetBytecode to compile for a JDK 14. |
static String |
JDK15 |
This ("15" ) is the value for targetBytecode to compile for a JDK 15. |
static String |
JDK16 |
This ("16" ) is the value for targetBytecode to compile for a JDK 16. |
static String |
JDK17 |
This ("17" ) is the value for targetBytecode to compile for a JDK 17. |
static String |
JDK4 |
This ("1.4" ) is the value for targetBytecode to compile for a JDK 1.4. |
static String |
JDK5 |
This ("1.5" ) is the value for targetBytecode to compile for a JDK 1.5. |
static String |
JDK6 |
This ("1.6" ) is the value for targetBytecode to compile for a JDK 1.6. |
static String |
JDK7 |
This ("1.7" ) is the value for targetBytecode to compile for a JDK 1.7. |
static String |
JDK8 |
This ("1.8" ) is the value for targetBytecode to compile for a JDK 1.8. |
static String |
JDK9 |
This ("9" ) is the value for targetBytecode to compile for a JDK 9. |
static Map<String, Integer> |
JDK_TO_BYTECODE_VERSION_MAP |
JDK version to bytecode version mapping. |
static String |
MEM_STUB |
Joint Compilation Option for enabling generating stubs in memory. |
static String |
PARALLEL_PARSE |
Optimization Option for enabling parallel parsing. |
static String |
POST_JDK5 |
This constant is for comparing targetBytecode to ensure it is set to JDK 1.5 or later. |
static String |
PRE_JDK5 |
This constant is for comparing targetBytecode to ensure it is set to an earlier value than JDK 1.5. |
static String |
RUNTIME_GROOVYDOC |
Optimization Option for enabling attaching Groovydoc annotation. |
Constructor and description |
---|
CompilerConfiguration
() Sets the compiler flags/settings to default values. |
CompilerConfiguration
(CompilerConfiguration configuration) Copy constructor. |
CompilerConfiguration
(Properties configuration) Sets the configuration flags/settings according to values from the supplied Properties instance
or if not found, supplying a default value. |
Type Params | Return Type | Name and description |
---|---|---|
|
public CompilerConfiguration |
addCompilationCustomizers(CompilationCustomizer customizers) |
|
public CompilerConfiguration |
addCompilationCustomizers(CompilationCustomizer customizers) Adds compilation customizers to the compilation process. |
|
public void |
configure(Properties configuration) Method to configure a CompilerConfiguration by using Properties. |
|
public BytecodeProcessor |
getBytecodePostprocessor() |
|
public List<String> |
getClasspath() |
|
public List<String> |
getClasspath()
|
|
public List<CompilationCustomizer> |
getCompilationCustomizers() |
|
public List<CompilationCustomizer> |
getCompilationCustomizers() Returns the list of compilation customizers. |
|
public boolean |
getDebug() Returns true if debugging operation has been requested. |
|
public String |
getDefaultScriptExtension() |
|
public Set<String> |
getDisabledGlobalASTTransformations() |
|
public Set<String> |
getDisabledGlobalASTTransformations() Returns the list of disabled global AST transformation class names. |
|
public Map<String, Object> |
getJointCompilationOptions() |
|
public Map<String, Object> |
getJointCompilationOptions() Gets the joint compilation options for this configuration. |
|
public int |
getMinimumRecompilationInterval() |
|
public Map<String, Boolean> |
getOptimizationOptions() |
|
public Map<String, Boolean> |
getOptimizationOptions() Gets the optimization options for this configuration. |
|
public PrintWriter |
getOutput() Gets the currently configured output writer. |
|
public boolean |
getParameters() Returns true if parameter metadata generation has been enabled. |
|
public ParserPluginFactory |
getPluginFactory() |
|
public boolean |
getRecompileGroovySource() |
|
public String |
getScriptBaseClass() Gets the name of the base class for scripts. |
|
public Set<String> |
getScriptExtensions() |
|
public Set<String> |
getScriptExtensions() |
|
public String |
getSourceEncoding() Gets the currently configured source file encoding. |
|
public String |
getTargetBytecode() Returns the compiler bytecode compatibility level. |
|
public File |
getTargetDirectory() Gets the target directory for writing classes. |
|
public int |
getTolerance() Returns the requested error tolerance. |
|
public boolean |
getVerbose() Returns true if verbose operation has been requested. |
|
public int |
getWarningLevel() Gets the currently configured warning level. |
|
public boolean |
isGroovydocEnabled() Checks if groovydoc is enabled. |
|
public boolean |
isIndyEnabled() Checks if invoke dynamic is enabled. |
|
public static boolean |
isPostJDK5(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version. |
|
public static boolean |
isPostJDK7(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version. |
|
public static boolean |
isPostJDK8(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version. |
|
public static boolean |
isPostJDK9(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version. |
|
public boolean |
isPreviewFeatures() Whether the bytecode version has preview features enabled (JEP 12) |
|
public boolean |
isRuntimeGroovydocEnabled() Checks if runtime groovydoc is enabled. |
|
public void |
setBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor) |
|
public void |
setBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor) |
|
public void |
setClasspath(String classpath) |
|
public void |
setClasspath(String classpath) Sets the classpath. |
|
public void |
setClasspathList(List<String> parts) |
|
public void |
setClasspathList(List<String> parts) sets the classpath using a list of Strings |
|
public void |
setDebug(boolean debug) |
|
public void |
setDebug(boolean debug) Turns debugging operation on or off. |
|
public void |
setDefaultScriptExtension(String defaultScriptExtension) |
|
public void |
setDefaultScriptExtension(String defaultScriptExtension) |
|
public void |
setDisabledGlobalASTTransformations(Set<String> disabledGlobalASTTransformations) |
|
public void |
setDisabledGlobalASTTransformations(Set<String> disabledGlobalASTTransformations) Disables the specified global AST transformations. |
|
public void |
setJointCompilationOptions(Map<String, Object> options) |
|
public void |
setJointCompilationOptions(Map<String, Object> options) Sets the joint compilation options for this configuration. |
|
public void |
setMinimumRecompilationInterval(int time) |
|
public void |
setMinimumRecompilationInterval(int time) |
|
public void |
setOptimizationOptions(Map<String, Boolean> options) |
|
public void |
setOptimizationOptions(Map<String, Boolean> options) Sets the optimization options for this configuration. |
|
public void |
setOutput(PrintWriter output) |
|
public void |
setOutput(PrintWriter output) Sets the output writer. |
|
public void |
setParameters(boolean parameters) |
|
public void |
setParameters(boolean parameters) Turns parameter metadata generation on or off. |
|
public void |
setPluginFactory(ParserPluginFactory pluginFactory) |
|
public void |
setPluginFactory(ParserPluginFactory pluginFactory) |
|
public void |
setPreviewFeatures(boolean previewFeatures) |
|
public void |
setPreviewFeatures(boolean previewFeatures) Sets whether the bytecode version has preview features enabled (JEP 12). |
|
public void |
setRecompileGroovySource(boolean recompile) |
|
public void |
setRecompileGroovySource(boolean recompile) |
|
public void |
setScriptBaseClass(String scriptBaseClass) |
|
public void |
setScriptBaseClass(String scriptBaseClass) Sets the name of the base class for scripts. |
|
public void |
setScriptExtensions(Set<String> scriptExtensions) |
|
public void |
setScriptExtensions(Set<String> scriptExtensions) |
|
public void |
setSourceEncoding(String encoding) |
|
public void |
setSourceEncoding(String encoding) Sets the encoding to be used when reading source files. |
|
public void |
setTargetBytecode(String version) |
|
public void |
setTargetBytecode(String version) Sets the bytecode compatibility level. |
|
public void |
setTargetDirectory(File directory) |
|
public void |
setTargetDirectory(String directory) |
|
public void |
setTargetDirectory(File directory) Sets the target directory. |
|
public void |
setTargetDirectory(String directory) Sets the target directory. |
|
public void |
setTolerance(int tolerance) |
|
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. |
|
public void |
setVerbose(boolean verbose) |
|
public void |
setVerbose(boolean verbose) Turns verbose operation on or off. |
|
public void |
setWarningLevel(int level) |
|
public void |
setWarningLevel(int level) Sets the warning level. |
The valid targetBytecode values.
The ASM API version used when loading/parsing classes and generating proxy adapter classes.
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()
.
Optimization Option for enabling attaching groovydoc as AST node metadata.
Optimization Option for enabling invokedynamic
compilation.
This ("10"
) is the value for targetBytecode to compile for a JDK 10.
This ("11"
) is the value for targetBytecode to compile for a JDK 11.
This ("12"
) is the value for targetBytecode to compile for a JDK 12.
This ("13"
) is the value for targetBytecode to compile for a JDK 13.
This ("14"
) is the value for targetBytecode to compile for a JDK 14.
This ("15"
) is the value for targetBytecode to compile for a JDK 15.
This ("16"
) is the value for targetBytecode to compile for a JDK 16.
This ("17"
) is the value for targetBytecode to compile for a JDK 17.
This ("1.4"
) is the value for targetBytecode to compile for a JDK 1.4.
This ("1.5"
) is the value for targetBytecode to compile for a JDK 1.5.
This ("1.6"
) is the value for targetBytecode to compile for a JDK 1.6.
This ("1.7"
) is the value for targetBytecode to compile for a JDK 1.7.
This ("1.8"
) is the value for targetBytecode to compile for a JDK 1.8.
This ("9"
) is the value for targetBytecode to compile for a JDK 9.
JDK version to bytecode version mapping.
Joint Compilation Option for enabling generating stubs in memory.
Optimization Option for enabling parallel parsing.
This constant is for comparing targetBytecode to ensure it is set to JDK 1.5 or later.
This constant is for comparing targetBytecode to ensure it is set to an earlier value than JDK 1.5.
Sets the compiler flags/settings to default values. The following system properties are referenced when setting the configuration:
The following system properties are referenced when setting the configuration optimization options:
Property Key Related Property Getter groovy.antlr4
getPluginFactory groovy.source.encoding
(defaulting tofile.encoding
)getSourceEncoding groovy.target.bytecode
getTargetBytecode groovy.target.directory
getTargetDirectory groovy.parameters
getParameters() groovy.preview.features
isPreviewFeatures groovy.default.scriptExtension
getDefaultScriptExtension
Property Key Related Property Getter groovy.target.indy
getOptimizationOptions groovy.attach.groovydoc
getOptimizationOptions groovy.attach.runtime.groovydoc
getOptimizationOptions
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);
configuration
- The configuration to copy. Sets the configuration flags/settings according to values from the supplied Properties
instance
or if not found, supplying a default value.
Note that unlike CompilerConfiguration(), the "defaults" here do not in general
include checking the settings in System.getProperties.
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
object that is backed by System.getProperties()
(which
is done using this constructor). That might be done like this:
And you also have to contend with a possibleProperties myProperties = new Properties(System.getProperties()); myProperties.setProperty("groovy.output.debug", "true"); myConfiguration = new CompilerConfiguration(myProperties);
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:
The following properties are referenced when setting the configuration:// 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 Related Property Getter groovy.warnings
getWarningLevel groovy.source.encoding
(defaulting tofile.encoding
)getSourceEncoding groovy.target.directory
getTargetDirectory groovy.target.bytecode
getTargetBytecode groovy.parameters
getParameters() groovy.preview.features
isPreviewFeatures groovy.classpath
getClasspath groovy.output.verbose
getVerbose groovy.output.debug
getDebug groovy.errors.tolerance
getTolerance groovy.default.scriptExtension
getDefaultScriptExtension groovy.script.base
getScriptBaseClass groovy.recompile
getRecompileGroovySource groovy.recompile.minimumInterval
getMinimumRecompilationInterval groovy.disabled.global.ast.transformations
getDisabledGlobalASTTransformations
configuration
- The properties to get flag values from.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.
customizers
- the list of customizers to be addedMethod to configure a CompilerConfiguration by using Properties. For a list of available properties look at CompilerConfiguration(Properties).
configuration
- The properties to get flag values from.Returns the list of compilation customizers.
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.
Gets the optimization options for this configuration.
Gets the currently configured output writer.
Returns true if parameter metadata generation has been enabled.
Gets the name of the base class for scripts. It must be a subclass of Script.
Gets the currently configured source file encoding.
Returns the compiler bytecode compatibility level. Defaults to the minimum officially supported bytecode version for any particular Groovy version.
Gets the target directory for writing classes.
Returns the requested error tolerance.
Returns true if verbose operation has been requested.
Gets the currently configured warning level. See WarningMessage for level details.
Checks if groovydoc is enabled.
Checks if invoke dynamic is enabled.
Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS.Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS.Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS.Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS.Whether the bytecode version has preview features enabled (JEP 12)
Checks if runtime groovydoc is enabled.
Sets the classpath.
sets the classpath using a list of Strings
parts
- list of strings containing the classpath partsTurns debugging operation on or off.
Disables the specified global AST transformations. In order to avoid class loading side effects, it is not recommended to use MyASTTransformation.class.getName() but instead 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/services/org.codehaus.groovy.transform.ASTTransformation file. If you explicitly add a global AST transformation in your compilation process, for example using the ASTTransformationCustomizer or using a org.codehaus.groovy.control.CompilationUnit.IPrimaryClassNodeOperation, 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.Sets the joint compilation options for this configuration. Using null will disable joint compilation.
options
- the optionsSets 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".
options
- the options.Sets the output writer.
Turns parameter metadata generation on or off.
Sets whether the bytecode version has preview features enabled (JEP 12).
previewFeatures
- whether to support preview featuresSets the name of the base class for scripts. It must be a subclass of Script.
Sets the encoding to be used when reading source files.
Sets the bytecode compatibility level. The parameter can take one of the values in ALLOWED_JDKS.
version
- the bytecode compatibility levelSets the target directory.
Sets the target directory.
Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.
Turns verbose operation on or off.
Sets the warning level. See WarningMessage for level details.
Copyright © 2003-2024 The Apache Software Foundation. All rights reserved.