From 2d4ac0340bbae9e5bddc470a5941b43e2721bc79 Mon Sep 17 00:00:00 2001 From: DUHIEU Benjamin Date: Sat, 30 Nov 2019 16:14:28 +0100 Subject: [PATCH] feat: Create main. Build Jar --- build.gradle | 8 +++++++- src/main/java/Bot.java | 5 +++-- src/main/java/ChatRoom.java | 4 +--- src/main/java/Main.java | 5 ++++- src/main/java/User.java | 11 ----------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 68e7996..c8ca6a3 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,14 @@ jacocoTestReport { } } +jar { + manifest { + attributes 'Main-Class': 'Main' + } +} + group 'org.example' -version '1.0-SNAPSHOT' +version '1.0' mainClassName = 'Main' diff --git a/src/main/java/Bot.java b/src/main/java/Bot.java index b2a6ba0..06df415 100644 --- a/src/main/java/Bot.java +++ b/src/main/java/Bot.java @@ -43,8 +43,9 @@ private boolean parseMessage(String message) { if (message.equals("@hello")) { this.botName = "hello"; this.formatResponse(); - return true; + System.out.println(getResponse()); + return false; } - return false; + return message.equals("++"); } } diff --git a/src/main/java/ChatRoom.java b/src/main/java/ChatRoom.java index 5119592..2244ba8 100644 --- a/src/main/java/ChatRoom.java +++ b/src/main/java/ChatRoom.java @@ -22,15 +22,13 @@ public void initialize() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (logic(reader)); + reader.close(); } private boolean logic(BufferedReader reader) throws IOException { user.displayUserName(); String command = reader.readLine(); - user.getUserMessage(command); if (bot.receiveMessage(command)) { - System.out.println(bot.getResponse()); - user.sayByeToBot(); return false; } return true; diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 348bc8c..378b3c9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,8 +4,11 @@ public class Main { public static void main(String[] args) throws IOException { // TODO: Parse string + Parser parser = new Parser(args); + if (!parser.parse()) + return ; ChatRoom chatRoom = new ChatRoom(); - chatRoom.setUserName("Toto"); + chatRoom.setUserName(parser.getArgumentsAtIndex(0)); chatRoom.initialize(); } } diff --git a/src/main/java/User.java b/src/main/java/User.java index cdf2839..7db89f7 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -14,18 +14,7 @@ public String getUserName() { return this.username; } - public void getUserMessage(String msg) { - System.out.println(msg); - } - public void displayUserName() { System.out.print("[" + this.username + "] "); } - - public void sayByeToBot() { - displayUserName(); - System.out.println(SAY_FOO); - displayUserName(); - System.out.println(EXIT); - } }