felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r821877 - in /felix/trunk/karaf: shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/
Date Mon, 05 Oct 2009 15:49:34 GMT
Author: gnodet
Date: Mon Oct  5 15:49:34 2009
New Revision: 821877

URL: http://svn.apache.org/viewvc?rev=821877&view=rev
Log:
FELIX-1694: [karaf][shell] Do not print stack traces on exceptions, patch provided by Alin
Dreghiciu

Modified:
    felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
    felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ConsoleFactory.java
    felix/trunk/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
    felix/trunk/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java

Modified: felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java?rev=821877&r1=821876&r2=821877&view=diff
==============================================================================
--- felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
(original)
+++ felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
Mon Oct  5 15:49:34 2009
@@ -24,6 +24,7 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.util.Properties;
+import java.util.concurrent.Callable;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 import java.util.concurrent.ArrayBlockingQueue;
@@ -32,7 +33,6 @@
 import jline.ConsoleReader;
 import jline.Terminal;
 import jline.UnsupportedTerminal;
-import jline.WindowsTerminal;
 import jline.AnsiWindowsTerminal;
 import org.apache.felix.karaf.shell.console.Completer;
 import org.osgi.service.command.CommandProcessor;
@@ -44,6 +44,7 @@
 
     public static final String PROMPT = "PROMPT";
     public static final String DEFAULT_PROMPT = "\u001B[1m${USER}\u001B[0m@${APPLICATION}>
";
+    public static final String PRINT_STACK_TRACES = "karaf.printStackTraces";
 
     private CommandSession session;
     private ConsoleReader reader;
@@ -57,6 +58,7 @@
     private InputStream in;
     private PrintStream out;
     private PrintStream err;
+    private Callable<Boolean> printStackTraces;
 
     public Console(CommandProcessor processor,
                    InputStream in,
@@ -64,7 +66,8 @@
                    PrintStream err,
                    Terminal term,
                    Completer completer,
-                   Runnable closeCallback) throws Exception
+                   Runnable closeCallback,
+                   Callable<Boolean> printStackTraces ) throws Exception
     {
         this.in = in;
         this.out = out;
@@ -75,6 +78,7 @@
         this.session = processor.createSession(this.consoleInput, this.out, this.err);
         this.session.put("SCOPE", "shell:osgi:*");
         this.closeCallback = closeCallback;
+        this.printStackTraces = printStackTraces;
 
         reader = new ConsoleReader(this.consoleInput,
                                    new PrintWriter(this.out),
@@ -125,8 +129,16 @@
             }
             catch (Throwable t)
             {
-                t.printStackTrace(session.getConsole());
-                //System.err.println("Exception: " + t.getMessage());
+                try {
+                    if ( printStackTraces.call()) {
+                        t.printStackTrace(session.getConsole());
+                    }
+                    else {
+                        session.getConsole().println(t.getMessage());
+                    }
+                } catch (Exception ignore) {
+                        // ignore
+                }
             }
         }
         //System.err.println("Exiting console...");

Modified: felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ConsoleFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ConsoleFactory.java?rev=821877&r1=821876&r2=821877&view=diff
==============================================================================
--- felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ConsoleFactory.java
(original)
+++ felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/ConsoleFactory.java
Mon Oct  5 15:49:34 2009
@@ -23,6 +23,7 @@
 import java.io.OutputStream;
 import java.lang.reflect.Method;
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import org.apache.felix.karaf.shell.console.Completer;
 import org.apache.felix.karaf.shell.console.completer.AggregateCompleter;
@@ -81,13 +82,19 @@
                     }
                 }
             };
+            final Callable<Boolean> printStackTraces = new Callable<Boolean>()
{
+                public Boolean call() {
+                    return Boolean.valueOf(bundleContext.getProperty(Console.PRINT_STACK_TRACES));
+                }
+            };
             this.console = new Console(commandProcessor,
                                        in,
                                        wrap(out),
                                        wrap(err),
                                        terminal,
                                        new AggregateCompleter(completers),
-                                       callback);
+                                       callback,
+                                       printStackTraces);
             CommandSession session = console.getSession();
             session.put("USER", "karaf");
             session.put("APPLICATION", System.getProperty("karaf.name", "root"));

Modified: felix/trunk/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java?rev=821877&r1=821876&r2=821877&view=diff
==============================================================================
--- felix/trunk/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
(original)
+++ felix/trunk/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
Mon Oct  5 15:49:34 2009
@@ -26,6 +26,7 @@
 import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.felix.karaf.shell.console.Completer;
 import org.apache.felix.karaf.shell.console.completer.AggregateCompleter;
@@ -86,6 +87,11 @@
 
         public void start(final Environment env) throws IOException {
             try {
+                final Callable<Boolean> printStackTraces = new Callable<Boolean>()
{
+                    public Boolean call() {
+                        return Boolean.valueOf(System.getProperty(Console.PRINT_STACK_TRACES));
+                    }
+                };
                 Console console = new Console(commandProcessor,
                                               in,
                                               new PrintStream(out),
@@ -96,7 +102,8 @@
                                                   public void run() {
                                                       destroy();
                                                   }
-                                              });
+                                              },
+                                              printStackTraces);
                 CommandSession session = console.getSession();
                 session.put("APPLICATION", System.getProperty("karaf.name", "root"));
                 for (Map.Entry<String,String> e : env.getEnv().entrySet()) {

Modified: felix/trunk/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java?rev=821877&r1=821876&r2=821877&view=diff
==============================================================================
--- felix/trunk/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
(original)
+++ felix/trunk/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
Mon Oct  5 15:49:34 2009
@@ -31,6 +31,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.PrintStream;
 import java.io.InputStream;
+import java.util.concurrent.Callable;
 import java.util.zip.GZIPOutputStream;
 import java.util.List;
 import java.net.URL;
@@ -198,13 +199,20 @@
                 out = new PipedInputStream();
                 PrintStream pipedOut = new PrintStream(new PipedOutputStream(out), true);
 
+                final Callable<Boolean> printStackTraces = new Callable<Boolean>()
{
+                    public Boolean call() {
+                        return Boolean.valueOf(bundleContext.getProperty(Console.PRINT_STACK_TRACES));
+                    }
+                };
+
                 console = new Console(commandProcessor,
                                       new PipedInputStream(in),
                                       pipedOut,
                                       pipedOut,
                                       new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
                                       new AggregateCompleter(completers),
-                                      null);
+                                      null,
+                                      printStackTraces);
                 CommandSession session = console.getSession();
                 session.put("APPLICATION", System.getProperty("karaf.name", "root"));
                 session.put("USER", "karaf");



Mime
View raw message