You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/05/01 18:29:50 UTC

incubator-tinkerpop git commit: updated the preprocessor.sh to show the line and line number that failed if there is an Exception when processing the ascii source docs. fixed up traversal docs with Optional semantics work on TraveraslSideEffects.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 8e31f7c5d -> a9466cebf


updated the preprocessor.sh to show the line and line number that failed if there is an Exception when processing the ascii source docs. fixed up traversal docs with Optional semantics work on TraveraslSideEffects.


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

Branch: refs/heads/master
Commit: a9466cebf358829fb71298660fe25195434191ea
Parents: 8e31f7c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri May 1 10:29:44 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri May 1 10:29:44 2015 -0600

----------------------------------------------------------------------
 docs/preprocessor/processor.groovy | 137 +++++++++++++++++---------------
 docs/src/the-traversal.asciidoc    |   4 +-
 2 files changed, 74 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a9466ceb/docs/preprocessor/processor.groovy
----------------------------------------------------------------------
diff --git a/docs/preprocessor/processor.groovy b/docs/preprocessor/processor.groovy
index 627c0af..093f82b 100644
--- a/docs/preprocessor/processor.groovy
+++ b/docs/preprocessor/processor.groovy
@@ -24,8 +24,6 @@ import org.apache.tinkerpop.gremlin.process.computer.util.ScriptEngineCache
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
 
-import javax.script.ScriptContext
-
 def BLOCK_DELIMITER = "----"
 def RESULT_PREFIX = "==>"
 def STATEMENT_CONTINUATION_CHARACTERS = [".", ",", "{", "("]
@@ -43,6 +41,8 @@ def imports = new org.apache.tinkerpop.gremlin.console.ConsoleImportCustomizerPr
 def skipNextRead = false
 def inCodeSection = false
 def engine
