concept
This commit is contained in:
parent
2d7e0f893a
commit
6e23dd7f1a
1
jcmd
1
jcmd
@ -1 +0,0 @@
|
||||
Subproject commit 52e0edc1b95565edc335a1d1c120cf7b8f4bd4c9
|
||||
BIN
jcmd/.DS_Store
vendored
Normal file
BIN
jcmd/.DS_Store
vendored
Normal file
Binary file not shown.
3
jcmd/.idea/.gitignore
generated
vendored
Normal file
3
jcmd/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
13
jcmd/.idea/compiler.xml
generated
Normal file
13
jcmd/.idea/compiler.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="jcmd" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
7
jcmd/.idea/encodings.xml
generated
Normal file
7
jcmd/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
20
jcmd/.idea/jarRepositories.xml
generated
Normal file
20
jcmd/.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
12
jcmd/.idea/misc.xml
generated
Normal file
12
jcmd/.idea/misc.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="temurin-23" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
7
jcmd/.idea/vcs.xml
generated
Normal file
7
jcmd/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
0
jcmd/.mvn/jvm.config
Normal file
0
jcmd/.mvn/jvm.config
Normal file
0
jcmd/.mvn/maven.config
Normal file
0
jcmd/.mvn/maven.config
Normal file
92
jcmd/pom.xml
Normal file
92
jcmd/pom.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.vimo</groupId>
|
||||
<artifactId>jcmd</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>jcmd</name>
|
||||
<description>A simple jcmd.</description>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.12.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</plugin>
|
||||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
BIN
jcmd/src/.DS_Store
vendored
Normal file
BIN
jcmd/src/.DS_Store
vendored
Normal file
Binary file not shown.
12
jcmd/src/main/java/de/vimo/InputTextTillCommand.java
Normal file
12
jcmd/src/main/java/de/vimo/InputTextTillCommand.java
Normal file
@ -0,0 +1,12 @@
|
||||
package de.vimo;
|
||||
|
||||
public interface InputTextTillCommand {
|
||||
|
||||
void splitTextToCommandOptionArgument(String text);
|
||||
|
||||
void setCommand(String command);
|
||||
|
||||
void setArgument(String argument);
|
||||
|
||||
void setOption(String option);
|
||||
}
|
||||
48
jcmd/src/main/java/de/vimo/Jcmd.java
Normal file
48
jcmd/src/main/java/de/vimo/Jcmd.java
Normal file
@ -0,0 +1,48 @@
|
||||
package de.vimo;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Jcmd implements InputTextTillCommand
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Scanner inputUser = new Scanner(System.in);
|
||||
System.out.println("Typ your terminal command");
|
||||
|
||||
try {
|
||||
while (inputUser.hasNextLine()) {
|
||||
String line = inputUser.nextLine();
|
||||
if (line.equals("q")) {
|
||||
break;
|
||||
}
|
||||
System.out.println(line);
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println(e);
|
||||
} finally {
|
||||
inputUser.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void splitTextToCommandOptionArgument(String text) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCommand(String command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArgument(String argument) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(String option) {
|
||||
|
||||
}
|
||||
}
|
||||
22
jcmd/src/main/java/de/vimo/Main.java
Normal file
22
jcmd/src/main/java/de/vimo/Main.java
Normal file
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
jcmd/src/main/java/de/vimo/command/CdCommand.java
Normal file
26
jcmd/src/main/java/de/vimo/command/CdCommand.java
Normal file
@ -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<Flag> flags, List<Argument> args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flag> getFlags() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
25
jcmd/src/main/java/de/vimo/command/HelpCommand.java
Normal file
25
jcmd/src/main/java/de/vimo/command/HelpCommand.java
Normal file
@ -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<Flag> flags, List<Argument> args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flag> getFlags() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
25
jcmd/src/main/java/de/vimo/command/LsCommand.java
Normal file
25
jcmd/src/main/java/de/vimo/command/LsCommand.java
Normal file
@ -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<Flag> flags, List<Argument> args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flag> getFlags() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
25
jcmd/src/main/java/de/vimo/command/MkdirCommand.java
Normal file
25
jcmd/src/main/java/de/vimo/command/MkdirCommand.java
Normal file
@ -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<Flag> flags, List<Argument> args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flag> getFlags() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
15
jcmd/src/main/java/de/vimo/core/Argument.java
Normal file
15
jcmd/src/main/java/de/vimo/core/Argument.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
12
jcmd/src/main/java/de/vimo/core/Command.java
Normal file
12
jcmd/src/main/java/de/vimo/core/Command.java
Normal file
@ -0,0 +1,12 @@
|
||||
package de.vimo.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Command {
|
||||
|
||||
int exec(List<Flag> flags, List<Argument> args);
|
||||
|
||||
String getName();
|
||||
|
||||
List<Flag> getFlags();
|
||||
}
|
||||
28
jcmd/src/main/java/de/vimo/core/Flag.java
Normal file
28
jcmd/src/main/java/de/vimo/core/Flag.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
78
jcmd/src/main/java/de/vimo/core/Line.java
Normal file
78
jcmd/src/main/java/de/vimo/core/Line.java
Normal file
@ -0,0 +1,78 @@
|
||||
package de.vimo.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Line {
|
||||
|
||||
private String command;
|
||||
|
||||
private List<String> flags;
|
||||
|
||||
private List<String> args;
|
||||
|
||||
public Line(String command, List<String> flags, List<String> args) {
|
||||
this.command = command;
|
||||
this.flags = flags;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public Line(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public List<String> 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<Flag> flags;
|
||||
//
|
||||
// private final List<Argument> args;
|
||||
//
|
||||
// public Line(Command command, List<Flag> flags, List<Argument> args) {
|
||||
// this.command = command;
|
||||
// this.flags = flags;
|
||||
// this.args = args;
|
||||
// }
|
||||
//
|
||||
// public Command getCommand() {
|
||||
// return command;
|
||||
// }
|
||||
//
|
||||
// public List<Flag> getFlags() {
|
||||
// return flags;
|
||||
// }
|
||||
//
|
||||
// public List<Argument> getArgs() {
|
||||
// return args;
|
||||
// }
|
||||
}
|
||||
6
jcmd/src/main/java/de/vimo/core/Parser.java
Normal file
6
jcmd/src/main/java/de/vimo/core/Parser.java
Normal file
@ -0,0 +1,6 @@
|
||||
package de.vimo.core;
|
||||
|
||||
public interface Parser {
|
||||
|
||||
Line parse(String raw);
|
||||
}
|
||||
117
jcmd/src/main/java/de/vimo/core/ParserVivi.java
Normal file
117
jcmd/src/main/java/de/vimo/core/ParserVivi.java
Normal file
@ -0,0 +1,117 @@
|
||||
package de.vimo.core;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParserVivi implements Parser {
|
||||
|
||||
List<String> flags = new ArrayList<>(List.of());
|
||||
List<String> args = new ArrayList<>(List.of());
|
||||
|
||||
|
||||
@Override
|
||||
public Line parse(String raw) {
|
||||
|
||||
flags = new ArrayList<>(List.of());
|
||||
args = new ArrayList<>(List.of());
|
||||
|
||||
String replaceWords = raw.replaceAll("\\s+"," ");
|
||||
String trimWords = replaceWords.trim();
|
||||
String[] arrayWords = trimWords.split(" ");
|
||||
|
||||
String command = null;
|
||||
boolean commandCheck = isCommandValid(arrayWords);
|
||||
boolean flagsCheck = isFlagsValid(arrayWords);
|
||||
boolean argsCheck = isArgsValid(arrayWords);
|
||||
|
||||
Line resultLine = null;
|
||||
|
||||
if (arrayWords.length > 0) {
|
||||
if (commandCheck) {
|
||||
command = arrayWords[0];
|
||||
if (arrayWords.length == 1) {
|
||||
resultLine = new Line(command, flags, args);
|
||||
} else if (flagsCheck && !argsCheck) {
|
||||
resultLine = new Line(command, flags, args);
|
||||
} else if (!flagsCheck && argsCheck) {
|
||||
resultLine = new Line(command, flags, args);
|
||||
} else if (flagsCheck && argsCheck) {
|
||||
resultLine = new Line(command, flags, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultLine;
|
||||
}
|
||||
|
||||
public boolean isArgsValid(String[] words) {
|
||||
int arrayWordsLength = words.length;
|
||||
boolean isArgsValid = false;
|
||||
char[] charWord = new char[0];
|
||||
|
||||
for (int i = 1; i < words.length; i++) {
|
||||
charWord = words[i].toCharArray();
|
||||
|
||||
if (checkCharArgs(charWord)) {
|
||||
args.add(words[i]);
|
||||
isArgsValid = true;
|
||||
}
|
||||
}
|
||||
return isArgsValid;
|
||||
}
|
||||
|
||||
public boolean checkCharArgs(char[] charWord) {
|
||||
boolean isChecked = false;
|
||||
|
||||
if (charWord.length != 0) {
|
||||
if (!(charWord[0] == '-')) {
|
||||
isChecked = true;
|
||||
}
|
||||
}
|
||||
return isChecked;
|
||||
}
|
||||
|
||||
public boolean isCommandValid(String[] arrayWords) {
|
||||
int arrayWordsLength = arrayWords.length;
|
||||
boolean isCommandValid = false;
|
||||
|
||||
if (arrayWordsLength != 0) {
|
||||
if (arrayWords[0].matches("[a-zA-Z]+")) {
|
||||
isCommandValid = true;
|
||||
}
|
||||
}
|
||||
return isCommandValid;
|
||||
}
|
||||
|
||||
public boolean isFlagsValid(String[] words) {
|
||||
char[] charWord = new char[0];
|
||||
boolean isFlagsValid = false;
|
||||
|
||||
for (int i = 1; i < words.length; i++) {
|
||||
if (words[i].contains("-")) {
|
||||
charWord = words[i].toCharArray();
|
||||
if (checkChar(charWord)) {
|
||||
for (int j = 1; j < charWord.length; j++) {
|
||||
flags.add(String.valueOf(charWord[j]));
|
||||
}
|
||||
isFlagsValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isFlagsValid;
|
||||
}
|
||||
|
||||
public boolean checkChar(char[] charWord) {
|
||||
boolean isChecked = false;
|
||||
|
||||
if (charWord.length != 1) {
|
||||
for (int i = 0; i < charWord.length; i++) {
|
||||
if (charWord[0] == '-' && Character.isLetter(charWord[1])) {
|
||||
isChecked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isChecked;
|
||||
}
|
||||
}
|
||||
26
jcmd/src/site/site.xml
Normal file
26
jcmd/src/site/site.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project name="jcmd" xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
|
||||
<bannerLeft>
|
||||
<name>jcmd</name>
|
||||
<src>https://maven.apache.org/images/apache-maven-project.png</src>
|
||||
<href>https://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
|
||||
<bannerRight>
|
||||
<src>https://maven.apache.org/images/maven-logo-black-on-white.png</src>
|
||||
<href>https://maven.apache.org/</href>
|
||||
</bannerRight>
|
||||
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>1.7</version>
|
||||
</skin>
|
||||
|
||||
<body>
|
||||
<menu ref="parent" />
|
||||
<menu ref="reports" />
|
||||
</body>
|
||||
</project>
|
||||
49
jcmd/src/test/java/de/vimo/core/ParserTest.java
Normal file
49
jcmd/src/test/java/de/vimo/core/ParserTest.java
Normal file
@ -0,0 +1,49 @@
|
||||
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() {
|
||||
// <-- Your implementation goes here
|
||||
|
||||
Parser parser = new ParserVivi(); // <-- Your implementation goes here
|
||||
|
||||
// test invalid strings -> should return null
|
||||
assertNull(parser.parse(""));
|
||||
assertNull(parser.parse("-"));
|
||||
assertNull(parser.parse("ls -"));
|
||||
assertNull(parser.parse("ls --"));
|
||||
|
||||
// test valid string
|
||||
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"));
|
||||
|
||||
// new tests
|
||||
|
||||
testInput(parser, "print hello-world", "print", List.of(), List.of("hello-world"));
|
||||
}
|
||||
|
||||
private void testInput(Parser parser, String input, String expectedCommand, List<String> expectedFlags, List<String> expectedArgs) {
|
||||
Line line = parser.parse(input);
|
||||
|
||||
assertEquals(expectedCommand, line.getCommand(), "Wrong command");
|
||||
assertEquals(expectedFlags, line.getFlags(), "Wrong flags");
|
||||
assertEquals(expectedArgs, line.getArgs(), "Wrong args");
|
||||
}
|
||||
}
|
||||
BIN
jcmd/target/.DS_Store
vendored
Normal file
BIN
jcmd/target/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/InputTextTillCommand.class
Normal file
BIN
jcmd/target/classes/de/vimo/InputTextTillCommand.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/Jcmd.class
Normal file
BIN
jcmd/target/classes/de/vimo/Jcmd.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/Main.class
Normal file
BIN
jcmd/target/classes/de/vimo/Main.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/check/StringCheck.class
Normal file
BIN
jcmd/target/classes/de/vimo/check/StringCheck.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/command/CdCommand.class
Normal file
BIN
jcmd/target/classes/de/vimo/command/CdCommand.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/command/HelpCommand.class
Normal file
BIN
jcmd/target/classes/de/vimo/command/HelpCommand.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/command/LsCommand.class
Normal file
BIN
jcmd/target/classes/de/vimo/command/LsCommand.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/command/MkdirCommand.class
Normal file
BIN
jcmd/target/classes/de/vimo/command/MkdirCommand.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/Argument.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/Argument.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/Command.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/Command.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/Flag.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/Flag.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/Line.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/Line.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/Parser.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/Parser.class
Normal file
Binary file not shown.
BIN
jcmd/target/classes/de/vimo/core/ParserVivi.class
Normal file
BIN
jcmd/target/classes/de/vimo/core/ParserVivi.class
Normal file
Binary file not shown.
BIN
jcmd/target/test-classes/de/vimo/core/ParserTest.class
Normal file
BIN
jcmd/target/test-classes/de/vimo/core/ParserTest.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user