Class DefaultGroovyCompiler

java.lang.Object
ch.grengine.code.groovy.DefaultGroovyCompiler
All Implemented Interfaces:
Compiler

public class DefaultGroovyCompiler extends Object implements Compiler
Default Groovy compiler.
Since:
1.0
Author:
Alain Stalder, Made in Switzerland.
  • Constructor Details

    • DefaultGroovyCompiler

      protected DefaultGroovyCompiler(DefaultGroovyCompiler.Builder builder)
      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

      public DefaultGroovyCompiler(ClassLoader parent)
      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

      public DefaultGroovyCompiler(ClassLoader parent, CompilerConfiguration config)
      constructor from given parent class loader and compiler configuration.
      Parameters:
      parent - parent class loader
      config - 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 Grape
      runtimeLoader - 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 GrapeEngine in the Grape class 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

      public static void enableGrapeSupport(Object lock)
      enable Grape support for Grengine with the given lock.

      Wraps the GrapeEngine in the Grape class 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 GrapeEngine in the Grape class (equivalent to calling Grengine.Grape.deactivate()).

      See user manual under "Grengine and Grape" for more info.

      Since:
      1.2
    • compile

      public Code compile(Sources sources)
      compiles the given Groovy script sources to an instance of Code in memory.

      If CompilerConfiguration.getTargetDirectory() is not null, class files are also written to the target directory.

      Specified by:
      compile in interface Compiler
      Parameters:
      sources - sources
      Returns:
      code
      Throws:
      CompileException - if compilation failed
      NullPointerException - if sources are null
      Since:
      1.0
    • addToCompilationUnit

      protected SourceUnit addToCompilationUnit(CompilationUnit cu, Source source, Sources sources)
      adds the given source to the given compilation unit and returns the resulting source unit.
      Parameters:
      cu - compilation unit
      source - source
      sources - all sources, needed only if the type of source is unsupported, for the resulting CompileException
      Returns:
      source unit
      Throws:
      CompileException - if the type of source is unsupported
      Since:
      1.0
    • getBuilder

      public DefaultGroovyCompiler.Builder getBuilder()
      gets the builder.
      Returns:
      builder
      Since:
      1.0
    • getParent

      public ClassLoader getParent()
      gets the parent class loader.
      Returns:
      parent class loader
      Since:
      1.0
    • getCompilerConfiguration

      public CompilerConfiguration getCompilerConfiguration()
      gets the compiler configuration.
      Returns:
      compiler configuration
      Since:
      1.0