Groovy 2.2.1

org.codehaus.groovy.control
[Java] Class CompilerConfiguration

java.lang.Object
  org.codehaus.groovy.control.CompilerConfiguration

public class CompilerConfiguration
extends Object

Compilation control flags and coordination stuff.

Authors:
Chris Poirier
Jochen Theodorou
Jim White
Cedric Champeau


Field Summary
static CompilerConfiguration DEFAULT

A convenience for getting a default configuration.

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 POST_JDK5

This ("1.5") is the value for targetBytecode to compile for a JDK 1.5 or later JVM

static String PRE_JDK5

This ("1.4") is the value for targetBytecode to compile for a JDK 1.4 JVM

static String currentJVMVersion

 
Constructor Summary
CompilerConfiguration()

CompilerConfiguration(CompilerConfiguration configuration)

Copy constructor.

CompilerConfiguration(Properties configuration)

Sets the Flags to the specified configuration, with defaults for those not supplied.

 
Method Summary
CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)

void configure(Properties configuration)

List getClasspath()

Returns true if debugging operation has been requested.

List getCompilationCustomizers()

boolean getDebug()

String getDefaultScriptExtension()

Set getDisabledGlobalASTTransformations()

Map getJointCompilationOptions()

Adds compilation customizers to the compilation process.

int getMinimumRecompilationInterval()

Map getOptimizationOptions()

Returns the list of disabled global AST transformation class names.

PrintWriter getOutput()

ParserPluginFactory getPluginFactory()

boolean getRecompileGroovySource()

String getScriptBaseClass()

Set getScriptExtensions()

String getSourceEncoding()

Gets the target directory for writing classes.

String getTargetBytecode()

Gets the optimization options for this configuration.

File getTargetDirectory()

int getTolerance()

boolean getVerbose()

int getWarningLevel()

Gets the currently configured warning level.

static boolean isPostJDK5(String bytecodeVersion)

Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.

static boolean isPostJDK7(String bytecodeVersion)

Method to configure a this CompilerConfiguration by using Properties.

void setClasspath(String classpath)

Turns debugging operation on or off.

void setClasspathList(List parts)

Returns the requested error tolerance.

void setDebug(boolean debug)

void setDefaultScriptExtension(String defaultScriptExtension)

void setDisabledGlobalASTTransformations(Set disabledGlobalASTTransformations)

void setJointCompilationOptions(Map options)

Returns the list of compilation customizers.

void setMinimumRecompilationInterval(int time)

void setOptimizationOptions(Map options)

Disables global AST transformations.

void setOutput(PrintWriter output)

void setPluginFactory(ParserPluginFactory pluginFactory)

void setRecompileGroovySource(boolean recompile)

void setScriptBaseClass(String scriptBaseClass)

void setScriptExtensions(Set scriptExtensions)

void setSourceEncoding(String encoding)

void setTargetBytecode(String version)

Sets the joint compilation options for this configuration.

void setTargetDirectory(String directory)

void setTargetDirectory(File directory)

Turns verbose operation on or off.

void setTolerance(int tolerance)

void setVerbose(boolean verbose)

void setWarningLevel(int level)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

DEFAULT

public static final CompilerConfiguration DEFAULT
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().


JDK4

public static final String JDK4
This ("1.4") is the value for targetBytecode to compile for a JDK 1.4. *


JDK5

public static final String JDK5
This ("1.5") is the value for targetBytecode to compile for a JDK 1.5. *


JDK6

public static final String JDK6
This ("1.6") is the value for targetBytecode to compile for a JDK 1.6. *


JDK7

public static final String JDK7
This ("1.7") is the value for targetBytecode to compile for a JDK 1.7. *


JDK8

public static final String JDK8
This ("1.8") is the value for targetBytecode to compile for a JDK 1.8. *


POST_JDK5

public static final String POST_JDK5
This ("1.5") is the value for targetBytecode to compile for a JDK 1.5 or later JVM. *


PRE_JDK5

public static final String PRE_JDK5
This ("1.4") is the value for targetBytecode to compile for a JDK 1.4 JVM. *


currentJVMVersion

public static final String currentJVMVersion


 
Constructor Detail

