You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2008/04/25 12:14:26 UTC
svn commit: r651561 - in
/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell:
DefaultShell.java console/FileHistory.java console/JLineConsole.java
Author: gnodet
Date: Fri Apr 25 03:14:26 2008
New Revision: 651561
URL: http://svn.apache.org/viewvc?rev=651561&view=rev
Log:
Externalize the history object so that it can be reused for an history command
Added:
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/FileHistory.java
Modified:
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java
Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java?rev=651561&r1=651560&r2=651561&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java (original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java Fri Apr 25 03:14:26 2008
@@ -32,6 +32,7 @@
import org.apache.geronimo.gshell.command.IO;
import org.apache.geronimo.gshell.console.Console;
import org.apache.geronimo.gshell.console.Console.ErrorHandler;
+import org.apache.geronimo.gshell.console.FileHistory;
import org.apache.geronimo.gshell.console.JLineConsole;
import org.apache.geronimo.gshell.console.TerminalInfo;
import org.apache.geronimo.gshell.console.Console.Prompter;
@@ -79,19 +80,23 @@
@Requirement
private IO io;
+ @Requirement
+ private History history;
+
private Prompter prompter;
private ErrorHandler errorHandler;
public DefaultShell() {}
- public DefaultShell(final ShellInfo shellInfo, final Branding branding, final CommandExecutor executor, final Terminal terminal, final Environment env, final IO io) {
+ public DefaultShell(final ShellInfo shellInfo, final Branding branding, final CommandExecutor executor, final Terminal terminal, final Environment env, final IO io, final History history) {
this.shellInfo = shellInfo;
this.branding = branding;
this.executor = executor;
this.terminal = terminal;
this.env = env;
this.io = io;
+ this.history = history;
}
public Environment getEnvironment() {
@@ -183,9 +188,10 @@
console.setErrorHandler(getErrorHandler());
// Hook up a nice history file (we gotta hold on to the history object at some point so the 'history' command can get to it)
- History history = new History();
+ if (history == null) {
+ history = new FileHistory(branding);
+ }
console.setHistory(history);
- console.setHistoryFile(new File(branding.getUserDirectory(), branding.getHistoryFileName()));
// Unless the user wants us to shut up, then display a nice welcome banner
if (!io.isQuiet()) {
Added: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/FileHistory.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/FileHistory.java?rev=651561&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/FileHistory.java (added)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/FileHistory.java Fri Apr 25 03:14:26 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.console;
+
+import java.io.File;
+import java.io.IOException;
+import jline.History;
+import org.apache.geronimo.gshell.branding.Branding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+
+@Component(role=History.class, hint="default")
+public class FileHistory extends History {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Requirement
+ private Branding branding;
+
+ public FileHistory() {
+ }
+
+ public FileHistory(final Branding branding) throws IOException {
+ this.branding = branding;
+ initialize();
+ }
+
+ public void initialize() throws IOException {
+ setHistoryFile(new File(branding.getUserDirectory(), branding.getHistoryFileName()));
+ }
+
+ public void setHistoryFile(final File file) throws IOException {
+ assert file != null;
+ File dir = file.getParentFile();
+ if (!dir.exists()) {
+ dir.mkdirs();
+ log.debug("Created base directory for history file: {}", dir);
+ }
+ log.debug("Using history file: {}", file);
+ super.setHistoryFile(file);
+ }
+
+}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java?rev=651561&r1=651560&r2=651561&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java (original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java Fri Apr 25 03:14:26 2008
@@ -72,22 +72,6 @@
reader.setHistory(history);
}
- public void setHistoryFile(final File file) throws IOException {
- assert file != null;
-
- File dir = file.getParentFile();
-
- if (!dir.exists()) {
- dir.mkdirs();
-
- log.debug("Created base directory for history file: {}", dir);
- }
-
- log.debug("Using history file: {}", file);
-
- reader.getHistory().setHistoryFile(file);
- }
-
protected String readLine(final String prompt) throws IOException {
return reader.readLine(prompt);
}