karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject karaf git commit: [KARAF-4926] Fix "bin/shell command" never stopping
Date Fri, 06 Jan 2017 08:23:54 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 3672a6022 -> 0b6b68a63


[KARAF-4926] Fix "bin/shell command" never stopping

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/0b6b68a6
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/0b6b68a6
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/0b6b68a6

Branch: refs/heads/master
Commit: 0b6b68a632fd18b8dbf323fb9782ca41b4d0b9a3
Parents: 3672a60
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Fri Jan 6 09:23:49 2017 +0100
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Fri Jan 6 09:23:49 2017 +0100

----------------------------------------------------------------------
 .../shell/impl/console/ConsoleSessionImpl.java  | 32 ++++++++--------
 .../shell/impl/console/standalone/Main.java     | 39 ++++++++++----------
 2 files changed, 35 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/0b6b68a6/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index 970668c..eff48de 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -264,24 +264,22 @@ public class ConsoleSessionImpl implements Session {
     }
 
     public void close() {
-        if (!running) {
-            return;
-        }
-//        out.println();
-        reader.getHistory().save();
+        if (running) {
+            reader.getHistory().save();
 
-        running = false;
-        if (thread != Thread.currentThread()) {
-            thread.interrupt();
-        }
-        if (closeCallback != null) {
-            closeCallback.run();
-        }
-        if (terminal instanceof AutoCloseable) {
-            try {
-                ((AutoCloseable) terminal).close();
-            } catch (Exception e) {
-                // Ignore
+            running = false;
+            if (thread != Thread.currentThread()) {
+                thread.interrupt();
+            }
+            if (closeCallback != null) {
+                closeCallback.run();
+            }
+            if (terminal instanceof AutoCloseable) {
+                try {
+                    ((AutoCloseable) terminal).close();
+                } catch (Exception e) {
+                    // Ignore
+                }
             }
         }
         if (session != null)

http://git-wip-us.apache.org/repos/asf/karaf/blob/0b6b68a6/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
index 03290e0..f1607bf 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
@@ -140,26 +140,27 @@ public class Main {
 
         try (org.jline.terminal.Terminal jlineTerminal = TerminalBuilder.terminal()) {
             final Terminal terminal = new JLineTerminal(jlineTerminal);
-            Session session = createSession(sessionFactory, command.length() > 0 ? null
: in, out, err, terminal);
-            session.put("USER", user);
-            session.put("APPLICATION", application);
-
-            discoverCommands(session, cl, getDiscoveryResource());
-
-            if (command.length() > 0) {
-                // Shell is directly executing a sub/command, we don't setup a console
-                // in this case, this avoids us reading from stdin un-necessarily.
-                session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
-                session.put(Session.PRINT_STACK_TRACES, "execution");
-                try {
-                    session.execute(command);
-                } catch (Throwable t) {
-                    ShellUtil.logException(session, t);
+            try (Session session = createSession(sessionFactory, command.length() > 0
? null : in, out, err, terminal)) {
+                session.put("USER", user);
+                session.put("APPLICATION", application);
+
+                discoverCommands(session, cl, getDiscoveryResource());
+
+                if (command.length() > 0) {
+                    // Shell is directly executing a sub/command, we don't setup a console
+                    // in this case, this avoids us reading from stdin un-necessarily.
+                    session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
+                    session.put(Session.PRINT_STACK_TRACES, "execution");
+                    try {
+                        session.execute(command);
+                    } catch (Throwable t) {
+                        ShellUtil.logException(session, t);
+                    }
+
+                } else {
+                    // We are going into full blown interactive shell mode.
+                    session.run();
                 }
-
-            } else {
-                // We are going into full blown interactive shell mode.
-                session.run();
             }
         }
     }


Mime
View raw message