From 2326c7e2cb644844ec358cfe9ff32d486d570dc1 Mon Sep 17 00:00:00 2001 From: Ryan Michela Date: Sat, 28 Dec 2013 22:47:19 -0800 Subject: [PATCH] get bukkit 1.7.2 to compile --- pom.xml | 9 +--- .../ryanmichela/sshd/ConsoleLogFormatter.java | 42 +++++++++++++++++++ .../ryanmichela/sshd/ConsoleShellFactory.java | 7 +--- .../sshd/PublicKeyAuthenticator.java | 2 +- 4 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java diff --git a/pom.xml b/pom.xml index a278ab3..5476a39 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.ryanmichela SSHD - 1.0 + 1.1 http://dev.bukkit.org/server-mods/sshd/ @@ -30,7 +30,7 @@ org.bukkit craftbukkit - 1.6.4-R1.0 + 1.7.2-R0.1-SNAPSHOT provided jar @@ -41,11 +41,6 @@ compile jar - - - - - diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java b/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java new file mode 100644 index 0000000..58ad16d --- /dev/null +++ b/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java @@ -0,0 +1,42 @@ +package com.ryanmichela.sshd; + +/** + * Copyright 2013 Ryan Michela + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +public class ConsoleLogFormatter extends Formatter { + + private SimpleDateFormat dateFormat; + + public ConsoleLogFormatter() { + this.dateFormat = new SimpleDateFormat("HH:mm:ss"); + } + + public String format(LogRecord logrecord) { + StringBuilder stringbuilder = new StringBuilder(); + + stringbuilder.append(" ["); + stringbuilder.append(this.dateFormat.format(Long.valueOf(logrecord.getMillis()))).append(" "); + + stringbuilder.append(logrecord.getLevel().getName()).append("]: "); + stringbuilder.append(this.formatMessage(logrecord)); + stringbuilder.append('\n'); + Throwable throwable = logrecord.getThrown(); + + if (throwable != null) { + StringWriter stringwriter = new StringWriter(); + + throwable.printStackTrace(new PrintWriter(stringwriter)); + stringbuilder.append(stringwriter.toString()); + } + + return stringbuilder.toString(); + } +} + diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java index 7987c63..706955e 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java @@ -10,7 +10,6 @@ import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.logging.Formatter; import java.util.logging.Logger; import java.util.logging.StreamHandler; @@ -66,19 +65,17 @@ public class ConsoleShellFactory implements Factory { public void start(Environment env) throws IOException { - Formatter bukkitFormatter = Bukkit.getLogger().getHandlers()[0].getFormatter(); - try { consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal()); consoleReader.setExpandEvents(true); consoleReader.addCompleter(new ConsoleCommandCompleter()); - streamHandler = new FlushyStreamHandler(out, bukkitFormatter, consoleReader); + streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader); Bukkit.getLogger().addHandler(streamHandler); Logger.getLogger("").addHandler(streamHandler); environment = env; - thread = new Thread(this, "EchoShell " + env.getEnv().get(Environment.ENV_USER)); + thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER)); thread.start(); } catch (Exception e) { throw new IOException("Error starting shell", e); diff --git a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java index d8eb328..ea61a74 100644 --- a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java +++ b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java @@ -1,6 +1,6 @@ package com.ryanmichela.sshd; -import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang.ArrayUtils; import org.apache.sshd.server.PublickeyAuthenticator; import org.apache.sshd.server.session.ServerSession;