Package org.codehaus.groovy.control
Class CompilerConfiguration
- java.lang.Object
- 
- org.codehaus.groovy.control.CompilerConfiguration
 
- 
 public class CompilerConfiguration extends java.lang.ObjectCompilation control flags and coordination stuff.
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.String[]ALLOWED_JDKSThe valid targetBytecode values.static intASM_API_VERSIONThe ASM API version used when loading/parsing classes and generating proxy adapter classes.static java.lang.StringCURRENT_JVM_VERSIONDeprecated.static CompilerConfigurationDEFAULTA convenience for getting a default configuration.static java.lang.StringDEFAULT_SOURCE_ENCODINGstatic java.lang.StringINVOKEDYNAMICOptimization Option for enablinginvokedynamiccompilation.static java.util.Map<java.lang.String,java.lang.Integer>JDK_TO_BYTECODE_VERSION_MAPJDK version to bytecode version mapping.static java.lang.StringJDK10This ("10") is the value for targetBytecode to compile for a JDK 10.static java.lang.StringJDK11This ("11") is the value for targetBytecode to compile for a JDK 11.static java.lang.StringJDK12This ("12") is the value for targetBytecode to compile for a JDK 12.static java.lang.StringJDK13This ("13") is the value for targetBytecode to compile for a JDK 13.static java.lang.StringJDK14This ("14") is the value for targetBytecode to compile for a JDK 14.static java.lang.StringJDK15This ("15") is the value for targetBytecode to compile for a JDK 15.static java.lang.StringJDK4This ("1.4") is the value for targetBytecode to compile for a JDK 1.4.static java.lang.StringJDK5This ("1.5") is the value for targetBytecode to compile for a JDK 1.5.static java.lang.StringJDK6This ("1.6") is the value for targetBytecode to compile for a JDK 1.6.static java.lang.StringJDK7This ("1.7") is the value for targetBytecode to compile for a JDK 1.7.static java.lang.StringJDK8This ("1.8") is the value for targetBytecode to compile for a JDK 1.8.static java.lang.StringJDK9This ("9") is the value for targetBytecode to compile for a JDK 9.static java.lang.StringPOST_JDK5Deprecated.static java.lang.StringPRE_JDK5Deprecated.
 - 
Constructor SummaryConstructors Constructor Description CompilerConfiguration()Sets the compiler flags/settings to default values.CompilerConfiguration(java.util.Properties configuration)Sets the configuration flags/settings according to values from the suppliedPropertiesinstance or if not found, supplying a default value.CompilerConfiguration(CompilerConfiguration configuration)Copy constructor.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CompilerConfigurationaddCompilationCustomizers(CompilationCustomizer... customizers)Adds compilation customizers to the compilation process.voidconfigure(java.util.Properties configuration)Method to configure a CompilerConfiguration by using Properties.BytecodeProcessorgetBytecodePostprocessor()java.util.List<java.lang.String>getClasspath()java.util.List<CompilationCustomizer>getCompilationCustomizers()Returns the list of compilation customizers.booleangetDebug()Returns true if debugging operation has been requested.java.lang.StringgetDefaultScriptExtension()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.intgetMinimumRecompilationInterval()java.util.Map<java.lang.String,java.lang.Boolean>getOptimizationOptions()Gets the optimization options for this configuration.java.io.PrintWritergetOutput()Deprecated.not used anymorebooleangetParameters()Returns true if parameter metadata generation has been enabled.ParserPluginFactorygetPluginFactory()booleangetRecompileGroovySource()java.lang.StringgetScriptBaseClass()Gets the name of the base class for scripts.java.util.Set<java.lang.String>getScriptExtensions()java.lang.StringgetSourceEncoding()Gets the currently configured source file encoding.java.lang.StringgetTargetBytecode()Returns the compiler bytecode compatibility level.java.io.FilegetTargetDirectory()Gets the target directory for writing classes.intgetTolerance()Returns the requested error tolerance.booleangetVerbose()Returns true if verbose operation has been requested.intgetWarningLevel()Gets the currently configured warning level.booleanisIndyEnabled()Checks if invoke dynamic is enabled.static booleanisPostJDK5(java.lang.String bytecodeVersion)Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.static booleanisPostJDK7(java.lang.String bytecodeVersion)Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.static booleanisPostJDK8(java.lang.String bytecodeVersion)Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.static booleanisPostJDK9(java.lang.String bytecodeVersion)Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.booleanisPreviewFeatures()Whether the bytecode version has preview features enabled (JEP 12)voidsetBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor)voidsetClasspath(java.lang.String classpath)Sets the classpath.voidsetClasspathList(java.util.List<java.lang.String> parts)sets the classpath using a list of StringsvoidsetDebug(boolean debug)Turns debugging operation on or off.voidsetDefaultScriptExtension(java.lang.String defaultScriptExtension)voidsetDisabledGlobalASTTransformations(java.util.Set<java.lang.String> disabledGlobalASTTransformations)Disables the specified global AST transformations.voidsetJointCompilationOptions(java.util.Map<java.lang.String,java.lang.Object> options)Sets the joint compilation options for this configuration.voidsetMinimumRecompilationInterval(int time)voidsetOptimizationOptions(java.util.Map<java.lang.String,java.lang.Boolean> options)Sets the optimization options for this configuration.voidsetOutput(java.io.PrintWriter output)Deprecated.not used anymore, has no effectvoidsetParameters(boolean parameters)Turns parameter metadata generation on or off.voidsetPluginFactory(ParserPluginFactory pluginFactory)voidsetPreviewFeatures(boolean previewFeatures)Sets whether the bytecode version has preview features enabled (JEP 12).voidsetRecompileGroovySource(boolean recompile)voidsetScriptBaseClass(java.lang.String scriptBaseClass)Sets the name of the base class for scripts.voidsetScriptExtensions(java.util.Set<java.lang.String> scriptExtensions)voidsetSourceEncoding(java.lang.String encoding)Sets the encoding to be used when reading source files.voidsetTargetBytecode(java.lang.String version)Sets the bytecode compatibility level.voidsetTargetDirectory(java.io.File directory)Sets the target directory.voidsetTargetDirectory(java.lang.String directory)Sets the target directory.voidsetTolerance(int tolerance)Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.voidsetVerbose(boolean verbose)Turns verbose operation on or off.voidsetWarningLevel(int level)Sets the warning level.
 
