Skip to content

Language Support

vasanth-asokan edited this page Feb 10, 2015 · 2 revisions

Nicobar supports Groovy 2 out of the box, with the language plugin provided by the nicobar-groovy2 subproject. The snippet below illustrates how a script module loader must be initialized to support Groovy 2. Note, that the code relies on discovering specific resources from the groovy 2 jars, which are expected to be on the application’s classpath.

public void setupModuleLoader() {
    // configure Groovy plugin
    ScriptCompilerPluginSpec compilerSpec = new ScriptCompilerPluginSpec.Builder(GROOVY2_PLUGIN_ID) 
                .addRuntimeResource(getGroovyRuntime())
                .addRuntimeResource(getGroovyPluginLocation())
                .withPluginClassName(GROOVY2_COMPILER_PLUGIN_CLASS)
                .build()
    ScriptModuleLoader moduleLoader = new ScriptModuleLoader.Builder()
            .addPluginSpec(compilerSpec)
            .build();
}

public Path getGroovyRuntime() {
    Path path = ClassPathUtils.findRootPathForResource("META-INF/groovy-release-info.properties", getClass().getClassLoader());
    if (path == null) {
        throw new IllegalStateException("coudln't find groovy-all.n.n.n.jar in the classpath.");
    }
    return path;
}

public Path getGroovyPluginLocation() {
    String resourceName = ClassPathUtils.classNameToResourceName(GROOVY2_COMPILER_PLUGIN_CLASS);
    Path path = ClassPathUtils.findRootPathForResource(resourceName, getClass().getClassLoader());
    if (path == null) {
        throw new IllegalStateException("coudln't find groovy2 plugin jar in the classpath.");
    }
    return path;
}
Clone this wiki locally