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-3455] Improve custom parser so that they can preprocess the command line which will be executed by gogo
Date Thu, 19 Feb 2015 13:33:14 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 22f73d75d -> 95fd0809a


[KARAF-3455] Improve custom parser so that they can preprocess the command line which will
be executed by gogo

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

Branch: refs/heads/master
Commit: 95fd0809a5c37616f41e443067046e946d5a4b53
Parents: 22f73d7
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Thu Feb 19 14:32:59 2015 +0100
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Thu Feb 19 14:32:59 2015 +0100

----------------------------------------------------------------------
 .../apache/karaf/jdbc/command/parsing/JdbcParser.java  | 12 ++++++++++++
 .../org/apache/karaf/shell/api/console/Parser.java     |  2 ++
 .../karaf/shell/impl/action/command/ActionCommand.java |  9 +++++++++
 .../karaf/shell/impl/console/ConsoleSessionImpl.java   |  3 ++-
 .../shell/impl/console/parsing/CommandLineParser.java  |  8 +-------
 .../karaf/shell/support/parsing/DefaultParser.java     | 13 +++++++++++++
 .../karaf/shell/impl/console/parsing/ParsingTest.java  | 13 +++++++++++++
 7 files changed, 52 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/jdbc/src/main/java/org/apache/karaf/jdbc/command/parsing/JdbcParser.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/karaf/jdbc/command/parsing/JdbcParser.java b/jdbc/src/main/java/org/apache/karaf/jdbc/command/parsing/JdbcParser.java
index 90238c3..3aeb972 100644
--- a/jdbc/src/main/java/org/apache/karaf/jdbc/command/parsing/JdbcParser.java
+++ b/jdbc/src/main/java/org/apache/karaf/jdbc/command/parsing/JdbcParser.java
@@ -72,4 +72,16 @@ public class JdbcParser implements Parser {
                 command.substring(0, parser.position()));
     }
 
+    @Override
+    public String preprocess(Session session, CommandLine cmdLine) {
+        StringBuilder parsed = new StringBuilder();
+        for (int i = 0 ; i < cmdLine.getArguments().length; i++) {
+            String arg = cmdLine.getArguments()[i];
+            if (i > 0) {
+                parsed.append(" ");
+            }
+            parsed.append(arg);
+        }
+        return parsed.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/shell/core/src/main/java/org/apache/karaf/shell/api/console/Parser.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Parser.java b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Parser.java
index c653c27..acc0e07 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Parser.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Parser.java
@@ -25,4 +25,6 @@ public interface Parser {
 
     CommandLine parse(Session session, String command, int cursor);
 
+    String preprocess(Session session, CommandLine commandLine);
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ActionCommand.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ActionCommand.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ActionCommand.java
index 9c33d34..ac4be9f 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ActionCommand.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ActionCommand.java
@@ -132,6 +132,15 @@ public class ActionCommand implements org.apache.karaf.shell.api.console.Command
             }
             throw new IllegalStateException("Could not find specified parser");
         }
+
+        @Override
+        public String preprocess(Session session, CommandLine commandLine) {
+            Object service = session.getRegistry().getService(clazz);
+            if (service instanceof Parser) {
+                return ((Parser) service).preprocess(session, commandLine);
+            }
+            throw new IllegalStateException("Could not find specified parser");
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/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 4ff0c96..c1465e6 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
@@ -289,7 +289,8 @@ public class ConsoleSessionImpl implements Session {
 
     @Override
     public Object execute(CharSequence commandline) throws Exception {
-        return session.execute(commandline);
+        String command = CommandLineParser.parse(this, commandline.toString());
+        return session.execute(command);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/shell/core/src/main/java/org/apache/karaf/shell/impl/console/parsing/CommandLineParser.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/parsing/CommandLineParser.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/parsing/CommandLineParser.java
index 5dbb6ff..a504c7c 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/parsing/CommandLineParser.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/parsing/CommandLineParser.java
@@ -84,13 +84,7 @@ public class CommandLineParser {
             }
 
             CommandLine cmdLine = cmdParser.parse(session, rem, rem.length());
-            for (int i = 0 ; i < cmdLine.getArguments().length; i++) {
-                String arg = cmdLine.getArguments()[i];
-                if (i > 0) {
-                    parsed.append(" ");
-                }
-                parsed.append(arg);
-            }
+            parsed.append(cmdParser.preprocess(session, cmdLine));
 
             int length = cmdLine.getBuffer().length();
             if (length < rem.length()) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/shell/core/src/main/java/org/apache/karaf/shell/support/parsing/DefaultParser.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/support/parsing/DefaultParser.java
b/shell/core/src/main/java/org/apache/karaf/shell/support/parsing/DefaultParser.java
index 7b01042..f5c4a07 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/support/parsing/DefaultParser.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/support/parsing/DefaultParser.java
@@ -40,4 +40,17 @@ public class DefaultParser implements Parser {
                         command.substring(0, parser.position()));
     }
 
+    @Override
+    public String preprocess(Session session, CommandLine cmdLine) {
+        StringBuilder parsed = new StringBuilder();
+        for (int i = 0 ; i < cmdLine.getArguments().length; i++) {
+            String arg = cmdLine.getArguments()[i];
+            if (i > 0) {
+                parsed.append(" ");
+            }
+            parsed.append(arg);
+        }
+        return parsed.toString();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/95fd0809/shell/core/src/test/java/org/apache/karaf/shell/impl/console/parsing/ParsingTest.java
----------------------------------------------------------------------
diff --git a/shell/core/src/test/java/org/apache/karaf/shell/impl/console/parsing/ParsingTest.java
b/shell/core/src/test/java/org/apache/karaf/shell/impl/console/parsing/ParsingTest.java
index ff605ee..440f96a 100644
--- a/shell/core/src/test/java/org/apache/karaf/shell/impl/console/parsing/ParsingTest.java
+++ b/shell/core/src/test/java/org/apache/karaf/shell/impl/console/parsing/ParsingTest.java
@@ -132,6 +132,19 @@ public class ParsingTest {
                             parser.position(),
                             command.substring(0, parser.position()));
         }
+
+        @Override
+        public String preprocess(Session session, CommandLine cmdLine) {
+            StringBuilder parsed = new StringBuilder();
+            for (int i = 0 ; i < cmdLine.getArguments().length; i++) {
+                String arg = cmdLine.getArguments()[i];
+                if (i > 0) {
+                    parsed.append(" ");
+                }
+                parsed.append(arg);
+            }
+            return parsed.toString();
+        }
     }
 
 }


Mime
View raw message