You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/05 16:42:56 UTC
incubator-tinkerpop git commit: Add test to validate that it is
possible to compile scripts without bindings.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master b34785f06 -> c78984a2f
Add test to validate that it is possible to compile scripts without bindings.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/c78984a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/c78984a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/c78984a2
Branch: refs/heads/master
Commit: c78984a2ff9e260bf4b53628b6f97116b49a4197
Parents: b34785f
Author: Stephen Mallette <sp...@apache.org>
Authored: Thu Mar 5 10:42:28 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Thu Mar 5 10:42:28 2015 -0500
----------------------------------------------------------------------
.../groovy/jsr223/GremlinGroovyScriptEngineTest.java | 15 +++++++++++++++
.../groovy/jsr223/GremlinGroovyScriptEngine.java | 15 +++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c78984a2/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 0531aa9..9473c0b 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -74,6 +74,21 @@ public class GremlinGroovyScriptEngineTest extends AbstractGremlinTest {
}
@Test
+ public void shouldCompileScriptWithoutRequiringVariableBindings() throws Exception {
+ // compile() should cache the script to avoid future compilation
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
+
+ final String script = "g.V(x).out()";
+ assertFalse(engine.isCached(script));
+ assertNotNull(engine.compile(script));
+ assertTrue(engine.isCached(script));
+
+ engine.reset();
+
+ assertFalse(engine.isCached(script));
+ }
+
+ @Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldLoadImports() throws Exception {
final ScriptEngine engineNoImports = new GremlinGroovyScriptEngine(new NoImportCustomizerProvider());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c78984a2/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 79d82ab..e00f59c 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -317,8 +317,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
try {
return new GroovyCompiledScript(this, getScriptClass(scriptSource));
} catch (SyntaxException e) {
- throw new ScriptException(e.getMessage(),
- e.getSourceLocator(), e.getLine());
+ throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine());
} catch (IOException e) {
throw new ScriptException(e);
} catch (CompilationFailedException ee) {
@@ -368,6 +367,10 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
return clazz;
}
+ boolean isCached(final String script) {
+ return classMap.get(script) != null;
+ }
+
Object eval(final Class scriptClass, final ScriptContext context) throws ScriptException {
ensureSandbox();
@@ -403,12 +406,12 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
for (Method m : scriptClass.getMethods()) {
final String name = m.getName();
globalClosures.put(name, new MethodClosure(scriptObject, name));
- };
+ }
final MetaClass oldMetaClass = scriptObject.getMetaClass();
scriptObject.setMetaClass(new DelegatingMetaClass(oldMetaClass) {
@Override
- public Object invokeMethod(Object object, String name, Object args) {
+ public Object invokeMethod(final Object object, final String name, final Object args) {
if (args == null) {
return invokeMethod(object, name, MetaClassHelper.EMPTY_ARRAY);
} else if (args instanceof Tuple) {
@@ -421,7 +424,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
@Override
- public Object invokeMethod(Object object, String name, Object args[]) {
+ public Object invokeMethod(final Object object, final String name, final Object args[]) {
try {
return super.invokeMethod(object, name, args);
} catch (MissingMethodException mme) {
@@ -430,7 +433,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements
}
@Override
- public Object invokeStaticMethod(Object object, String name, Object args[]) {
+ public Object invokeStaticMethod(final Object object, final String name, final Object args[]) {
try {
return super.invokeStaticMethod(object, name, args);
} catch (MissingMethodException mme) {