Skip to content

Commit

Permalink
Add Launcher Class to make .jar file runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
iyioon committed Sep 20, 2023
1 parent f1c56cd commit 03c8dc2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 11 deletions.
3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: duke.Duke

7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ test {
}

application {
mainClass.set("duke.Duke")
mainClass.set("Launcher")
}

shadowJar {
archiveFileName = "duke.jar"
archiveBaseName = "duke"
archiveClassifier = null
dependsOn("distZip", "distTar")
archiveFileName = "ken.jar"
}

run{
Expand Down
6 changes: 6 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
T|false|test
T|false|a
T|false|a
T|false|a
T|false|a
T|false|test
T|false|1
11 changes: 11 additions & 0 deletions src/main/java/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import duke.Duke;
import javafx.application.Application;

/**
* Launcher for stating the program with gui.
*/
public class Launcher {
public static void main(String[] args) {
Application.launch(Duke.class, args);
}
}
4 changes: 0 additions & 4 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class Duke extends Application {
private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));

public static void main(String[] args) {
Application.launch(Duke.class, args);
}

/**
* Start the program with GUI.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Parser {
* @return The corresponding duke.command.Command object.
*/
public static Command parse(String userInput) throws DukeException {
String[] words = userInput.toLowerCase().split("\\s+");
String[] words = userInput.trim().toLowerCase().split("\\s+");
switch (words[0]) {
case "bye":
return new ExitCommand();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AddCommand implements Command {
*/
@Override
public boolean execute(TaskList tasks, Ui ui) throws DukeException {
String userInput = ui.getLastMsg();
String userInput = ui.getLastMsg().trim();

// Determine the task type based on the message.
if (userInput.toLowerCase().startsWith("todo")) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Launcher

14 changes: 14 additions & 0 deletions src/test/java/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ public void parse_unknownCommand_exceptionThrown() {
assertEquals(true, true);
}
}

@Test
public void parse_handleMultipleSpaces() {
String[] testInputs = {" bye", " bye ", " bye"};
String lastInput = testInputs[0];
try {
for (String command : testInputs) {
lastInput = command;
Parser.parse(command);
}
} catch (DukeException e) {
fail(lastInput + " command failed to parse");
}
}
}

0 comments on commit 03c8dc2

Please sign in to comment.