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/d6fcb927
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d6fcb927
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d6fcb927

Branch: refs/heads/TINKERPOP-1562
Commit: d6fcb927a79d1e6af637377f5ae7b5c66c98caf4
Parents: 6e6dd1b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Nov 26 07:37:28 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Dec 1 06:41:43 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/d6fcb927/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/d6fcb927/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());
+    }
 }

Reply via email to