Skip to content

Commit

Permalink
Merge pull request #5885 from ehsavoie/WFCORE-6717
Browse files Browse the repository at this point in the history
[WFCORE-6717]: Incorrectly set options on the command line should fail
  • Loading branch information
yersan authored Mar 1, 2024
2 parents c55f3ce + cde3d7d commit dd8c13b
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions server/src/main/java/org/jboss/as/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,45 +323,48 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope
// do nothing, just need to filter out as Windows batch scripts cannot filter it out
} else if(arg.startsWith(CommandLineConstants.GIT_REPO)) {
int idx = arg.indexOf("=");
if (idx == arg.length() - 1) {
return requireValue(arg, productConfig);
}
if (idx == -1) {
final int next = i + 1;
if (next < argsLength) {
gitRepository = args[next];
i++;
} else {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
return requireValue(arg, productConfig);
}
} else {
gitRepository = arg.substring(idx + 1);
}
} else if(arg.startsWith(CommandLineConstants.GIT_AUTH)) {
int idx = arg.indexOf("=");
if (idx == arg.length() - 1) {
return requireValue(arg, productConfig);
}
if (idx == -1) {
final int next = i + 1;
if (next < argsLength) {
gitAuthConfiguration = args[next];
i++;
} else {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
return requireValue(arg, productConfig);
}
} else {
gitAuthConfiguration = arg.substring(idx + 1);
}
} else if(arg.startsWith(CommandLineConstants.GIT_BRANCH)) {
int idx = arg.indexOf("=");
if (idx == arg.length() - 1) {
return requireValue(arg, productConfig);
}
if (idx == -1) {
final int next = i + 1;
if (next < argsLength) {
gitBranch = args[next];
i++;
} else {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
return requireValue(arg, productConfig);
}
} else {
gitBranch = arg.substring(idx + 1);
Expand All @@ -375,15 +378,16 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope
} else if(ConfigurationExtensionFactory.isConfigurationExtensionSupported()
&& ConfigurationExtensionFactory.commandLineContainsArgument(arg)) {
int idx = arg.indexOf("=");
if (idx == arg.length() - 1) {
return requireValue(arg, productConfig);
}
if (idx == -1) {
final int next = i + 1;
if (next < argsLength) {
supplementalConfiguration = args[next];
i++;
} else {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
return requireValue(arg, productConfig);
}
} else {
supplementalConfiguration = arg.substring(idx + 1);
Expand All @@ -394,9 +398,7 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope
return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
}
} catch (IndexOutOfBoundsException e) {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper(ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
return requireValue(arg, productConfig);
}
}

Expand All @@ -408,6 +410,12 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope
startGracefully, gitRepository, gitBranch, gitAuthConfiguration, supplementalConfiguration));
}

private static ServerEnvironmentWrapper requireValue(String arg, ProductConfig productConfig) {
STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
usage(productConfig);
return new ServerEnvironmentWrapper(ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
}

private static void assertSingleConfig(String serverConfig) {
if (serverConfig != null) {
throw ServerLogger.ROOT_LOGGER.cannotHaveBothInitialServerConfigAndServerConfig();
Expand Down

0 comments on commit dd8c13b

Please sign in to comment.