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

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

commit 851c5825ab772064b319a60689c93a11138688b7
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 9 18:01:56 2017 +0100

    [KARAF-5475] Send an event to EventAdmin after having executed a command in 
the shell and include the result / exception
---
 .../impl/console/osgi/EventAdminListener.java      | 25 ++++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git 
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
 
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
index b7b805e..ec249a2 100644
--- 
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
+++ 
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
@@ -45,21 +45,32 @@ public class EventAdminListener implements 
CommandSessionListener, Closeable
     }
 
     public void beforeExecute(CommandSession session, CharSequence command) {
+    }
+
+    public void afterExecute(CommandSession session, CharSequence command, 
Exception exception) {
+        sendEvent(command, null, exception);
+    }
+
+    public void afterExecute(CommandSession session, CharSequence command, 
Object result) {
+        sendEvent(command, result, null);
+    }
+
+    private void sendEvent(CharSequence command, Object result, Exception 
exception) {
         if (command.toString().trim().length() > 0) {
             EventAdmin admin = tracker.getService();
             if (admin != null) {
                 Map<String, Object> props = new HashMap<>();
                 props.put("command", command.toString());
-                Event event = new 
Event("org/apache/karaf/shell/console/EXECUTING", props);
+                if (result != null) {
+                    props.put("result", result);
+                }
+                if (exception != null) {
+                    props.put("exception", exception);
+                }
+                Event event = new 
Event("org/apache/karaf/shell/console/EXECUTED", props);
                 admin.postEvent(event);
             }
         }
     }
 
-    public void afterExecute(CommandSession session, CharSequence command, 
Exception exception) {
-    }
-
-    public void afterExecute(CommandSession session, CharSequence command, 
Object result) {
-    }
-
 }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to