From 080f8df7e273ae95605a2a93be5346a068267f43 Mon Sep 17 00:00:00 2001 From: Bulat Khasanov Date: Tue, 17 Jan 2017 09:22:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20he?= =?UTF-8?q?lp=20=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 2 ++ pom.xml | 15 ++++++++++++++- src/main/java/ru/khasanov/Main.java | 5 +++++ src/main/java/ru/khasanov/Server.java | 3 ++- src/main/java/ru/khasanov/http/Response.java | 2 +- src/main/java/ru/khasanov/settings/Settings.java | 8 ++++++-- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..804fffb --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +mvn clean compile assembly:single diff --git a/pom.xml b/pom.xml index bdfdbaf..52ac1f3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ ru.khasanov flash jar - 1.0-SNAPSHOT + 0.1.0 @@ -15,6 +15,19 @@ 1.7 + + maven-assembly-plugin + + + + ru.khasanov.Main + + + + jar-with-dependencies + + + flash diff --git a/src/main/java/ru/khasanov/Main.java b/src/main/java/ru/khasanov/Main.java index b20519c..80a407d 100644 --- a/src/main/java/ru/khasanov/Main.java +++ b/src/main/java/ru/khasanov/Main.java @@ -24,8 +24,13 @@ private static void disableLogging() { public static void main(String[] args) { Settings settings = new Settings(); JCommander jCommander = new JCommander(settings); + jCommander.setProgramName(Server.NAME); try { jCommander.parse(args); + if (settings.isHelp()) { + jCommander.usage(); + return; + } if (!settings.isLoggingEnable()) { disableLogging(); } diff --git a/src/main/java/ru/khasanov/Server.java b/src/main/java/ru/khasanov/Server.java index 53e2833..e44eb89 100644 --- a/src/main/java/ru/khasanov/Server.java +++ b/src/main/java/ru/khasanov/Server.java @@ -21,6 +21,7 @@ * Created by bulat on 06.01.17. */ public class Server { + public static final String NAME = "Flash"; public static final String VERSION = "0.1.0"; private static final Integer MIN_WORKER_COUNT = 2; private static final Logger logger = LoggerFactory.getLogger(Server.class); @@ -88,7 +89,7 @@ public ServerSocketChannel initServerSocketChannel() throws IOException { serverSocketChannel.configureBlocking(false); SocketAddress socketAddress = new InetSocketAddress("localhost", settings.getPort()); serverSocketChannel.socket().bind(socketAddress); - System.out.println(String.format("Started Flash %s server at %s", VERSION, socketAddress)); + System.out.println(String.format("Started %s %s server at %s", NAME, VERSION, socketAddress)); return serverSocketChannel; } diff --git a/src/main/java/ru/khasanov/http/Response.java b/src/main/java/ru/khasanov/http/Response.java index 5426d39..ed1fe04 100644 --- a/src/main/java/ru/khasanov/http/Response.java +++ b/src/main/java/ru/khasanov/http/Response.java @@ -28,7 +28,7 @@ public void setDefaultHeaders() { } public void setServerHeader() { - headers.put(ResponseHeader.SERVER, "Flash/" + Server.VERSION); + headers.put(ResponseHeader.SERVER, String.format("%s/%s", Server.NAME, Server.VERSION)); } public StatusCode getStatusCode() { diff --git a/src/main/java/ru/khasanov/settings/Settings.java b/src/main/java/ru/khasanov/settings/Settings.java index 02ca02b..851f7b6 100644 --- a/src/main/java/ru/khasanov/settings/Settings.java +++ b/src/main/java/ru/khasanov/settings/Settings.java @@ -8,6 +8,8 @@ * Created by bulat on 06.01.17. */ public class Settings { + @Parameter(names = {"-h", "--help"}, help = true, description = "Display help information") + private boolean help = false; @Parameter(names = {"-c", "--cache"}, arity = 1, description = "Enable cache using") private boolean cacheEnable = true; @Parameter(names = {"-r", "--root-directory"}, description = "Set root directory path", @@ -15,9 +17,11 @@ public class Settings { private String rootDirectory = "root_dir"; @Parameter(names = {"-p", "--port"}, description = "Set port", validateWith = PortValidator.class) private int port = 8080; - @Parameter(names = {"-l", "--loggingEnable"}, arity = 1, description = "Enable logging") + @Parameter(names = {"-l", "--logging-enable"}, arity = 1, description = "Enable logging") private boolean loggingEnable = true; - + public boolean isHelp() { + return help; + } public boolean isCacheEnable() { return cacheEnable; }