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 2016/12/16 15:55:10 UTC

[09/50] tinkerpop git commit: TINKERPOP-1562 Get customizers for both python and jython.

TINKERPOP-1562 Get customizers for both python and jython.

The customizers are combined to a set and therefore should only apply once. Presumably there wouldn't be a different set of customizers for one versus the other. If there were and you wanted them separate I guess you'd have to build two separate script engine instances.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9f33bee4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9f33bee4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9f33bee4

Branch: refs/heads/TINKERPOP-1490
Commit: 9f33bee4d75ee359c6687d4b777bb687a459925f
Parents: 05ff0c0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Nov 26 07:37:28 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Dec 2 06:31:49 2016 -0500

----------------------------------------------------------------------
 .../python/jsr223/GremlinJythonScriptEngineFactory.java  |  6 +++++-
 .../gremlin/jsr223/GremlinEnabledScriptEngineTest.java   | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9f33bee4/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
index 696c2ea..34978a7 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
@@ -29,7 +29,9 @@ import org.python.jsr223.PyScriptEngineFactory;
 import javax.script.ScriptEngine;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -101,7 +103,9 @@ public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory impl
 
     @Override
     public GremlinScriptEngine getScriptEngine() {
-        final List<Customizer> customizers =  manager.getCustomizers(GREMLIN_JYTHON);
+        final Set<Customizer> customizers = new HashSet<>(manager.getCustomizers(GREMLIN_JYTHON));
+        customizers.addAll(manager.getCustomizers(GREMLIN_PYTHON));
+
         return (customizers.isEmpty()) ? new GremlinJythonScriptEngine() :
                 new GremlinJythonScriptEngine(customizers.toArray(new Customizer[customizers.size()]));
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9f33bee4/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinEnabledScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinEnabledScriptEngineTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinEnabledScriptEngineTest.java
index f6bbcb8..8fa70b0 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinEnabledScriptEngineTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/GremlinEnabledScriptEngineTest.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.junit.Test;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 
@@ -79,4 +80,14 @@ public class GremlinEnabledScriptEngineTest {
             assertEquals(clazz, scriptEngine.eval(clazz.getSimpleName()));
         }
     }
+
+    @Test
+    public void shouldReturnOneCustomizers() {
+        // just returns the core plugin as the other assigned plugin doesn't match the tested engine
+        final GremlinScriptEngineManager mgr = new DefaultGremlinScriptEngineManager();
+        mgr.addPlugin(ImportGremlinPlugin.build()
+                .classImports(java.awt.Color.class)
+                .appliesTo(Collections.singletonList("fake-script-engine")).create());
+        assertEquals(1, mgr.getCustomizers(ENGINE_TO_TEST).size());
+    }
 }