Groovy Module (Commons)

Last modified by Vincent Massol on 2021/03/17 21:55

cogGroovy Execution API
Developed by

XWiki Development Team

0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard


This module has the following features:

  • Ability to define Groovy Compilation Customizer components to customize execution of Groovy scripts
  • A Timed Interrupt Customizer allowing to stop executing Groovy Scripts after a given timeout has been reached

Timed Interrupt Customizer

This customizer stops execution of Groovy Script after a timeout has been reached, thus preventing long running operations. However this works only for Groovy code. If the Groovy code calls Java methods for example and these methods take a long time to execute the execution will be stopped only when the Groovy code regains control.

Implementing a new Customizer

Do the following:

  • Add a Component implementing the org.xwiki.groovy.GroovyCompilationCustomizer Component Role.
  • Implement the CompilationCustomizer createCustomizer();┬ámethod.

For example:

public class TimedInterruptGroovyCompilationCustomizer implements GroovyCompilationCustomizer
     * Used to get the script timeout configuration parameter value.

   private TimedInterruptCustomizerConfiguration configuration;

   public CompilationCustomizer createCustomizer()
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("value", this.configuration.getTimeout());
       return new ASTTransformationCustomizer(parameters, TimedInterrupt.class);

Prerequisites & Installation Instructions

No Groovy Customizers are defined by default.

To add a Compilation Customizer, edit the configuration file and add the following property:

groovy.compilationCustomizers=<list of customizer ids here>

For example to enable the Timed Interrupt Customizer, you would write:


You can also configure the Timed Interrupt Customize timeout value by adding/editing the following property, in seconds (60 seconds being the default):


Get Connected