public class CompilerConfiguration extends Object
Modifier and Type | Field and Description |
---|---|
static String[] |
ALLOWED_JDKS
An array of the valid targetBytecode values
|
static int |
ASM_API_VERSION |
static String |
CURRENT_JVM_VERSION
Deprecated.
|
static CompilerConfiguration |
DEFAULT
A convenience for getting a default configuration.
|
static String |
DEFAULT_SOURCE_ENCODING
The default source encoding
|
static String |
INVOKEDYNAMIC
This (
"indy" ) is the Optimization Option value for enabling invokedynamic compilation. |
static Map<String,Integer> |
JDK_TO_BYTECODE_VERSION_MAP
JDK version to bytecode version mapping
|
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 |
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 String |
POST_JDK5
Deprecated.
|
static String |
PRE_JDK5
Deprecated.
|
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. |
Modifier and Type | Method and Description |
---|---|
CompilerConfiguration |
addCompilationCustomizers(CompilationCustomizer... customizers)
Adds compilation customizers to the compilation process.
|
void |
configure(Properties configuration)
Method to configure a CompilerConfiguration by using Properties.
|
BytecodeProcessor |
getBytecodePostprocessor() |
List<String> |
getClasspath() |
List<CompilationCustomizer> |
getCompilationCustomizers()
Returns the list of compilation customizers.
|
boolean |
getDebug()
Returns true if debugging operation has been requested.
|
String |
getDefaultScriptExtension() |
Set<String> |
getDisabledGlobalASTTransformations()
Returns the list of disabled global AST transformation class names.
|
Map<String,Object> |
getJointCompilationOptions()
Gets the joint compilation options for this configuration.
|
int |
getMinimumRecompilationInterval() |
Map<String,Boolean> |
getOptimizationOptions()
Gets the optimization options for this configuration.
|
PrintWriter |
getOutput()
Deprecated.
not used anymore
|
boolean |
getParameters()
Returns true if parameter metadata generation has been enabled.
|
ParserPluginFactory |
getPluginFactory() |
boolean |
getRecompileGroovySource() |
String |
getScriptBaseClass()
Gets the name of the base class for scripts.
|
Set<String> |
getScriptExtensions() |
String |
getSourceEncoding()
Gets the currently configured source file encoding.
|
String |
getTargetBytecode()
Retrieves the compiler bytecode compatibility level.
|
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.
|
boolean |
isIndyEnabled()
Check whether invoke dynamic enabled
|
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.
|
static boolean |
isPostJDK8(String bytecodeVersion)
Checks if the specified bytecode version string represents a JDK 1.8+ compatible
bytecode version.
|
static boolean |
isPostJDK9(String bytecodeVersion)
Checks if the specified bytecode version string represents a JDK 1.8+ compatible
bytecode version.
|
boolean |
isPreviewFeatures()
Whether the bytecode version has preview features enabled (JEP 12)
|
void |
setBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor) |
void |
setClasspath(String classpath)
Sets the classpath.
|
void |
setClasspathList(List<String> parts)
sets the classpath using a list of Strings
|
void |
setDebug(boolean debug)
Turns debugging operation on or off.
|
void |
setDefaultScriptExtension(String defaultScriptExtension) |
void |
setDisabledGlobalASTTransformations(Set<String> disabledGlobalASTTransformations)
Disables the specified 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 effect
|
void |
setParameters(boolean parameters)
Turns parameter metadata generation on or off.
|
void |
setPluginFactory(ParserPluginFactory pluginFactory) |
void |
setPreviewFeatures(boolean previewFeatures)
Sets whether the bytecode version has preview features enabled (JEP 12).
|
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.
|
public static final String INVOKEDYNAMIC
"indy"
) is the Optimization Option value for enabling invokedynamic
compilation.public static final String JDK4
"1.4"
) is the value for targetBytecode to compile for a JDK 1.4.public static final String JDK5
"1.5"
) is the value for targetBytecode to compile for a JDK 1.5.public static final String JDK6
"1.6"
) is the value for targetBytecode to compile for a JDK 1.6.public static final String JDK7
"1.7"
) is the value for targetBytecode to compile for a JDK 1.7.public static final String JDK8
"1.8"
) is the value for targetBytecode to compile for a JDK 1.8.public static final String JDK9
"9"
) is the value for targetBytecode to compile for a JDK 9.public static final String JDK10
"10"
) is the value for targetBytecode to compile for a JDK 10.public static final String JDK11
"11"
) is the value for targetBytecode to compile for a JDK 11.public static final String JDK12
"12"
) is the value for targetBytecode to compile for a JDK 12.public static final String JDK13
"13"
) is the value for targetBytecode to compile for a JDK 13.public static final String JDK14
"14"
) is the value for targetBytecode to compile for a JDK 14.@Deprecated public static final String POST_JDK5
@Deprecated public static final String PRE_JDK5
public static final Map<String,Integer> JDK_TO_BYTECODE_VERSION_MAP
public static final String[] ALLOWED_JDKS
@Deprecated public static final String CURRENT_JVM_VERSION
public static final String DEFAULT_SOURCE_ENCODING
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 static final int ASM_API_VERSION
public CompilerConfiguration()
The following system properties are referenced when setting the configuration optimization options:
Property Key Related Property Getter groovy.source.encoding
(defaulting tofile.encoding
)getSourceEncoding()
groovy.target.bytecode
getTargetBytecode()
groovy.target.directory
getTargetDirectory()
groovy.parameters
getParameters()
groovy.preview.features
isPreviewFeatures()
groovy.script.base
getScriptBaseClass()
groovy.default.scriptExtension
getDefaultScriptExtension()
Property Key Related Property Getter groovy.target.indy
getOptimizationOptions()
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(Properties configuration) throws ConfigurationException
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.ConfigurationException
public static boolean isPostJDK5(String bytecodeVersion)
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS
.public static boolean isPostJDK7(String bytecodeVersion)
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS
.public static boolean isPostJDK8(String bytecodeVersion)
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS
.public static boolean isPostJDK9(String bytecodeVersion)
bytecodeVersion
- The parameter can take one of the values in ALLOWED_JDKS
.public void configure(Properties configuration) throws ConfigurationException
CompilerConfiguration(Properties)
.configuration
- The properties to get flag values from.ConfigurationException
public int getWarningLevel()
WarningMessage
for level details.public void setWarningLevel(int level)
WarningMessage
for level details.public String getSourceEncoding()
public void setSourceEncoding(String encoding)
@Deprecated public PrintWriter getOutput()
@Deprecated public void setOutput(PrintWriter output)
public File getTargetDirectory()
public void setTargetDirectory(String directory)
public void setTargetDirectory(File directory)
public void setClasspath(String classpath)
public void setClasspathList(List<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 boolean getParameters()
public void setParameters(boolean parameters)
public int getTolerance()
public void setTolerance(int tolerance)
public String getScriptBaseClass()
public void setScriptBaseClass(String scriptBaseClass)
public ParserPluginFactory getPluginFactory()
public void setPluginFactory(ParserPluginFactory pluginFactory)
public String getDefaultScriptExtension()
public void setDefaultScriptExtension(String defaultScriptExtension)
public void setRecompileGroovySource(boolean recompile)
public boolean getRecompileGroovySource()
public void setMinimumRecompilationInterval(int time)
public int getMinimumRecompilationInterval()
public void setTargetBytecode(String version)
ALLOWED_JDKS
.version
- the bytecode compatibility levelpublic String getTargetBytecode()
public boolean isPreviewFeatures()
public void setPreviewFeatures(boolean previewFeatures)
previewFeatures
- whether to support preview featurespublic Map<String,Object> getJointCompilationOptions()
public void setJointCompilationOptions(Map<String,Object> options)
options
- the optionspublic Map<String,Boolean> getOptimizationOptions()
public void setOptimizationOptions(Map<String,Boolean> options)
options
- the options.IllegalArgumentException
- if the options are nullpublic CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)
customizers
- the list of customizers to be addedpublic List<CompilationCustomizer> getCompilationCustomizers()
public Set<String> getDisabledGlobalASTTransformations()
public void setDisabledGlobalASTTransformations(Set<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.public BytecodeProcessor getBytecodePostprocessor()
public void setBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor)
public boolean isIndyEnabled()