tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [01/50] tinkerpop git commit: TINKERPOP-1562 Abstracted groovysh/io to GremlinShellEnvironment [Forced Update!]
Date Fri, 16 Dec 2016 15:55:02 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1490 2cb737ef8 -> 79dac23b2 (forced update)


TINKERPOP-1562 Abstracted groovysh/io to GremlinShellEnvironment

The GremlinShellEnvironment provides a way to abstract groovysh and io classes (i.e. groovy
specific classes) so that plugins don't need to depend on gremlin-groovy at all.


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

Branch: refs/heads/TINKERPOP-1490
Commit: 2efa2e4b75ea8032355677165097b492f2979aa8
Parents: 35c8fcd
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Nov 23 17:10:13 2016 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Fri Dec 2 06:28:51 2016 -0500

----------------------------------------------------------------------
 .../console/jsr223/GephiRemoteAcceptor.groovy   | 15 ++++----
 .../console/plugin/GephiRemoteAcceptor.groovy   |  2 ++
 .../gremlin/console/plugin/PluggedIn.groovy     | 26 +++++++++++++-
 .../console/jsr223/DriverGremlinPlugin.java     |  8 ++---
 .../console/jsr223/DriverRemoteAcceptor.java    | 16 ++++-----
 .../console/jsr223/GephiGremlinPlugin.java      | 10 ++----
 .../jsr223/console/ConsoleCustomizer.java       |  7 +---
 .../jsr223/console/GremlinShellEnvironment.java | 37 ++++++++++++++++++++
 .../hadoop/jsr223/HadoopGremlinPlugin.java      |  7 ++--
 .../hadoop/jsr223/HadoopRemoteAcceptor.java     | 22 ++++++------
 10 files changed, 99 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptor.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptor.groovy
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptor.groovy
index dbc1156..4e41fa4 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptor.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptor.groovy
@@ -29,14 +29,13 @@ import org.apache.http.impl.client.CloseableHttpClient
 import org.apache.http.impl.client.HttpClients
 import org.apache.http.util.EntityUtils
 import org.apache.tinkerpop.gremlin.console.plugin.GephiTraversalVisualizationStrategy
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteException
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
 import org.apache.tinkerpop.gremlin.structure.Edge
 import org.apache.tinkerpop.gremlin.structure.Graph
 import org.apache.tinkerpop.gremlin.structure.Vertex