- 
- 
- 
Field Detail- 
INVOKEDYNAMICpublic static final java.lang.String INVOKEDYNAMIC Optimization Option for enablinginvokedynamiccompilation.- See Also:
- Constant Field Values
 
 - 
JDK4public static final java.lang.String JDK4 This ("1.4") is the value for targetBytecode to compile for a JDK 1.4.- See Also:
- Constant Field Values
 
 - 
JDK5public static final java.lang.String JDK5 This ("1.5") is the value for targetBytecode to compile for a JDK 1.5.- See Also:
- Constant Field Values
 
 - 
JDK6public static final java.lang.String JDK6 This ("1.6") is the value for targetBytecode to compile for a JDK 1.6.- See Also:
- Constant Field Values
 
 - 
JDK7public static final java.lang.String JDK7 This ("1.7") is the value for targetBytecode to compile for a JDK 1.7.- See Also:
- Constant Field Values
 
 - 
JDK8public static final java.lang.String JDK8 This ("1.8") is the value for targetBytecode to compile for a JDK 1.8.- See Also:
- Constant Field Values
 
 - 
JDK9public static final java.lang.String JDK9 This ("9") is the value for targetBytecode to compile for a JDK 9.- See Also:
- Constant Field Values
 
 - 
JDK10public static final java.lang.String JDK10 This ("10") is the value for targetBytecode to compile for a JDK 10.- See Also:
- Constant Field Values
 
 - 
JDK11public static final java.lang.String JDK11 This ("11") is the value for targetBytecode to compile for a JDK 11.- See Also:
- Constant Field Values
 
 - 
JDK12public static final java.lang.String JDK12 This ("12") is the value for targetBytecode to compile for a JDK 12.- See Also:
- Constant Field Values
 
 - 
JDK13public static final java.lang.String JDK13 This ("13") is the value for targetBytecode to compile for a JDK 13.- See Also:
- Constant Field Values
 
 - 
JDK14public static final java.lang.String JDK14 This ("14") is the value for targetBytecode to compile for a JDK 14.- See Also:
- Constant Field Values
 
 - 
JDK15public static final java.lang.String JDK15 This ("15") is the value for targetBytecode to compile for a JDK 15.- See Also:
- Constant Field Values
 
 - 
POST_JDK5@Deprecated public static final java.lang.String POST_JDK5 Deprecated.This constant is for comparing targetBytecode to ensure it is set to JDK 1.5 or later.- See Also:
- Constant Field Values
 
 - 
PRE_JDK5@Deprecated public static final java.lang.String PRE_JDK5 Deprecated.This constant is for comparing targetBytecode to ensure it is set to an earlier value than JDK 1.5.- See Also:
- Constant Field Values
 
 - 
JDK_TO_BYTECODE_VERSION_MAPpublic static final java.util.Map<java.lang.String,java.lang.Integer> JDK_TO_BYTECODE_VERSION_MAP JDK version to bytecode version mapping.
 - 
ALLOWED_JDKSpublic static final java.lang.String[] ALLOWED_JDKS The valid targetBytecode values.
 - 
