You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2011/07/05 14:51:53 UTC

svn commit: r1143032 - in /karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline: Console.java KarafFileHistory.java

Author: cschneider
Date: Tue Jul  5 12:51:53 2011
New Revision: 1143032

URL: http://svn.apache.org/viewvc?rev=1143032&view=rev
Log:
KARAF-281 Fixed

Added:
    karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java   (with props)
Modified:
    karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java

Modified: karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1143032&r1=1143031&r2=1143032&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java (original)
+++ karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java Tue Jul  5 12:51:53 2011
@@ -103,39 +103,13 @@ public class Console implements Runnable
                                    this.terminal);
 
         final File file = getHistoryFile();
-        file.getParentFile().mkdirs();
-
-        // We may not have the perms to read the history file...
-        if( file.exists() && file.canRead() ) {
-            // Override the FileHistory impl to trap failures due to the
-            // user does not having write access to the history file.
-            reader.setHistory(new FileHistory(file) {
-                boolean failed = false;
-                @Override
-                public void flush() throws IOException {
-                    if( !failed ) {
-                        try {
-                            super.flush();
-                        } catch (IOException e) {
-                            failed = true;
-                            LOGGER.debug("Cold not write history file: "+file, e);
-                        }
-                    }
-                }
+        try {
+            file.getParentFile().mkdirs();
+        	reader.setHistory(new KarafFileHistory(file));
+		} catch (Exception e) {
+			LOGGER.error("Can not read history from file " + file + ". Using in memory history", e);
+		}
 
-                @Override
-                public void purge() throws IOException {
-                    if( !failed ) {
-                        try {
-                            super.purge();
-                        } catch (IOException e) {
-                            failed = true;
-                            LOGGER.debug("Cold not delete history file: "+file, e);
-                        }
-                    }
-                }
-            });
-        }
         session.put(".jline.history", reader.getHistory());
         Completer completer = createCompleter();
         if (completer != null) {

Added: karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java?rev=1143032&view=auto
==============================================================================
--- karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java (added)
+++ karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java Tue Jul  5 12:51:53 2011
@@ -0,0 +1,46 @@
+package org.apache.karaf.shell.console.jline;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jline.console.history.FileHistory;
+
+/**
+ * Override the FileHistory impl to trap failures due to the
+ * user does not having write access to the history file.
+ */
+public final class KarafFileHistory extends FileHistory {
+	static final Logger LOGGER = LoggerFactory.getLogger(KarafFileHistory.class);
+	boolean failed = false;
+
+	public KarafFileHistory(File file) throws IOException {
+		super(file);
+	}
+
+	@Override
+	public void flush() throws IOException {
+	    if( !failed ) {
+	        try {
+	            super.flush();
+	        } catch (IOException e) {
+	            failed = true;
+	            LOGGER.debug("Could not write history file: "+ getFile(), e);
+	        }
+	    }
+	}
+
+	@Override
+	public void purge() throws IOException {
+	    if( !failed ) {
+	        try {
+	            super.purge();
+	        } catch (IOException e) {
+	            failed = true;
+	            LOGGER.debug("Could not delete history file: "+ getFile(), e);
+	        }
+	    }
+	}
+}
\ No newline at end of file

Propchange: karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/KarafFileHistory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain