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 final Parameters params = new Parameters();
private String launcherType;
public static void main(String[] args) { public static void main(String[] args) {
EntryPoint listener = new EntryPoint(); EntryPoint listener = new EntryPoint();
@ -80,15 +78,6 @@ public final class EntryPoint {
return Action.Abort; 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: { default: {
if (tokens.length != 2) if (tokens.length != 2)
throw new ParseException("Error while parsing:" + inData); throw new ParseException("Error while parsing:" + inData);
@ -129,12 +118,11 @@ public final class EntryPoint {
return 1; return 1;
} }
if (launcherType != null) {
try { try {
Launcher launcher = Launcher launcher =
LauncherFactory LauncherFactory
.getInstance() .getInstance()
.createLauncher(launcherType, params); .createLauncher(params);
launcher.launch(); launcher.launch();
@ -150,11 +138,6 @@ public final class EntryPoint {
} }
} }
LOGGER.log(Level.SEVERE, "No valid launcher implementation specified.");
return 1;
}
private enum Action { private enum Action {
Proceed, Proceed,
Launch, Launch,

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); LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherProvider == null) if (launcherProvider == null)