karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject karaf git commit: Refactor read and execute out of run
Date Tue, 01 Aug 2017 11:37:01 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 5d6cd21b0 -> ff6d8a08d


Refactor read and execute out of run


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

Branch: refs/heads/master
Commit: ff6d8a08d5311e2fb9d91ba6a5f76a07ffae41d3
Parents: 5d6cd21
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Aug 1 13:36:36 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Aug 1 13:36:50 2017 +0200

----------------------------------------------------------------------
 .../shell/impl/console/ConsoleSessionImpl.java  | 58 +++++++++++---------
 1 file changed, 32 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ff6d8a08/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 05ab109..3efac34 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
@@ -341,33 +341,11 @@ public class ConsoleSessionImpl implements Session {
             String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
             executeScript(scriptFileName);
             while (running) {
-                String command = null;
-                reading.set(true);
-                try {
-                    command = reader.readLine(getPrompt(), getRPrompt(), null, null);
-                } catch (EndOfFileException e) {
-                    break;
-                } catch (UserInterruptException e) {
-                    // Ignore, loop again
-                    continue;
-                } catch (Throwable t) {
-                    ShellUtil.logException(this, t);
-                } finally {
-                    reading.set(false);
-                }
+                String command = readCommand(reading);
                 if (command == null) {
                     break;
                 }
-                try {
-                    Object result = session.execute(command);
-                    if (result != null) {
-                        session.getConsole().println(session.format(result, Converter.INSPECT));
-                    }
-                } catch (InterruptedException e) {
-                    LOGGER.debug("Console session is closed");
-                } catch (Throwable t) {
-                    ShellUtil.logException(this, t);
-                }
+                execute(command);
             }
             close();
         } finally {
@@ -400,6 +378,36 @@ public class ConsoleSessionImpl implements Session {
         return isLocal != null && isLocal;
     }
 
+    private String readCommand(AtomicBoolean reading) throws UserInterruptException {
+        String command = null;
+        reading.set(true);
+        try {
+            command = reader.readLine(getPrompt(), getRPrompt(), null, null);
+        } catch (EndOfFileException e) {
+            command = null;
+        } catch (UserInterruptException e) {
+            command = ""; // Do nothing
+        } catch (Throwable t) {
+            ShellUtil.logException(this, t);
+        } finally {
+            reading.set(false);
+        }
+        return command;
+    }
+
+    private void execute(String command) {
+        try {
+            Object result = session.execute(command);
+            if (result != null) {
+                session.getConsole().println(session.format(result, Converter.INSPECT));
+            }
+        } catch (InterruptedException e) {
+            LOGGER.debug("Console session is closed");
+        } catch (Throwable t) {
+            ShellUtil.logException(this, t);
+        }
+    }
+
     private String getStatusLine(Job job, int width, String status) {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < width - 1; i++) {
@@ -501,8 +509,6 @@ public class ConsoleSessionImpl implements Session {
         }
     }
 
-
-
     protected void welcome(Properties brandingProps) {
         String welcome = brandingProps.getProperty("welcome");
         if (welcome != null && welcome.length() > 0) {


Mime
View raw message