This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 7062595  Support loop interruption in Console with ctrl+c
7062595 is described below

commit 7062595b72108e9545eaceb62e45b4ea7d946ed6
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Tue Apr 9 07:56:40 2019 -0400

    Support loop interruption in Console with ctrl+c
    
    Couldn't support this with older versions of groovysh/jline so versions 
before the 3.4.2 line won't be able to break out of while(true){} types of 
situations. CTR
---
 .../groovy/org/apache/tinkerpop/gremlin/console/Console.groovy |  7 +++----
 .../apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy    | 10 +++++++++-
 .../console/jsr223/GephiRemoteAcceptorIntegrateTest.java       |  2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 9324f6d..d275dc2 100644
--- 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -47,12 +47,9 @@ import org.codehaus.groovy.tools.shell.IO
 import org.codehaus.groovy.tools.shell.InteractiveShellRunner
 import org.codehaus.groovy.tools.shell.commands.SetCommand
 import org.fusesource.jansi.Ansi
-import picocli.CommandLine
 import sun.misc.Signal
 import sun.misc.SignalHandler
 
-import java.util.concurrent.atomic.AtomicBoolean
-
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
@@ -99,7 +96,7 @@ class Console {
             }
         })
 
-        groovy = new GremlinGroovysh(mediator)
+        groovy = new GremlinGroovysh(mediator, io)
 
         def commandsToRemove = groovy.getRegistry().commands().findAll { it 
instanceof SetCommand }
         commandsToRemove.each { groovy.getRegistry().remove(it) }
@@ -121,6 +118,8 @@ class Console {
         imports.getFieldClasses().collect { Mediator.IMPORT_STATIC_SPACE + 
it.getCanonicalName() + Mediator.IMPORT_WILDCARD}.each{ groovy.execute(it) }
 
         final InteractiveShellRunner runner = new 
InteractiveShellRunner(groovy, handlePrompt)
+        runner.reader.setHandleUserInterrupt(false)
+        runner.reader.setHandleLitteralNext(false)
         runner.setErrorHandler(handleError)
         try {
             final FileHistory history = new FileHistory(new 
File(ConsoleFs.HISTORY_FILE))
diff --git 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
index f5fa16a..96015db 100644
--- 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
+++ 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
@@ -18,9 +18,13 @@
  */
 package org.apache.tinkerpop.gremlin.console
 
+import groovy.transform.ThreadInterrupt
 import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
 import org.codehaus.groovy.tools.shell.Command
 import org.codehaus.groovy.tools.shell.Groovysh
+import org.codehaus.groovy.tools.shell.IO
 import org.codehaus.groovy.tools.shell.ParseCode
 import org.codehaus.groovy.tools.shell.Parser
 import org.codehaus.groovy.tools.shell.util.CommandArgumentParser
@@ -33,8 +37,12 @@ import 
org.codehaus.groovy.tools.shell.util.CommandArgumentParser
 class GremlinGroovysh extends Groovysh {
 
     private final Mediator mediator
+    private final static CompilerConfiguration compilerConfig = new 
CompilerConfiguration(CompilerConfiguration.DEFAULT) {{
+        addCompilationCustomizers(new 
ASTTransformationCustomizer(ThreadInterrupt.class))
+    }}
 
-    public GremlinGroovysh(final Mediator mediator) {
+    public GremlinGroovysh(final Mediator mediator, final IO io) {
+        super(io, compilerConfig)
         this.mediator = mediator
     }
 
diff --git 
a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptorIntegrateTest.java
 
b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptorIntegrateTest.java
index 9a1c541..b1f8eff 100644
--- 
a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptorIntegrateTest.java
+++ 
b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/GephiRemoteAcceptorIntegrateTest.java
@@ -55,7 +55,7 @@ import static org.junit.Assert.assertThat;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class GephiRemoteAcceptorIntegrateTest {
-    private static final Groovysh groovysh = new GremlinGroovysh(new 
Mediator(null));
+    private static final Groovysh groovysh = new GremlinGroovysh(new 
Mediator(null), new IO());
     private static int port = pickOpenPort();
 
     private GephiRemoteAcceptor acceptor;

Reply via email to