Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1278 ba26c372b -> 8b88fe63a
Gremlin-Groovy and Gremlin-Jython (jython) have different semantics around ScriptContext... dar. However, I think that GremlinServer's test suite is bad using GLOBAL_SCOPE -- should use ENGINE_SCOPE. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8b88fe63 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8b88fe63 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8b88fe63 Branch: refs/heads/TINKERPOP-1278 Commit: 8b88fe63aade3b5ba7ce90fa5874461d0147be75 Parents: ba26c37 Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Mon Jun 27 12:32:29 2016 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Mon Jun 27 12:32:29 2016 -0600 ---------------------------------------------------------------------- .../gremlin/groovy/engine/ScriptEngines.java | 16 ++++++++-------- .../python/jsr223/GremlinJythonScriptEngine.java | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8b88fe63/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java index 716e817..5d144ba 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java @@ -123,7 +123,7 @@ public class ScriptEngines implements AutoCloseable { * Compiles a script without executing it. * * @throws UnsupportedOperationException if the {@link ScriptEngine} implementation does not implement - * the {@link javax.script.Compilable} interface. + * the {@link javax.script.Compilable} interface. */ public CompiledScript compile(final String script, final String language) throws ScriptException { if (!scriptEngines.containsKey(language)) @@ -142,7 +142,7 @@ public class ScriptEngines implements AutoCloseable { * Compiles a script without executing it. * * @throws UnsupportedOperationException if the {@link ScriptEngine} implementation does not implement - * the {@link javax.script.Compilable} interface. + * the {@link javax.script.Compilable} interface. */ public CompiledScript compile(final Reader script, final String language) throws ScriptException { if (!scriptEngines.containsKey(language)) @@ -350,7 +350,7 @@ public class ScriptEngines implements AutoCloseable { * thread until that process completes. */ private void awaitControlOp() { - if(controlWaiters.size() > 0 || controlOperationExecuting.get()) { + if (controlWaiters.size() > 0 || controlOperationExecuting.get()) { evalWaiters.add(Thread.currentThread()); LockSupport.park(this); } @@ -371,9 +371,9 @@ public class ScriptEngines implements AutoCloseable { // CompilerCustomizerProvider. the value is a list of arguments to pass to an available constructor. // the arguments must match in terms of type, so given that configuration typically comes from yaml // or properties file, it is best to stick to primitive values when possible here for simplicity. - final Map<String,Object> compilerCustomizerProviders = (Map<String,Object>) config.getOrDefault( + final Map<String, Object> compilerCustomizerProviders = (Map<String, Object>) config.getOrDefault( "compilerCustomizerProviders", Collections.emptyMap()); - compilerCustomizerProviders.forEach((k,v) -> { + compilerCustomizerProviders.forEach((k, v) -> { try { final Class providerClass = Class.forName(k); if (v != null && v instanceof List && ((List) v).size() > 0) { @@ -386,7 +386,7 @@ public class ScriptEngines implements AutoCloseable { final Optional<Constructor> constructor = Stream.of(providerClass.getConstructors()) .filter(c -> c.getParameterCount() == argClasses.length && - allMatch(c.getParameterTypes(), argClasses)) + allMatch(c.getParameterTypes(), argClasses)) .findFirst(); if (constructor.isPresent()) providers.add((CompilerCustomizerProvider) @@ -397,7 +397,7 @@ public class ScriptEngines implements AutoCloseable { } else { providers.add((CompilerCustomizerProvider) providerClass.newInstance()); } - } catch(Exception ex) { + } catch (Exception ex) { logger.warn(String.format("Could not instantiate CompilerCustomizerProvider implementation [%s]. It will not be applied.", k), ex); } }); @@ -428,7 +428,7 @@ public class ScriptEngines implements AutoCloseable { */ private static Bindings mergeBindings(final Bindings bindings, final ScriptEngine engine) { // plugins place "globals" here - see ScriptEnginePluginAcceptor - final Bindings global = engine.getBindings(ScriptContext.ENGINE_SCOPE); + final Bindings global = engine.getBindings(ScriptContext.GLOBAL_SCOPE); if (null == global) return bindings; // merge the globals with the incoming bindings where local bindings "win" http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8b88fe63/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java index 30b5874..514463b 100644 --- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java +++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java @@ -135,12 +135,14 @@ public class GremlinJythonScriptEngine implements ScriptEngine { @Override public Object eval(String script, Bindings n) throws ScriptException { - return this.pyScriptEngine.eval(script, n); + this.pyScriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(n); // TODO: groovy and jython act different + return this.pyScriptEngine.eval(script); } @Override public Object eval(Reader reader, Bindings n) throws ScriptException { - return this.pyScriptEngine.eval(reader, n); + this.pyScriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(n); // TODO: groovy and jython act different + return this.pyScriptEngine.eval(reader); } @Override