tinkerpop/gremlin — Issue #269: simplify GremlinGroovyScriptEngine and gremlin.groovy.console.Console
Author: i000
Created: 2011-12-15 23:39:37+00:00
State: open

Hi,

It seems (but I might be wrong) that the only reason for the existence of the `GremlinGroovyScriptEngine` class is to prepend gremlin-specific import statements to `eval` methods. It seems there is a simpler solution. The `GroovyScriptEngine` can be customized via the `setConfig` method with the `CompilerConfiguration` and `ImportCustomizer` .

The ``GremlinGroovyScriptEngineFactory.getScriptEngine`` would look along these lines:

```
ImportCustomizer ic = new ImportCustomizer();
ic.addStarImports("com.tinkerpop.gremlin"); // import com.tinkerpop.gremlin.*
...
CompilerConfiguration conf = new CompilerConfiguration();
conf.addCompilationCustomizers(ic);
GroovyScriptEngine gse = new GroovyScriptEngine();
gse.setConfig(conf);
```

Also the `Console` could be simplified with:

```
final Groovysh groovy = new Groovysh(conf);
```

See:

http://mrhaki.blogspot.com/2011/06/groovy-goodness-add-imports.html
http://groovy.codehaus.org/api/groovy/util/GroovyScriptEngine.html
http://www.devdaily.com/java/jwarehouse/groovy/src/test/groovy/util/GroovyScriptEngineTest.groovy.shtml
http://randomallsorts.blogspot.com/2011/02/replacing-properties-with-groovy-script.html