ASM_API_VERSIONpublic static final int ASM_API_VERSION The ASM API version used when loading/parsing classes and generating proxy adapter classes.- See Also:
- Constant Field Values
 
 - 
CURRENT_JVM_VERSION@Deprecated public static final java.lang.String CURRENT_JVM_VERSION Deprecated.- See Also:
- Constant Field Values
 
 - 
DEFAULT_SOURCE_ENCODINGpublic static final java.lang.String DEFAULT_SOURCE_ENCODING - See Also:
- Constant Field Values
 
 - 
DEFAULTpublic static final CompilerConfiguration 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 Detail- 
CompilerConfigurationpublic CompilerConfiguration() 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.source.encoding(defaulting tofile.encoding)getSourceEncoding()groovy.target.bytecodegetTargetBytecode()groovy.target.directorygetTargetDirectory()groovy.parametersgetParameters()groovy.preview.featuresisPreviewFeatures()groovy.default.scriptExtensiongetDefaultScriptExtension()Property Key Related Property Getter groovy.target.indygetOptimizationOptions()
 - 
CompilerConfigurationpublic 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 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); - Parameters:
- configuration- The configuration to copy.
 
 - 
CompilerConfigurationpublic CompilerConfiguration(java.util.Properties configuration) throws ConfigurationExceptionSets the configuration flags/settings according to values from the suppliedPropertiesinstance or if not found, supplying a default value. Note that unlikeCompilerConfiguration(), the "defaults" here do not in general include checking the settings inSystem.getProperties(). If you want to set a few flags but keep Groovy's default configuration behavior then be sure to make your settings in aPropertiesobject that is backed bySystem.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);SecurityExceptionwhen getting the system properties (SeeSystem.getProperties()). A safer approach would be to copy a defaultCompilerConfigurationand 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.warningsgetWarningLevel()groovy.source.encoding(defaulting tofile.encoding)getSourceEncoding()groovy.target.directorygetTargetDirectory()groovy.target.bytecodegetTargetBytecode()groovy.parametersgetParameters()groovy.preview.featuresisPreviewFeatures()groovy.classpathgetClasspath()groovy.output.verbosegetVerbose()groovy.output.debuggetDebug()groovy.errors.tolerancegetTolerance()groovy.default.scriptExtensiongetDefaultScriptExtension()groovy.script.basegetScriptBaseClass()groovy.recompilegetRecompileGroovySource()groovy.recompile.minimumIntervalgetMinimumRecompilationInterval()groovy.disabled.global.ast.transformationsgetDisabledGlobalASTTransformations()- Parameters:
- configuration- The properties to get flag values from.
- Throws:
- ConfigurationException
 
 
- 
 - 
