public static ServerEnvironment determineEnvironment(String[] args, Properties systemProperties, Map<String, String> systemEnvironment, ServerEnvironment.LaunchType launchType) {
final int argsLength = args.length;
String serverConfig = null;
String initialServerConfig = null;
RunningMode runningMode = RunningMode.NORMAL;
ProductConfig productConfig;
for (int i = 0; i < argsLength; i++) {
final String arg = args[i];
try {
if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), null);
System.out.println(productConfig.getPrettyVersionString());
return null;
} else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
usage();
return null;
} else if (CommandLineConstants.SERVER_CONFIG.equals(arg) || CommandLineConstants.SHORT_SERVER_CONFIG.equals(arg)
|| CommandLineConstants.OLD_SERVER_CONFIG.equals(arg)) {
serverConfig = args[++i];
} else if (arg.startsWith(CommandLineConstants.SERVER_CONFIG)) {
serverConfig = parseValue(arg, CommandLineConstants.SERVER_CONFIG);
if (serverConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.SHORT_SERVER_CONFIG)) {
serverConfig = parseValue(arg, CommandLineConstants.SHORT_SERVER_CONFIG);
if (serverConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.READ_ONLY_SERVER_CONFIG)) {
initialServerConfig = parseValue(arg, CommandLineConstants.READ_ONLY_SERVER_CONFIG);
if (initialServerConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.OLD_SERVER_CONFIG)) {
serverConfig = parseValue(arg, CommandLineConstants.OLD_SERVER_CONFIG);
if (serverConfig == null) {
return null;
}
} else if (CommandLineConstants.PROPERTIES.equals(arg) || CommandLineConstants.OLD_PROPERTIES.equals(arg)
|| CommandLineConstants.SHORT_PROPERTIES.equals(arg)) {
// Set system properties from url/file
if (!processProperties(arg, args[++i],systemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.SYS_PROP)) {
// set a system property
String name, value;
int idx = arg.indexOf("=");
if (idx == -1) {
name = arg.substring(2);
value = "true";
} else {
name = arg.substring(2, idx);
value = arg.substring(idx + 1, arg.length());
}
systemProperties.setProperty(name, value);
} else if (arg.startsWith(CommandLineConstants.PUBLIC_BIND_ADDRESS)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.printf(ServerMessages.MESSAGES.noArgValue(arg));
usage();
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
String propertyName = null;
if (idx < 0) {
// -b xxx -bmanagement xxx
propertyName = arg.length() == 2 ? ServerEnvironment.JBOSS_BIND_ADDRESS : ServerEnvironment.JBOSS_BIND_ADDRESS_PREFIX + arg.substring(2);
} else if (idx == 2) {
// -b=xxx
propertyName = ServerEnvironment.JBOSS_BIND_ADDRESS;
} else {
// -bmanagement=xxx
propertyName = ServerEnvironment.JBOSS_BIND_ADDRESS_PREFIX + arg.substring(2, idx);
}
systemProperties.setProperty(propertyName, value);
} else if (arg.startsWith(CommandLineConstants.DEFAULT_MULTICAST_ADDRESS)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.printf(ServerMessages.MESSAGES.valueExpectedForCommandLineOption(arg));
System.err.println();
usage();
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
systemProperties.setProperty(ServerEnvironment.JBOSS_DEFAULT_MULTICAST_ADDRESS, value);
} else if (CommandLineConstants.ADMIN_ONLY.equals(arg)) {
runningMode = RunningMode.ADMIN_ONLY;
} else if (arg.startsWith(CommandLineConstants.SECURITY_PROP)) {
//Value can be a comma separated key value pair
//Drop the first 2 characters
String token = arg.substring(2);
processSecurityProperties(token,systemProperties);
} else if (arg.equals(CommandLineConstants.DEBUG)) { // Need to process the debug options as they cannot be filtered out in Windows
// The next option may or may not be a port. Assume if it's a number and doesn't start with a - it's the port
final int next = i + 1;
if (next < argsLength) {
final String nextArg = args[next];
if (!nextArg.startsWith("-")) {
try {
Integer.parseInt(nextArg);
i++;
} catch (NumberFormatException ignore) {
}
}
}
} else {
System.err.printf(ServerMessages.MESSAGES.invalidCommandLineOption(arg));
usage();
return null;
}
} catch (IndexOutOfBoundsException e) {
System.err.printf(ServerMessages.MESSAGES.valueExpectedForCommandLineOption(arg));
usage();
return null;
}
}
if (serverConfig != null && initialServerConfig != null) {
throw ServerMessages.MESSAGES.cannotHaveBothInitialServerConfigAndServerConfig();
}
String hostControllerName = null; // No host controller unless in domain mode.
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), systemProperties);
return new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, serverConfig, initialServerConfig, launchType, runningMode, productConfig);
}