5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-06 02:29:49 +08:00

SQOOP-2764: Sqoop2: Sqoop shell history is no longer working

(Dian Fu via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-12-31 06:09:12 -08:00
parent 8d63df7145
commit 008b126932

View File

@ -22,6 +22,9 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import jline.console.history.History;
import jline.console.history.PersistentHistory;
import org.apache.sqoop.shell.core.Constants; import org.apache.sqoop.shell.core.Constants;
import org.apache.sqoop.shell.utils.ThrowableDisplayer; import org.apache.sqoop.shell.utils.ThrowableDisplayer;
import org.codehaus.groovy.runtime.MethodClosure; import org.codehaus.groovy.runtime.MethodClosure;
@ -56,8 +59,8 @@ public final class SqoopShell {
static { static {
commandsToKeep = new HashSet<String>(); commandsToKeep = new HashSet<String>();
commandsToKeep.add("exit"); commandsToKeep.add(":exit");
commandsToKeep.add("history"); commandsToKeep.add(":history");
} }
/** /**
@ -68,11 +71,26 @@ public final class SqoopShell {
*/ */
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT); System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
Groovysh shell = new Groovysh(); final Groovysh shell = new Groovysh();
// Install our error hook (exception handling) // Install our error hook (exception handling)
shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook")); shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));
// Install shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
History history = shell.getRunner().getReader().getHistory();
if (history instanceof PersistentHistory) {
try {
((PersistentHistory)history).flush();
} catch (IOException e) {
// Ignore this exception as it only affects history
}
}
}
});
CommandRegistry registry = shell.getRegistry(); CommandRegistry registry = shell.getRegistry();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<Command> iterator = registry.iterator(); Iterator<Command> iterator = registry.iterator();