Method Detail- 
isPostJDK5public static boolean isPostJDK5(java.lang.String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.5+
 
 - 
isPostJDK7public static boolean isPostJDK7(java.lang.String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.7+
 
 - 
isPostJDK8public static boolean isPostJDK8(java.lang.String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.8+
 
 - 
isPostJDK9public static boolean isPostJDK9(java.lang.String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 9.0+
 
 - 
configurepublic void configure(java.util.Properties configuration) throws ConfigurationExceptionMethod 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
 
 - 
getWarningLevelpublic int getWarningLevel() Gets the currently configured warning level. SeeWarningMessagefor level details.
 - 
setWarningLevelpublic void setWarningLevel(int level) Sets the warning level. SeeWarningMessagefor level details.
 - 
getSourceEncodingpublic java.lang.String getSourceEncoding() Gets the currently configured source file encoding.
 - 
setSourceEncodingpublic void setSourceEncoding(java.lang.String encoding) Sets the encoding to be used when reading source files.
 - 
getOutput@Deprecated public java.io.PrintWriter getOutput() Deprecated.not used anymoreGets the currently configured output writer.
 - 
setOutput@Deprecated public void setOutput(java.io.PrintWriter output) Deprecated.not used anymore, has no effectSets the output writer.
 - 
getTargetDirectorypublic java.io.File getTargetDirectory() Gets the target directory for writing classes.
 - 
setTargetDirectorypublic void setTargetDirectory(java.io.File directory) Sets the target directory.
 - 
setTargetDirectorypublic void setTargetDirectory(java.lang.String directory) Sets the target directory.
 - 
getClasspathpublic java.util.List<java.lang.String> getClasspath() - Returns:
- the classpath
 
 - 
setClasspathpublic void setClasspath(java.lang.String classpath) Sets the classpath.
 - 
setClasspathListpublic void setClasspathList(java.util.List<java.lang.String> parts) sets the classpath using a list of Strings- Parameters:
- parts- list of strings containing the classpath parts
 
 - 
getVerbosepublic boolean getVerbose() Returns true if verbose operation has been requested.
 - 
setVerbosepublic void setVerbose(boolean verbose) Turns verbose operation on or off.
 - 
getDebugpublic boolean getDebug() Returns true if debugging operation has been requested.
 - 
setDebugpublic void setDebug(boolean debug) Turns debugging operation on or off.
 - 
getParameterspublic boolean getParameters() Returns true if parameter metadata generation has been enabled.
 - 
setParameterspublic void setParameters(boolean parameters) Turns parameter metadata generation on or off.
 - 
getTolerancepublic int getTolerance() Returns the requested error tolerance.
 - 
setTolerancepublic 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.
 - 
getScriptBaseClasspublic java.lang.String getScriptBaseClass() Gets the name of the base class for scripts. It must be a subclass of Script.
 - 
setScriptBaseClasspublic void setScriptBaseClass(java.lang.String scriptBaseClass) Sets the name of the base class for scripts. It must be a subclass of Script.
 - 
getPluginFactorypublic ParserPluginFactory getPluginFactory() 
 - 
setPluginFactorypublic void setPluginFactory(ParserPluginFactory pluginFactory) 
 - 
setScriptExtensionspublic void setScriptExtensions(java.util.Set<java.lang.String> scriptExtensions) 
 - 
getScriptExtensionspublic java.util.Set<java.lang.String> getScriptExtensions() 
 - 
getDefaultScriptExtensionpublic java.lang.String getDefaultScriptExtension() 
 - 
setDefaultScriptExtensionpublic void setDefaultScriptExtension(java.lang.String defaultScriptExtension) 
 - 
getRecompileGroovySourcepublic boolean getRecompileGroovySource() 
 - 
setRecompileGroovySourcepublic void setRecompileGroovySource(boolean recompile) 
 - 
getMinimumRecompilationIntervalpublic int getMinimumRecompilationInterval() 
 - 
setMinimumRecompilationIntervalpublic void setMinimumRecompilationInterval(int time) 
 - 
getTargetBytecodepublic java.lang.String getTargetBytecode() Returns the compiler bytecode compatibility level. Defaults to the minimum officially supported bytecode version for any particular Groovy version.- Returns:
- bytecode compatibility level
 
 - 
setTargetBytecodepublic void setTargetBytecode(java.lang.String version) Sets the bytecode compatibility level. The parameter can take one of the values inALLOWED_JDKS.- Parameters:
- version- the bytecode compatibility level
 
 - 
isPreviewFeaturespublic boolean isPreviewFeatures() Whether the bytecode version has preview features enabled (JEP 12)- Returns:
- preview features
 
 - 
setPreviewFeaturespublic void setPreviewFeatures(boolean previewFeatures) Sets whether the bytecode version has preview features enabled (JEP 12).- Parameters:
- previewFeatures- whether to support preview features
 
 - 
getJointCompilationOptionspublic java.util.Map<java.lang.String,java.lang.Object> getJointCompilationOptions() Gets the joint compilation options for this configuration.- Returns:
- the options
 
 - 
setJointCompilationOptionspublic void setJointCompilationOptions(java.util.Map<java.lang.String,java.lang.Object> options) Sets the joint compilation options for this configuration. Using null will disable joint compilation.- Parameters:
- options- the options
 
 - 
getOptimizationOptionspublic java.util.Map<java.lang.String,java.lang.Boolean> getOptimizationOptions() Gets the optimization options for this configuration.- Returns:
- the options (always not null)
 
 - 
setOptimizationOptionspublic void setOptimizationOptions(java.util.Map<java.lang.String,java.lang.Boolean> options) 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:
- java.lang.IllegalArgumentException- if the options are null
 
 - 
addCompilationCustomizerspublic CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers) 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
 
 - 
getCompilationCustomizerspublic java.util.List<CompilationCustomizer> getCompilationCustomizers() Returns the list of compilation customizers.- Returns:
- the customizers (always not null)
 
 - 
getDisabledGlobalASTTransformationspublic java.util.Set<java.lang.String> getDisabledGlobalASTTransformations() Returns the list of disabled global AST transformation class names.- Returns:
- a list of global AST transformation fully qualified class names
 
 - 
setDisabledGlobalASTTransformationspublic void setDisabledGlobalASTTransformations(java.util.Set<java.lang.String> disabledGlobalASTTransformations) 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 theASTTransformationCustomizeror 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.
 
 - 
getBytecodePostprocessorpublic BytecodeProcessor getBytecodePostprocessor() 
 - 
setBytecodePostprocessorpublic void setBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor) 
 - 
isIndyEnabledpublic boolean isIndyEnabled() Checks if invoke dynamic is enabled.
 
- 
 
-