+def lineNumber = 0;
+def line = "";
 
 sanitize = { def codeLine ->
     codeLine.replaceAll(/\s*(\<\d+\>\s*)*\<\d+\>\s*$/, "").replaceAll(/\s*\/\/.*$/, "").trim()
@@ -53,76 +53,83 @@ format = { def codeLine ->
 }
 
 new File(this.args[0]).withReader { reader ->
-    while (skipNextRead || (line = reader.readLine()) != null) {
-        skipNextRead = false
-        if (inCodeSection) {
-            inCodeSection = !line.equals(BLOCK_DELIMITER)
+    try {
+        while (skipNextRead || (line = reader.readLine()) != null) {
+            lineNumber++;
+            skipNextRead = false
             if (inCodeSection) {
-                def script = new StringBuilder(header.toString())
-                imports.getCombinedImports().each { script.append("import ${it}\n") }
-                imports.getCombinedStaticImports().each { script.append("import static ${it}\n") }
-                def sanitizedLine = sanitize(line)
-                script.append(sanitizedLine)
-                println STATEMENT_PREFIX + format(line)
-                if (!sanitizedLine.isEmpty() && sanitizedLine[-1] in STATEMENT_CONTINUATION_CHARACTERS) {
-                    while (true) {
-                        line = reader.readLine()
-                        if (!line.startsWith(" ") && !line.startsWith("}") && !line.startsWith(")") || line.equals(BLOCK_DELIMITER)) {
-                            skipNextRead = true
-                            break
+                inCodeSection = !line.equals(BLOCK_DELIMITER)
+                if (inCodeSection) {
+                    def script = new StringBuilder(header.toString())
+                    imports.getCombinedImports().each { script.append("import ${it}\n") }
+                    imports.getCombinedStaticImports().each { script.append("import static ${it}\n") }
+                    def sanitizedLine = sanitize(line)
+                    script.append(sanitizedLine)
+                    println STATEMENT_PREFIX + format(line)
+                    if (!sanitizedLine.isEmpty() && sanitizedLine[-1] in STATEMENT_CONTINUATION_CHARACTERS) {
+                        while (true) {
+                            line = reader.readLine()
+                            if (!line.startsWith(" ") && !line.startsWith("}") && !line.startsWith(")") || line.equals(BLOCK_DELIMITER)) {
+                                skipNextRead = true
+                                break
+                            }
+                            sanitizedLine = sanitize(line)
+                            script.append(sanitizedLine)
+                            println STATEMENT_CONTINUATION_PREFIX + format(line)
                         }
-                        sanitizedLine = sanitize(line)
-                        script.append(sanitizedLine)
-                        println STATEMENT_CONTINUATION_PREFIX + format(line)
-                    }
-                }
-                if (line.startsWith("import ")) {
-                    println "..."
-                } else {
-                    if (line.equals(BLOCK_DELIMITER)) {
-                        skipNextRead = false
-                        inCodeSection = false
-                    }
-                    def res
-                    try {
-                       res = engine.eval(script.toString())
-                    } catch (e) {
-                       e.printStackTrace()
-                       System.exit(1)
-                    }
-                    if (res instanceof Map) {
-                        res = res.entrySet()
-                    }
-                    if (res instanceof Iterable) {
-                        res = res.iterator()
                     }
-                    if (res instanceof Iterator) {
-                        while (res.hasNext()) {
-                            def current = res.next()
-                            println RESULT_PREFIX + (current ?: "null")
+                    if (line.startsWith("import ")) {
+                        println "..."
+                    } else {
+                        if (line.equals(BLOCK_DELIMITER)) {
+                            skipNextRead = false
+                            inCodeSection = false
+                        }
+                        def res = engine.eval(script.toString())
+
+                        if (res instanceof Map) {
+                            res = res.entrySet()
+                        }
+                        if (res instanceof Iterable) {
+                            res = res.iterator()
+                        }
+                        if (res instanceof Iterator) {
+                            while (res.hasNext()) {
+                                def current = res.next()
+                                println RESULT_PREFIX + (current ?: "null")
+                            }
+                        } else if (!line.isEmpty() && !line.startsWith("//")) {
+                            println RESULT_PREFIX + (res ?: "null")
                         }
-                    } else if (!line.isEmpty() && !line.startsWith("//")) {
-                        println RESULT_PREFIX + (res ?: "null")
                     }
                 }
+                if (!inCodeSection) println BLOCK_DELIMITER
+            } else {
+                if (line.startsWith("[gremlin-")) {
+                    def parts = line.split(/,/, 2)
+                    def graphString = parts.size() == 2 ? parts[1].capitalize().replaceAll(/\s*\]\s*$/, "") : ""
+                    def lang = parts[0].split(/-/, 2)[1].replaceAll(/\s*\]\s*$/, "")
+                    def graph = graphString.isEmpty() ? TinkerGraph.open() : TinkerFactory."create${graphString}"()
+                    def g = graph.traversal(standard())
+                    engine = ScriptEngineCache.get(lang)
+                    engine.put("graph", graph)
+                    engine.put("g", g)
+                    engine.put("marko", g.V().has("name", "marko").tryNext().orElse(null))
+                    reader.readLine()
+                    inCodeSection = true
+                    println "[source,${lang}]"
+                    println BLOCK_DELIMITER
+                } else println line
             }
-            if (!inCodeSection) println BLOCK_DELIMITER
-        } else {
-            if (line.startsWith("[gremlin-")) {
-                def parts = line.split(/,/, 2)
-                def graphString = parts.size() == 2 ? parts[1].capitalize().replaceAll(/\s*\]\s*$/, "") : ""
-                def lang = parts[0].split(/-/, 2)[1].replaceAll(/\s*\]\s*$/, "")
-                def graph = graphString.isEmpty() ? TinkerGraph.open() : TinkerFactory."create${graphString}"()
-                def g = graph.traversal(standard())
-                engine = ScriptEngineCache.get(lang)
-                engine.put("graph",graph)
-                engine.put("g", g)
-                engine.put("marko", g.V().has("name", "marko").tryNext().orElse(null))
-                reader.readLine()
-                inCodeSection = true
-                println "[source,${lang}]"
-                println BLOCK_DELIMITER
-            } else println line
+        }
+    } catch (final Throwable e) {
+        try {
+            e.printStackTrace()
+            throw new IllegalArgumentException("The script that failed:\n(${lineNumber}) ${line}");
+        } catch (final Exception e1) {
+            e1.printStackTrace();
+            System.exit(1);
         }
     }
 }
+

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a9466ceb/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index 8e18694..ae94e62 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -1262,8 +1262,8 @@ There can be multiple `subgraph()` calls within the same traversal. Each operati
 ----
 t = g.V().outE('knows').subgraph('knowsG').inV().outE('created').subgraph('createdG').
           inV().inE('created').subgraph('createdG').iterate()
-t.sideEffects.get('knowsG').traversal(standard()).E()
-t.sideEffects.get('createdG').traversal(standard()).E()
+t.sideEffects.get('knowsG').get().traversal(standard()).E()
+t.sideEffects.get('createdG').get().traversal(standard()).E()
 ----
 
 IMPORTANT: The `subgraph()`-step only writes to graphs that support user supplied ids for its elements. Moreover, if no graph is specified via `withSideEffect()`, then <<tinkergraph-gremlin,TinkerGraph>> is assumed.