Class DefaultGroovyCompiler
- All Implemented Interfaces:
Compiler
- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionconstructor from parent class loader set to the context class loader of the current thread and from default compiler configuration.protectedconstructor from builder.DefaultGroovyCompiler(ClassLoader parent) constructor from given parent class loader and default compiler configuration.DefaultGroovyCompiler(ClassLoader parent, CompilerConfiguration config) constructor from given parent class loader and compiler configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected SourceUnitaddToCompilationUnit(CompilationUnit cu, Source source, Sources sources) adds the given source to the given compilation unit and returns the resulting source unit.compiles the given Groovy script sources to an instance ofCodein memory.static voiddisable Grape support for Grengine - not recommended in some scenarios where multiple callers can enable in an idempotent way but a single caller can disable for all.static voidenable Grape support for Grengine with the default lock.static voidenableGrapeSupport(Object lock) enable Grape support for Grengine with the given lock.gets the builder.gets the compiler configuration.gets the parent class loader.static CompilerConfigurationwithGrape(CompilerConfiguration config, GroovyClassLoader runtimeLoader) modifies the given compiler configuration for Grape support in this compiler.
-
Constructor Details
-
DefaultGroovyCompiler
constructor from builder.- Parameters:
builder- builder- Since:
- 1.0
-
DefaultGroovyCompiler
public DefaultGroovyCompiler()constructor from parent class loader set to the context class loader of the current thread and from default compiler configuration.- Since:
- 1.0
-
DefaultGroovyCompiler
constructor from given parent class loader and default compiler configuration.- Parameters:
parent- parent class loader- Throws:
NullPointerException- if the parent class loader is null- Since:
- 1.0
-
DefaultGroovyCompiler
constructor from given parent class loader and compiler configuration.- Parameters:
parent- parent class loaderconfig- compiler configuration- Throws:
NullPointerException- if the parent class loader or the compiler configuration is null- Since:
- 1.0
-
-
Method Details
-
withGrape
public static CompilerConfiguration withGrape(CompilerConfiguration config, GroovyClassLoader runtimeLoader) modifies the given compiler configuration for Grape support in this compiler.Only has an effect during compilation if Grape support had been enabled and only with this compiler class.
- Parameters:
config- compiler configuration to enable for GraperuntimeLoader- the GroovyClassLoader that is intended to be used later as a parent loader when loading classes compiled with the given compiler configuration- Returns:
- modified compiler configuration, same instance as argument
- Throws:
NullPointerException- if the compiler configuration is null- Since:
- 1.2
-
enableGrapeSupport
public static void enableGrapeSupport()enable Grape support for Grengine with the default lock.Wraps the
GrapeEnginein theGrapeclass with a wrapper that handles class loaders as needed by Grengine and locks grabs on the wrapper instance.Call once before using this compiler class in combination with Grengine when Grape grabs are needed (equivalent to calling
Grengine.Grape.activate()).See user manual under "Grengine and Grape" for more info.
- Since:
- 1.2
-
enableGrapeSupport
enable Grape support for Grengine with the given lock.Wraps the
GrapeEnginein theGrapeclass with a wrapper that handles class loaders as needed by Grengine and locks grabs with the given lock or, if the given lock is null, with the wrapper instance.Call once before using this compiler class in combination with Grengine when Grape grabs are needed (equivalent to calling
Grengine.Grape.activate(lock)).See user manual under "Grengine and Grape" for more info.
- Parameters:
lock- the lock to use; uses default lock if null- Since:
- 1.2
-
disableGrapeSupport
public static void disableGrapeSupport()disable Grape support for Grengine - not recommended in some scenarios where multiple callers can enable in an idempotent way but a single caller can disable for all.Unwraps the
GrapeEnginein theGrapeclass (equivalent to callingGrengine.Grape.deactivate()).See user manual under "Grengine and Grape" for more info.
- Since:
- 1.2
-
compile
compiles the given Groovy script sources to an instance ofCodein memory.If
CompilerConfiguration.getTargetDirectory()is not null, class files are also written to the target directory.- Specified by:
compilein interfaceCompiler- Parameters:
sources- sources- Returns:
- code
- Throws:
CompileException- if compilation failedNullPointerException- if sources are null- Since:
- 1.0
-
addToCompilationUnit
adds the given source to the given compilation unit and returns the resulting source unit.- Parameters:
cu- compilation unitsource- sourcesources- all sources, needed only if the type of source is unsupported, for the resultingCompileException- Returns:
- source unit
- Throws:
CompileException- if the type of source is unsupported- Since:
- 1.0
-
getBuilder
gets the builder.- Returns:
- builder
- Since:
- 1.0
-
getParent
gets the parent class loader.- Returns:
- parent class loader
- Since:
- 1.0
-
getCompilerConfiguration
gets the compiler configuration.- Returns:
- compiler configuration
- Since:
- 1.0
-