TINKERPOP-1562 Moved ScriptEngineCache to jsr223 package.

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

Branch: refs/heads/TINKERPOP-1562
Commit: 117c8863ef43a6ef741ad516fecfb4a0b510b11a
Parents: c76eccc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Dec 1 06:48:22 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Dec 1 06:48:22 2016 -0500

----------------------------------------------------------------------
 .../gremlin/jsr223/ScriptEngineCache.java       | 54 ++++++++++++++++++++
 .../gremlin/util/ScriptEngineCache.java         |  4 +-
 .../gremlin/jsr223/ScriptEngineCacheTest.java   | 46 +++++++++++++++++
 .../python/jsr223/JythonScriptEngineSetup.java  |  2 +-
 .../python/jsr223/JythonTranslatorTest.java     | 10 ----
 .../jsr223/PythonGraphSONJavaTranslator.java    |  2 +-
 .../gremlin/python/jsr223/PythonProvider.java   |  5 +-
 7 files changed, 106 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCache.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCache.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCache.java
new file mode 100644
index 0000000..9d2848d
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCache.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.jsr223;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A cache of standard {@code ScriptEngine} instances, instantiated by the 
standard {@code ScriptEngineManager}.
+ * These instances are NOT "Gremlin-enabled". See {@link 
SingleGremlinScriptEngineManager} for the analogous class
+ * that loads {@link GremlinScriptEngine} instances.
+ *
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public final class ScriptEngineCache {
+
+    private ScriptEngineCache() {}
+
+    public final static String DEFAULT_SCRIPT_ENGINE = "gremlin-groovy";
+
+    private final static ScriptEngineManager SCRIPT_ENGINE_MANAGER = new 
ScriptEngineManager();
+    private final static Map<String, ScriptEngine> CACHED_ENGINES = new 
ConcurrentHashMap<>();
+
+    public static ScriptEngine get(final String engineName) {
+        return CACHED_ENGINES.compute(engineName, (key, engine) -> {
+            if (null == engine) {
+                engine = SCRIPT_ENGINE_MANAGER.getEngineByName(engineName);
+                if (null == engine) {
+                    throw new IllegalArgumentException("There is no script 
engine with provided name: " + engineName);
+                }
+            }
+            return engine;
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java
index 1ce7d05..dc4aeb7 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java
@@ -28,12 +28,14 @@ import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * A cache of standard {@code ScriptEngine} instances, instantiated by the 
standard {@code ScriptEngineManager}.
- * These instances are not "Gremlin-enabled". See {@link 
SingleGremlinScriptEngineManager} for the analogous class
+ * These instances are NOT "Gremlin-enabled". See {@link 
SingleGremlinScriptEngineManager} for the analogous class
  * that loads {@link GremlinScriptEngine} instances.
  *
  * @author Daniel Kuppitz (http://gremlin.guru)
  * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @deprecated As of release 3.2.4, replaced by {@link 
org.apache.tinkerpop.gremlin.jsr223.ScriptEngineCache}.
  */
+@Deprecated
 public final class ScriptEngineCache {
 
     private ScriptEngineCache() {}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCacheTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCacheTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCacheTest.java
new file mode 100644
index 0000000..7cdbdc2
--- /dev/null
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/jsr223/ScriptEngineCacheTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.jsr223;
+
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ScriptEngineCacheTest {
+
+    @Test
+    public void shouldBeUtilityClass() throws Exception {
+        TestHelper.assertIsUtilityClass(ScriptEngineCache.class);
+    }
+
+    @Test
+    public void shouldGetEngineFromCache() {
+        assertSame(ScriptEngineCache.get("nashorn"), 
ScriptEngineCache.get("nashorn"));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldThrowWhenScripEngineDoesNotExist() {
+        
ScriptEngineCache.get("junk-that-no-one-would-ever-call-a-script-engine-83939473298432");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
----------------------------------------------------------------------
diff --git 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
index a16ce30..a4fe1ed 100644
--- 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
+++ 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
@@ -19,7 +19,7 @@
 
 package org.apache.tinkerpop.gremlin.python.jsr223;
 
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+import org.apache.tinkerpop.gremlin.jsr223.ScriptEngineCache;
 import org.python.jsr223.PyScriptEngine;
 
 import javax.script.ScriptException;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index 8bd3265..5a6e30d 100644
--- 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -19,26 +19,16 @@
 
 package org.apache.tinkerpop.gremlin.python.jsr223;
 
-import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
 import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
-import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.junit.Test;
 
-import javax.script.Bindings;
-import javax.script.SimpleBindings;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
----------------------------------------------------------------------
diff --git 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
index cdeb407..740fe1f 100644
--- 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
+++ 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
@@ -20,6 +20,7 @@
 package org.apache.tinkerpop.gremlin.python.jsr223;
 
 import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
+import org.apache.tinkerpop.gremlin.jsr223.ScriptEngineCache;
 import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.Translator;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
@@ -28,7 +29,6 @@ import 
org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 
 import javax.script.Bindings;
 import javax.script.ScriptContext;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/117c8863/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
----------------------------------------------------------------------
diff --git 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
index fe04156..9e03884 100644
--- 
a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
+++ 
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
@@ -23,12 +23,10 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
+import org.apache.tinkerpop.gremlin.jsr223.ScriptEngineCache;
 import 
org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest;
 import 
org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest;
 import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.PageRankTest;
-import 
org.apache.tinkerpop.gremlin.process.traversal.step.map.PeerPressureTest;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProfileTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest;
 import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest;
 import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest;
@@ -42,7 +40,6 @@ import 
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphVariables;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerProperty;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertexProperty;
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 
 import javax.script.ScriptException;
 import java.util.Arrays;

Reply via email to