X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fmain%2FMain.java;h=c9b7c5b9584564be58359e72f8d7601250553204;hb=8593a0995d655bebada567ab98a9de2cdf078243;hp=0033247ff53fc553acc14e778eff71c13d3fdfc0;hpb=1668dc75b65956d82ddfeb50a09ef04991996511;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/main/Main.java b/src/main/java/net/pterodactylus/xdcc/main/Main.java index 0033247..c9b7c5b 100644 --- a/src/main/java/net/pterodactylus/xdcc/main/Main.java +++ b/src/main/java/net/pterodactylus/xdcc/main/Main.java @@ -17,20 +17,16 @@ package net.pterodactylus.xdcc.main; +import static com.lexicalscope.jewel.cli.CliFactory.parseArguments; + import java.io.File; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.util.Collection; import java.util.HashSet; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.Executors; -import java.util.logging.ConsoleHandler; -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.ConnectionFactory; +import net.pterodactylus.irc.DefaultConnectionFactory; import net.pterodactylus.xdcc.core.Core; import net.pterodactylus.xdcc.data.Channel; import net.pterodactylus.xdcc.data.Download; @@ -42,6 +38,7 @@ import net.pterodactylus.xdcc.ui.stdin.NetworkAdapter; import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; +import com.lexicalscope.jewel.cli.Option; import org.codehaus.jackson.map.ObjectMapper; /** @@ -59,25 +56,13 @@ public class Main { public static void main(String... arguments) throws Exception { - ConsoleHandler consoleHandler = new ConsoleHandler(); - consoleHandler.setFormatter(new Formatter() { - - @Override - public String format(LogRecord logRecord) { - return String.format("%1$tF %1$tT %2$s %3$s\n", logRecord.getMillis(), logRecord.getLoggerName(), logRecord.getMessage()); - } - }); - consoleHandler.setLevel(Level.ALL); - Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]); - Logger.getLogger("").addHandler(consoleHandler); - Logger.getLogger("").setLevel(Level.ALL); - Logger.getLogger(Connection.class.getName()).setLevel(Level.INFO); - Logger.getLogger(Core.class.getName()).setLevel(Level.INFO); + Parameters parameters = parseArguments(Parameters.class, arguments); EventBus eventBus = new AsyncEventBus(Executors.newSingleThreadExecutor()); - Configuration configuration = new ObjectMapper().readValue(new File("configuration.json"), Configuration.class); + Configuration configuration = new ObjectMapper().readValue(new File(parameters.getConfiguration()), Configuration.class); + ConnectionFactory connectionFactory = new DefaultConnectionFactory(eventBus); - Core core = new Core(eventBus, configuration.getTemporaryDirectory(), configuration.getFinalDirectory()); + Core core = new Core(eventBus, connectionFactory, configuration.getTemporaryDirectory(), configuration.getFinalDirectory()); eventBus.register(core); for (Configuration.Network network : configuration.getNetworks()) { @@ -101,14 +86,22 @@ public class Main { Collection failedDownloads = new CopyOnWriteArraySet<>(); - CommandReader commandReader = new CommandReader(core, new InputStreamReader(System.in, "UTF-8"), new OutputStreamWriter(System.out, "UTF-8"), failedDownloads); - commandReader.start(); - eventBus.register(commandReader); - NetworkAdapter networkAcceptor = new NetworkAdapter(eventBus, (reader, writer) -> new CommandReader(core, reader, writer, failedDownloads), configuration.getTelnetPort()); networkAcceptor.start(); core.start(); } + /** + * Defines the command-line parameters. + * + * @author David ‘Bombe’ Roden + */ + private interface Parameters { + + @Option(longName = "configuration", description = "The configuration file", defaultValue = "configuration.json") + String getConfiguration(); + + } + }