CompilerConfiguration

public CompilerConfiguration()


CompilerConfiguration

public 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 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

public CompilerConfiguration(Properties configuration)
Sets the Flags to the specified configuration, with defaults for those not supplied. Note that those "defaults" here do not include checking the settings in 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. 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 KeyGet/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.


 
Method Detail

addCompilationCustomizers

public CompilerConfiguration addCompilationCustomizers(CompilationCustomizer... customizers)


configure

public void configure(Properties configuration)


getClasspath

public List getClasspath()
Returns true if debugging operation has been requested.


getCompilationCustomizers

public List getCompilationCustomizers()


getDebug

public boolean getDebug()


getDefaultScriptExtension

public String getDefaultScriptExtension()


getDisabledGlobalASTTransformations

public Set getDisabledGlobalASTTransformations()


getJointCompilationOptions

public Map getJointCompilationOptions()
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


getMinimumRecompilationInterval

public int getMinimumRecompilationInterval()


getOptimizationOptions

public Map getOptimizationOptions()
Returns the list of disabled global AST transformation class names.
Returns:
a list of global AST transformation fully qualified class names


getOutput

public PrintWriter getOutput()


getPluginFactory

public ParserPluginFactory getPluginFactory()


getRecompileGroovySource

public boolean getRecompileGroovySource()


getScriptBaseClass

public String getScriptBaseClass()


getScriptExtensions

public Set getScriptExtensions()


getSourceEncoding

public String getSourceEncoding()
Gets the target directory for writing classes.


getTargetBytecode

public String getTargetBytecode()
Gets the optimization options for this configuration.
Returns:
the options (always not null)


getTargetDirectory

public File getTargetDirectory()


getTolerance

public int getTolerance()


getVerbose

public boolean getVerbose()


getWarningLevel

public int getWarningLevel()
Gets the currently configured warning level. See WarningMessage for level details.


isPostJDK5

public static boolean isPostJDK5(String bytecodeVersion)
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+


isPostJDK7

public static boolean isPostJDK7(String bytecodeVersion)
Method to configure a this CompilerConfiguration by using Properties. For a list of available properties look at {link CompilerConfiguration(Properties).
Parameters:
configuration - The properties to get flag values from.


setClasspath

public void setClasspath(String classpath)
Turns debugging operation on or off.


setClasspathList

public void setClasspathList(List parts)
Returns the requested error tolerance.


setDebug

public void setDebug(boolean debug)


setDefaultScriptExtension

public void setDefaultScriptExtension(String defaultScriptExtension)


setDisabledGlobalASTTransformations

public void setDisabledGlobalASTTransformations(Set disabledGlobalASTTransformations)


setJointCompilationOptions

public void setJointCompilationOptions(Map options)
Returns the list of compilation customizers.
Returns:
the customizers (always not null)


setMinimumRecompilationInterval

public void setMinimumRecompilationInterval(int time)


setOptimizationOptions

public void setOptimizationOptions(Map options)
Disables global AST transformations. In order to avoid classloading 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 the ASTTransformationCustomizer or using a org.codehaus.groovy.control.CompilationUnit.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.


setOutput

public void setOutput(PrintWriter output)


setPluginFactory

public void setPluginFactory(ParserPluginFactory pluginFactory)


setRecompileGroovySource

public void setRecompileGroovySource(boolean recompile)


setScriptBaseClass

public void setScriptBaseClass(String scriptBaseClass)


setScriptExtensions

public void setScriptExtensions(Set scriptExtensions)


setSourceEncoding

public void setSourceEncoding(String encoding)


setTargetBytecode

public void setTargetBytecode(String version)
Sets the joint compilation options for this configuration. Using null will disable joint compilation.
Parameters:
options - the options


setTargetDirectory

public void setTargetDirectory(String directory)


setTargetDirectory

public void setTargetDirectory(File directory)
Turns verbose operation on or off.


setTolerance

public void setTolerance(int tolerance)


setVerbose

public void setVerbose(boolean verbose)


setWarningLevel

public void setWarningLevel(int level)


 

Copyright © 2003-2013 The Codehaus. All rights reserved.