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 2015/08/21 15:46:18 UTC

[1/2] incubator-tinkerpop git commit: Added some javadoc for ScriptExecutor.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp30 3a9e1983b -> 1df2012f2


Added some javadoc for ScriptExecutor.


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

Branch: refs/heads/tp30
Commit: 4d032c20b02af1d2eb2b019d84fc27de5e51e7f3
Parents: 3a9e198
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 21 09:23:14 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 21 09:23:14 2015 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4d032c20/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java
index 0f0105c..1d30a5d 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java
@@ -26,7 +26,9 @@ import java.util.Arrays;
 import java.util.List;
 
 /**
- * Executes a Gremlin script from the command line.
+ * Executes a Gremlin script from the command line. Takes a path to the Gremlin script file as the first argument.
+ * Remaining arguments are treated as parameters to the script, where they are batched up into an array and passed
+ * in as a single parameter to the script named "args".
  *
  * @author Pavel A. Yaskevich
  * @author Marko A. Rodriguez (http://markorodriguez.com)


[2/2] incubator-tinkerpop git commit: Added docs on the ScriptExecutor.

Posted by sp...@apache.org.
Added docs on the ScriptExecutor.


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

Branch: refs/heads/tp30
Commit: 1df2012f281535dd8675618562e8a2d0c61f6bf0
Parents: 4d032c2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 21 09:45:26 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 21 09:45:26 2015 -0400

----------------------------------------------------------------------
 docs/src/gremlin-applications.asciidoc | 46 +++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1df2012f/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index c82e68b..cf63054 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -183,6 +183,52 @@ CAUTION: Plugins must be compatible with the version of the Gremlin Console (or
 
 TIP: It is possible to manage plugin activation and deactivation by manually editing the `ext/plugins.txt` file which contains the class names of the "active" plugins.  It is also possible to clear dependencies added by `:install` by deleting them from the `ext` directory.
 
+Script Executor
+~~~~~~~~~~~~~~~
+
+For automated tasks and batch executions of Gremlin, it can be useful to execute Gremlin scripts from the command line.  Consider the following file named `gremlin.groovy`:
+
+[source,groovy]
+----
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
+graph = TinkerFactory.createModern()
+g = graph.traversal()
+g.V().each { println it }
+----
+
+This script creates the toy graph and then iterates through all its vertices printing each to the system out.  Note that under this approach, "imports" need to be explicitly defined (except for "core" TinkerPop classes).  In addition, plugins and other dependencies should already be "installed" via console commands which cannot be used with this mode of execution.  To execute this script from the command line, `gremlin.sh` has the `-e` option used as follows:
+
+[source,bash]
+----
+$ bin/gremlin.sh -e gremlin.groovy
+v[1]
+v[2]
+v[3]
+v[4]
+v[5]
+v[6]
+----
+
+It is also possible to pass arguments to scripts.  Any parameters following the file name specification are treated as arguments to the script. They are collected into a list and passed in as a variable called "args".  The following Gremlin script is exactly like the previous one, but it makes use of the "args" option to filter the vertices printed to system out:
+
+[source,groovy]
+----
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
+graph = TinkerFactory.createModern()
+g = graph.traversal()
+g.V().has('name',args[0]).each { println it }
+----
+
+When executed from the command line a parameter can be supplied:
+
+[source,bash]
+----
+$ bin/gremlin.sh -e gremlin.groovy marko
+v[1]
+$ bin/gremlin.sh -e gremlin.groovy vadas
+v[2]
+----
+
 [[gremlin-server]]
 Gremlin Server
 --------------