Refactor script parsing

This commit is contained in:
icelimetea 2022-05-14 16:48:14 +01:00
parent fac0b027b3
commit 3f259eb97a
2 changed files with 16 additions and 31 deletions

View File

@ -51,8 +51,6 @@ public final class EntryPoint {
private final Parameters params = new Parameters();
private String launcherType;
public static void main(String[] args) {
EntryPoint listener = new EntryPoint();
@ -80,15 +78,6 @@ public final class EntryPoint {
return Action.Abort;
}
case "launcher": {
if (tokens.length != 2)
throw new ParseException("Expected 2 tokens, got " + tokens.length);
launcherType = tokens[1];
return Action.Proceed;
}
default: {
if (tokens.length != 2)
throw new ParseException("Error while parsing:" + inData);
@ -129,30 +118,24 @@ public final class EntryPoint {
return 1;
}
if (launcherType != null) {
try {
Launcher launcher =
LauncherFactory
.getInstance()
.createLauncher(launcherType, params);
try {
Launcher launcher =
LauncherFactory
.getInstance()
.createLauncher(params);
launcher.launch();
launcher.launch();
return 0;
} catch (IllegalArgumentException e) {
LOGGER.log(Level.SEVERE, "Wrong argument.", e);
return 0;
} catch (IllegalArgumentException e) {
LOGGER.log(Level.SEVERE, "Wrong argument.", e);
return 1;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
return 1;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
return 1;
}
return 1;
}
LOGGER.log(Level.SEVERE, "No valid launcher implementation specified.");
return 1;
}
private enum Action {

View File

@ -39,7 +39,9 @@ public final class LauncherFactory {
});
}
public Launcher createLauncher(String name, Parameters parameters) {
public Launcher createLauncher(Parameters parameters) {
String name = parameters.first("launcher");
LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherProvider == null)