diff --git a/pom.xml b/pom.xml index dff1c8b..b074844 100644 --- a/pom.xml +++ b/pom.xml @@ -21,9 +21,10 @@ - junit - junit - 3.8.1 + org.junit.jupiter + junit-jupiter-api + 5.13.1 + test @@ -69,6 +70,16 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + diff --git a/src/main/java/de/vimo/Main.java b/src/main/java/de/vimo/Main.java new file mode 100644 index 0000000..62f41fe --- /dev/null +++ b/src/main/java/de/vimo/Main.java @@ -0,0 +1,22 @@ +package de.vimo; + +import de.vimo.core.Line; +import de.vimo.core.Parser; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Parser parser = null; + + while (true) { + String raw = scanner.nextLine(); + Line line = parser.parse(raw); + + if (line.getCommand() != null) { + // line.getCommand().exec(line.getFlags(), line.getArgs()); + } + } + } +} diff --git a/src/main/java/de/vimo/command/CdCommand.java b/src/main/java/de/vimo/command/CdCommand.java new file mode 100644 index 0000000..6fb12f1 --- /dev/null +++ b/src/main/java/de/vimo/command/CdCommand.java @@ -0,0 +1,26 @@ +package de.vimo.command; + +import de.vimo.core.Argument; +import de.vimo.core.Command; +import de.vimo.core.Flag; + +import java.util.List; + +public class CdCommand implements Command { + + @Override + public int exec(List flags, List args) { + return 0; + } + + @Override + public String getName() { + return null; + } + + @Override + public List getFlags() { + return null; + } +} + diff --git a/src/main/java/de/vimo/command/HelpCommand.java b/src/main/java/de/vimo/command/HelpCommand.java new file mode 100644 index 0000000..7eefe80 --- /dev/null +++ b/src/main/java/de/vimo/command/HelpCommand.java @@ -0,0 +1,25 @@ +package de.vimo.command; + +import de.vimo.core.Argument; +import de.vimo.core.Command; +import de.vimo.core.Flag; + +import java.util.List; + +public class HelpCommand implements Command { + + @Override + public int exec(List flags, List args) { + return 0; + } + + @Override + public String getName() { + return null; + } + + @Override + public List getFlags() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/de/vimo/command/LsCommand.java b/src/main/java/de/vimo/command/LsCommand.java new file mode 100644 index 0000000..bb04f87 --- /dev/null +++ b/src/main/java/de/vimo/command/LsCommand.java @@ -0,0 +1,25 @@ +package de.vimo.command; + +import de.vimo.core.Argument; +import de.vimo.core.Command; +import de.vimo.core.Flag; + +import java.util.List; + +public class LsCommand implements Command { + + @Override + public int exec(List flags, List args) { + return 0; + } + + @Override + public String getName() { + return null; + } + + @Override + public List getFlags() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/de/vimo/command/MkdirCommand.java b/src/main/java/de/vimo/command/MkdirCommand.java new file mode 100644 index 0000000..606a6a3 --- /dev/null +++ b/src/main/java/de/vimo/command/MkdirCommand.java @@ -0,0 +1,25 @@ +package de.vimo.command; + +import de.vimo.core.Argument; +import de.vimo.core.Command; +import de.vimo.core.Flag; + +import java.util.List; + +public class MkdirCommand implements Command { + + @Override + public int exec(List flags, List args) { + return 0; + } + + @Override + public String getName() { + return null; + } + + @Override + public List getFlags() { + return null; + } +} diff --git a/src/main/java/de/vimo/core/Argument.java b/src/main/java/de/vimo/core/Argument.java new file mode 100644 index 0000000..c7cf009 --- /dev/null +++ b/src/main/java/de/vimo/core/Argument.java @@ -0,0 +1,15 @@ +package de.vimo.core; + +public class Argument { + + private final String value; + + public Argument(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} + diff --git a/src/main/java/de/vimo/core/Command.java b/src/main/java/de/vimo/core/Command.java new file mode 100644 index 0000000..e29e252 --- /dev/null +++ b/src/main/java/de/vimo/core/Command.java @@ -0,0 +1,12 @@ +package de.vimo.core; + +import java.util.List; + +public interface Command { + + int exec(List flags, List args); + + String getName(); + + List getFlags(); +} diff --git a/src/main/java/de/vimo/core/Flag.java b/src/main/java/de/vimo/core/Flag.java new file mode 100644 index 0000000..7139abd --- /dev/null +++ b/src/main/java/de/vimo/core/Flag.java @@ -0,0 +1,28 @@ +package de.vimo.core; + +public class Flag { + + private final String shortName; + + private final String longName; + + private final String description; + + public Flag(String shortName, String longName, String description) { + this.shortName = shortName; + this.longName = longName; + this.description = description; + } + + public String getShortName() { + return shortName; + } + + public String getLongName() { + return longName; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/de/vimo/core/Line.java b/src/main/java/de/vimo/core/Line.java new file mode 100644 index 0000000..bc0eeab --- /dev/null +++ b/src/main/java/de/vimo/core/Line.java @@ -0,0 +1,73 @@ +package de.vimo.core; + +import java.util.List; + +public class Line { + + private final String command; + + private final List flags; + + private final List args; + + public Line(String command, List flags, List args) { + this.command = command; + this.flags = flags; + this.args = args; + } + + public String getCommand() { + return command; + } + + public List getFlags() { + return flags; + } + + public List getArgs() { + return args; + } + +// @Override +// public Line parse(String raw) { +// String regex = "[\\s]"; +// String[] myArray = raw.split(regex); +// +// for (int i = 1; i < myArray.length; i++) { +// if (myArray[i].contains("-")) { +// flags.add(myArray[i]); +// } else { +// args.add(myArray[i]); +// } +// } +// +// return new Line(myArray[0], flags, args); +// } + +// +// --- Please ignore this --- +// +// private final Command command; +// +// private final List flags; +// +// private final List args; +// +// public Line(Command command, List flags, List args) { +// this.command = command; +// this.flags = flags; +// this.args = args; +// } +// +// public Command getCommand() { +// return command; +// } +// +// public List getFlags() { +// return flags; +// } +// +// public List getArgs() { +// return args; +// } +} diff --git a/src/main/java/de/vimo/core/Parser.java b/src/main/java/de/vimo/core/Parser.java new file mode 100644 index 0000000..23c0f8e --- /dev/null +++ b/src/main/java/de/vimo/core/Parser.java @@ -0,0 +1,6 @@ +package de.vimo.core; + +public interface Parser { + + Line parse(String raw); +} diff --git a/src/test/java/de/vimo/AppTest.java b/src/test/java/de/vimo/AppTest.java deleted file mode 100644 index 8650642..0000000 --- a/src/test/java/de/vimo/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.vimo; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/src/test/java/de/vimo/core/ParserTest.java b/src/test/java/de/vimo/core/ParserTest.java new file mode 100644 index 0000000..d865a2b --- /dev/null +++ b/src/test/java/de/vimo/core/ParserTest.java @@ -0,0 +1,57 @@ +package de.vimo.core; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + + +public class ParserTest +{ + @Test + public void testParser() { + Parser parser = new Parser() { + @Override + public Line parse(String raw) { + String regex = "[\\s]"; + List flagsS = new ArrayList<>(List.of()); + List flagAll = new ArrayList<>(List.of()); + String result = ""; + List argsS = new ArrayList<>(List.of()); + String[] myArray = raw.split(regex); + + for (int i = 1; i < myArray.length; i++) { + if (myArray[i].contains("-")) { + result = myArray[i].replace("-",""); + flagsS = List.of(result.split("")); + flagAll.addAll(flagsS); + } else { + argsS.add(myArray[i]); + } + } + return new Line(myArray[0], flagAll, argsS); + } + }; // <-- Your implementation goes here + + testInput(parser, "ls", "ls", List.of(), List.of()); + testInput(parser, "ls -la", "ls", List.of("l", "a"), List.of()); + testInput(parser, "ls ./hello/world", "ls", List.of(), List.of("./hello/world")); + testInput(parser, "ls -la ./what", "ls", List.of("l", "a"), List.of("./what")); + testInput(parser, "rm -r /bin /opt", "rm", List.of("r"), List.of("/bin", "/opt")); + testInput(parser, "cd .", "cd", List.of(), List.of(".")); + testInput(parser, "mkdir .", "mkdir", List.of(), List.of(".")); + testInput(parser, "super -abc -de -f super nice danke paul", "super", List.of("a", "b", "c", "d", "e", "f"), List.of("super", "nice", "danke", "paul")); + } + + private void testInput(Parser parser, String input, String expectedCommand, List expectedFlags, List expectedArgs) { + Line line = parser.parse(input); + + assertEquals(expectedCommand, line.getCommand(), "Wrong command"); + assertEquals(expectedFlags, line.getFlags(), "Wrong flags"); + assertEquals(expectedArgs, line.getArgs(), "Wrong args"); + } +} diff --git a/target/classes/de/vimo/InputTextTillCommand.class b/target/classes/de/vimo/InputTextTillCommand.class new file mode 100644 index 0000000..3458787 Binary files /dev/null and b/target/classes/de/vimo/InputTextTillCommand.class differ diff --git a/target/classes/de/vimo/Jcmd.class b/target/classes/de/vimo/Jcmd.class index b9e0699..fb795a3 100644 Binary files a/target/classes/de/vimo/Jcmd.class and b/target/classes/de/vimo/Jcmd.class differ diff --git a/target/classes/de/vimo/Main.class b/target/classes/de/vimo/Main.class new file mode 100644 index 0000000..b3021f4 Binary files /dev/null and b/target/classes/de/vimo/Main.class differ diff --git a/target/classes/de/vimo/command/CdCommand.class b/target/classes/de/vimo/command/CdCommand.class new file mode 100644 index 0000000..5376783 Binary files /dev/null and b/target/classes/de/vimo/command/CdCommand.class differ diff --git a/target/classes/de/vimo/command/HelpCommand.class b/target/classes/de/vimo/command/HelpCommand.class new file mode 100644 index 0000000..92efecd Binary files /dev/null and b/target/classes/de/vimo/command/HelpCommand.class differ diff --git a/target/classes/de/vimo/command/LsCommand.class b/target/classes/de/vimo/command/LsCommand.class new file mode 100644 index 0000000..e8c5c47 Binary files /dev/null and b/target/classes/de/vimo/command/LsCommand.class differ diff --git a/target/classes/de/vimo/command/MkdirCommand.class b/target/classes/de/vimo/command/MkdirCommand.class new file mode 100644 index 0000000..741d02b Binary files /dev/null and b/target/classes/de/vimo/command/MkdirCommand.class differ diff --git a/target/classes/de/vimo/core/Argument.class b/target/classes/de/vimo/core/Argument.class new file mode 100644 index 0000000..cff4d83 Binary files /dev/null and b/target/classes/de/vimo/core/Argument.class differ diff --git a/target/classes/de/vimo/core/Command.class b/target/classes/de/vimo/core/Command.class new file mode 100644 index 0000000..a42dded Binary files /dev/null and b/target/classes/de/vimo/core/Command.class differ diff --git a/target/classes/de/vimo/core/Flag.class b/target/classes/de/vimo/core/Flag.class new file mode 100644 index 0000000..a0008db Binary files /dev/null and b/target/classes/de/vimo/core/Flag.class differ diff --git a/target/classes/de/vimo/core/Line.class b/target/classes/de/vimo/core/Line.class new file mode 100644 index 0000000..1af244e Binary files /dev/null and b/target/classes/de/vimo/core/Line.class differ diff --git a/target/classes/de/vimo/core/Parser.class b/target/classes/de/vimo/core/Parser.class new file mode 100644 index 0000000..ce31103 Binary files /dev/null and b/target/classes/de/vimo/core/Parser.class differ diff --git a/target/test-classes/de/vimo/core/ParserTest$1.class b/target/test-classes/de/vimo/core/ParserTest$1.class new file mode 100644 index 0000000..b90da57 Binary files /dev/null and b/target/test-classes/de/vimo/core/ParserTest$1.class differ diff --git a/target/test-classes/de/vimo/core/ParserTest.class b/target/test-classes/de/vimo/core/ParserTest.class new file mode 100644 index 0000000..d2f70ba Binary files /dev/null and b/target/test-classes/de/vimo/core/ParserTest.class differ