-import org.codehaus.groovy.tools.shell.Groovysh
-import org.codehaus.groovy.tools.shell.IO
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -48,8 +47,7 @@ class GephiRemoteAcceptor implements RemoteAcceptor {
     private int port = 8080
     private String workspace = "workspace1"
 
-    private final Groovysh shell
-    private final IO io
+    private final GremlinShellEnvironment shell
 
     private final Random rand = new Random();
     boolean traversalSubmittedForViz = false
@@ -64,9 +62,8 @@ class GephiRemoteAcceptor implements RemoteAcceptor {
 
     private CloseableHttpClient httpclient = HttpClients.createDefault();
 
-    public GephiRemoteAcceptor(final Groovysh shell, final IO io) {
+    public GephiRemoteAcceptor(final GremlinShellEnvironment shell) {
         this.shell = shell
-        this.io = io
 
         // traversal visualization defaults
         vizStepDelay = 1000;                 // 1 second pause between viz of steps
@@ -129,13 +126,13 @@ class GephiRemoteAcceptor implements RemoteAcceptor {
         else if (args[0] == "startSize")
             parseVizStartSize(args[1])
         else if (args[0] == "visualTraversal") {
-            def graphVar = shell.interp.context.getVariable(args[1])
+            def graphVar = shell.getVariable(args[1])
             if (!(graphVar instanceof Graph))
                 throw new RemoteException("Invalid argument to 'visualTraversal' - first
parameter must be a Graph instance")
 
             def gVar = args.size() == 3 ? args[2] : "vg"
             def theG = GraphTraversalSource.build().with(new GephiTraversalVisualizationStrategy(this)).create(graphVar)
-            shell.interp.context.setVariable(gVar, theG)
+            shell.setVariable(gVar, theG)
         } else
             throw new RemoteException("Invalid config arguments - check syntax")
 
@@ -151,7 +148,7 @@ class GephiRemoteAcceptor implements RemoteAcceptor {
         final String line = String.join(" ", args)
         if (line.trim() == "clear") {
             clearGraph()
-            io.out.println("Gephi workspace cleared")
+            shell.println("Gephi workspace cleared")
             return
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/GephiRemoteAcceptor.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/GephiRemoteAcceptor.groovy
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/GephiRemoteAcceptor.groovy
index 4198444..902a479 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/GephiRemoteAcceptor.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/GephiRemoteAcceptor.groovy
@@ -40,7 +40,9 @@ import org.codehaus.groovy.tools.shell.IO
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  * @author Randall Barnhart (randompi@gmail.com)
+ * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.console.jsr223.GephiRemoteAcceptor}
  */
+@Deprecated
 class GephiRemoteAcceptor implements RemoteAcceptor {
 
     private String host = "localhost"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
index 7a08a9d..364e6ef 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.jsr223.BindingsCustomizer
 import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer
 import org.apache.tinkerpop.gremlin.jsr223.ScriptCustomizer
 import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment
 import org.codehaus.groovy.tools.shell.Groovysh
 import org.codehaus.groovy.tools.shell.IO
 
@@ -111,7 +112,30 @@ class PluggedIn {
                 return Optional.empty()
 
             ConsoleCustomizer customizer = (ConsoleCustomizer) corePlugin.getCustomizers("gremlin-groovy").get().find{
it instanceof ConsoleCustomizer }
-            return Optional.of(new RemoteAcceptorAdapter(customizer.getRemoteAcceptor([(ConsoleCustomizer.ENV_CONSOLE_SHELL):
shell, (ConsoleCustomizer.ENV_CONSOLE_IO): io])))
+            return Optional.of(new RemoteAcceptorAdapter(customizer.getRemoteAcceptor(new
GroovyGremlinShellEnvironment())))
+        }
+
+        public class GroovyGremlinShellEnvironment implements GremlinShellEnvironment {
+
+            @Override
+            def <T> T getVariable(final String variableName) {
+                return (T) shell.interp.context.getVariable(variableName)
+            }
+
+            @Override
+            def <T> void setVariable(final String variableName, final T variableValue)
{
+                shell.interp.context.setVariable(variableName, variableValue)
+            }
+
+            @Override
+            void println(final String line) {
+                io.println(line)
+            }
+
+            @Override
+            def <T> T execute(final String line) {
+                return (T) shell.execute(line)
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverGremlinPlugin.java
b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverGremlinPlugin.java
index 89cec10..fb78ee9 100644
--- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverGremlinPlugin.java
+++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverGremlinPlugin.java
@@ -51,9 +51,7 @@ import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
 import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
 import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
 import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer;
-import org.codehaus.groovy.tools.shell.Groovysh;
-
-import java.util.Map;
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -99,8 +97,8 @@ public class DriverGremlinPlugin extends AbstractGremlinPlugin {
 
     private static class DriverConsoleCustomizer implements ConsoleCustomizer {
         @Override
-        public org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor getRemoteAcceptor(final
Map<String, Object> environment) {
-            return new DriverRemoteAcceptor((Groovysh) environment.get(ConsoleCustomizer.ENV_CONSOLE_SHELL));
+        public org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor getRemoteAcceptor(final
GremlinShellEnvironment environment) {
+            return new DriverRemoteAcceptor(environment);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
index 93ac184..aa02606 100644
--- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
+++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
@@ -25,10 +25,10 @@ import org.apache.tinkerpop.gremlin.driver.Result;
 import org.apache.tinkerpop.gremlin.driver.ResultSet;
 import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor;
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteException;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-import org.codehaus.groovy.tools.shell.Groovysh;
 
 import javax.security.sasl.SaslException;
 import java.io.FileNotFoundException;
@@ -75,10 +75,10 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
     private static final String TOKEN_SESSION_MANAGED = "session-managed";
     private static final List<String> POSSIBLE_TOKENS = Arrays.asList(TOKEN_TIMEOUT,
TOKEN_ALIAS);
 
-    private final Groovysh shell;
+    private final GremlinShellEnvironment shellEnvironment;
 
-    public DriverRemoteAcceptor(final Groovysh shell) {
-        this.shell = shell;
+    public DriverRemoteAcceptor(final GremlinShellEnvironment shellEnvironment) {
+        this.shellEnvironment = shellEnvironment;
     }
 
     @Override
@@ -152,11 +152,11 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
 
     @Override
     public Object submit(final List<String> args) throws RemoteException {
-        final String line = getScript(String.join(" ", args), this.shell);
+        final String line = getScript(String.join(" ", args), this.shellEnvironment);
 
         try {
             final List<Result> resultSet = send(line);
-            this.shell.getInterp().getContext().setProperty(RESULT, resultSet);
+            this.shellEnvironment.setVariable(RESULT, resultSet);
             return resultSet.stream().map(result -> result.getObject()).iterator();
         } catch (SaslException sasl) {
             throw new RemoteException("Security error - check username/password and related
settings", sasl);
@@ -232,7 +232,7 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
     /**
      * Retrieve a script as defined in the shell context.  This allows for multi-line scripts
to be submitted.
      */
-    public static String getScript(final String submittedScript, final Groovysh shell) {
-        return submittedScript.startsWith("@") ? shell.getInterp().getContext().getProperty(submittedScript.substring(1)).toString()
: submittedScript;
+    public static String getScript(final String submittedScript, final GremlinShellEnvironment
shellEnvironment) {
+        return submittedScript.startsWith("@") ? shellEnvironment.getVariable(submittedScript.substring(1)).toString()
: submittedScript;
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiGremlinPlugin.java
b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiGremlinPlugin.java
index 7698112..c30f864 100644
--- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiGremlinPlugin.java
+++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiGremlinPlugin.java
@@ -20,10 +20,7 @@ package org.apache.tinkerpop.gremlin.console.jsr223;
 
 import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
 import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer;
-import org.codehaus.groovy.tools.shell.Groovysh;
-import org.codehaus.groovy.tools.shell.IO;
-
-import java.util.Map;
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -37,9 +34,8 @@ public class GephiGremlinPlugin extends AbstractGremlinPlugin {
 
     private static class GephiConsoleCustomizer implements ConsoleCustomizer {
         @Override
-        public org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor getRemoteAcceptor(final
Map<String, Object> environment) {
-            return new GephiRemoteAcceptor((Groovysh) environment.get(ConsoleCustomizer.ENV_CONSOLE_SHELL),
-                    (IO) environment.get(ConsoleCustomizer.ENV_CONSOLE_IO));
+        public org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor getRemoteAcceptor(final
GremlinShellEnvironment gremlinShellEnvironment) {
+            return new GephiRemoteAcceptor(gremlinShellEnvironment);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
index 7b3d788..9204488 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
@@ -20,19 +20,14 @@ package org.apache.tinkerpop.gremlin.jsr223.console;
 
 import org.apache.tinkerpop.gremlin.jsr223.Customizer;
 
-import java.util.Map;
-
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public interface ConsoleCustomizer extends Customizer {
-    public static final String ENV_CONSOLE_IO = "ConsolePluginAcceptor.io";
-    public static final String ENV_CONSOLE_SHELL = "ConsolePluginAcceptor.shell";
-
     /**
      * Allows a plugin to utilize features of the {@code :remote} and {@code :submit} commands
of the Gremlin Console.
      * This method does not need to be implemented if the plugin is not meant for the Console
for some reason or
      * if it does not intend to take advantage of those commands.
      */
-    public RemoteAcceptor getRemoteAcceptor(final Map<String, Object> environment);
+    public RemoteAcceptor getRemoteAcceptor(final GremlinShellEnvironment environment);
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
new file mode 100644
index 0000000..6fc1363
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
@@ -0,0 +1,37 @@
+/*
+ * 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.console;
+
+/**
+ * Provides an abstraction over a "Gremlin Shell" (i.e. the core of a console), enabling
the plugin to not have to
+ * be hardcoded specifically to any particular shell, like the Gremlin Groovy Console, and
thus allowing it to
+ * not have to depend on the gremlin-groovy module itself.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public interface GremlinShellEnvironment {
+
+    public <T> T getVariable(final String variableName);
+
+    public <T> void setVariable(final String variableName, final T variableValue);
+
+    public void println(final String line);
+
+    public <T> T execute(final String line);
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
index 5e21027..b7403b6 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
@@ -53,14 +53,13 @@ import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
 import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
 import org.apache.tinkerpop.gremlin.jsr223.LazyBindingsCustomizer;
 import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor;
-import org.codehaus.groovy.tools.shell.Groovysh;
 
 import javax.script.Bindings;
 import javax.script.SimpleBindings;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 
@@ -147,8 +146,8 @@ public final class HadoopGremlinPlugin extends AbstractGremlinPlugin {
 
     private static class HadoopConsoleCustomizer implements ConsoleCustomizer {
         @Override
-        public RemoteAcceptor getRemoteAcceptor(final Map<String, Object> environment)
{
-            return new HadoopRemoteAcceptor((Groovysh) environment.get(ConsoleCustomizer.ENV_CONSOLE_SHELL));
+        public RemoteAcceptor getRemoteAcceptor(final GremlinShellEnvironment environment)
{
+            return new HadoopRemoteAcceptor(environment);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2efa2e4b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
index f2367bd..1fcdab1 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.hadoop.jsr223;
 
 import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
 import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph;
+import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor;
 import org.apache.tinkerpop.gremlin.jsr223.console.RemoteException;
 import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
@@ -30,7 +31,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
-import org.codehaus.groovy.tools.shell.Groovysh;
 
 import java.io.IOException;
 import java.util.Collections;
@@ -47,12 +47,12 @@ public final class HadoopRemoteAcceptor implements RemoteAcceptor {
     private static final String SPACE = " ";
 
     private HadoopGraph hadoopGraph;
-    private Groovysh shell;
+    private GremlinShellEnvironment shellEnvironment;
     private boolean useSugar = false;
     private TraversalSource traversalSource;
 
-    public HadoopRemoteAcceptor(final Groovysh shell) {
-        this.shell = shell;
+    public HadoopRemoteAcceptor(final GremlinShellEnvironment shellEnvironment) {
+        this.shellEnvironment = shellEnvironment;
     }
 
     @Override
@@ -60,9 +60,9 @@ public final class HadoopRemoteAcceptor implements RemoteAcceptor {
         if (args.size() != 1 && args.size() != 2) {
             throw new IllegalArgumentException("Usage: :remote connect " + HadoopGremlinPlugin.NAME
+ " <variable name of graph> <optional variable name of traversal source>");
         }
-        this.hadoopGraph = (HadoopGraph) this.shell.getInterp().getContext().getVariable(args.get(0));
+        this.hadoopGraph = this.shellEnvironment.getVariable(args.get(0));
         if (args.size() == 2)
-            this.traversalSource = ((TraversalSource) this.shell.getInterp().getContext().getVariable(args.get(1)));
+            this.traversalSource = this.shellEnvironment.getVariable(args.get(1));
         else
             this.traversalSource = this.hadoopGraph.traversal();
         ///
@@ -78,7 +78,7 @@ public final class HadoopRemoteAcceptor implements RemoteAcceptor {
             if (args.get(i).equals(USE_SUGAR))
                 this.useSugar = Boolean.valueOf(args.get(i + 1));
             else if (args.get(i).equals(USE_TRAVERSAL_SOURCE)) {
-                this.traversalSource = ((TraversalSource) this.shell.getInterp().getContext().getVariable(args.get(i
+ 1)));
+                this.traversalSource = this.shellEnvironment.getVariable(args.get(i + 1));
             } else
                 throw new IllegalArgumentException("The provided configuration is unknown:
" + args.get(i) + ":" + args.get(i + 1));
         }
@@ -92,12 +92,12 @@ public final class HadoopRemoteAcceptor implements RemoteAcceptor {
     @Override
     public Object submit(final List<String> args) throws RemoteException {
         try {
-            String script = getScript(String.join(SPACE, args), this.shell);
+            String script = getScript(String.join(SPACE, args), this.shellEnvironment);
             if (this.useSugar)
                 script = SugarLoader.class.getCanonicalName() + ".load()\n" + script;
             final TraversalVertexProgram program = TraversalVertexProgram.build().traversal(this.traversalSource,
"gremlin-groovy", script).create(this.hadoopGraph);
             final ComputerResult computerResult = VertexProgramStrategy.getComputer(this.traversalSource.getStrategies()).get().apply(this.hadoopGraph).program(program).submit().get();
-            this.shell.getInterp().getContext().setVariable(RESULT, computerResult);
+            this.shellEnvironment.setVariable(RESULT, computerResult);
             ///
             final Traversal.Admin<ComputerResult, ?> traversal = new DefaultTraversal<>(computerResult.graph());
             traversal.addStep(new ComputerResultStep<>(traversal));
@@ -121,7 +121,7 @@ public final class HadoopRemoteAcceptor implements RemoteAcceptor {
     /**
      * Retrieve a script as defined in the shell context.  This allows for multi-line scripts
to be submitted.
      */
-    public static String getScript(final String submittedScript, final Groovysh shell) {
-        return submittedScript.startsWith("@") ? shell.getInterp().getContext().getProperty(submittedScript.substring(1)).toString()
: submittedScript;
+    public static String getScript(final String submittedScript, final GremlinShellEnvironment
shell) {
+        return submittedScript.startsWith("@") ? shell.getVariable(submittedScript.substring(1)).toString()
: submittedScript;
     }
 }


Mime
View raw message