docs: public static ServerEnvironmentWrapper determineEnvironment(String[] args, Properties systemProperties, Map<String, String> systemEnvironment,
                                                           ServerEnvironment.LaunchType launchType, long startTime) {
          final int argsLength = args.length;
          String serverConfig = null;
          String gitRepository = null;
          String gitBranch = MASTER;
          String gitAuthConfiguration = null;
          RunningMode runningMode = RunningMode.NORMAL;
          ProductConfig productConfig;
          ConfigurationFile.InteractionPolicy configInteractionPolicy = ConfigurationFile.InteractionPolicy.STANDARD;
          boolean startSuspended = false;
          boolean removeConfig = false;
          boolean startModeSet = false;
          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 = ProductConfig.fromFilesystemSlot(Module.getBootModuleLoader(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), null);
                      STDOUT.println(productConfig.getPrettyVersionString());
                      return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.NORMAL);
                  } else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
                      usage();
                      return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.NORMAL);
                  } else if (CommandLineConstants.SERVER_CONFIG.equals(arg) || CommandLineConstants.SHORT_SERVER_CONFIG.equals(arg)
                          || CommandLineConstants.OLD_SERVER_CONFIG.equals(arg)) {
                      assertSingleConfig(serverConfig);
                      serverConfig = args[++i];
                  } else if (arg.startsWith(CommandLineConstants.SERVER_CONFIG)) {
                      assertSingleConfig(serverConfig);
                      serverConfig = parseValue(arg, CommandLineConstants.SERVER_CONFIG);
                      if (serverConfig == null) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } else if (arg.startsWith(CommandLineConstants.SHORT_SERVER_CONFIG)) {
                      assertSingleConfig(serverConfig);
                      serverConfig = parseValue(arg, CommandLineConstants.SHORT_SERVER_CONFIG);
                      if (serverConfig == null) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } else if (arg.startsWith(CommandLineConstants.READ_ONLY_SERVER_CONFIG)) {
                      assertSingleConfig(serverConfig);
                      serverConfig = parseValue(arg, CommandLineConstants.READ_ONLY_SERVER_CONFIG);
                      if (serverConfig == null) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      configInteractionPolicy = ConfigurationFile.InteractionPolicy.READ_ONLY;
                  } else if (arg.startsWith(CommandLineConstants.OLD_SERVER_CONFIG)) {
                      serverConfig = parseValue(arg, CommandLineConstants.OLD_SERVER_CONFIG);
                      if (serverConfig == null) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } else if (arg.startsWith("--internal-empty-config")) {
                      assert launchType == ServerEnvironment.LaunchType.EMBEDDED;
                      configInteractionPolicy = removeConfig ? ConfigurationFile.InteractionPolicy.DISCARD : ConfigurationFile.InteractionPolicy.NEW;
                  } else if (arg.startsWith("--internal-remove-config")) {
                      assert launchType == ServerEnvironment.LaunchType.EMBEDDED;
                      removeConfig = true;
                      if (configInteractionPolicy == ConfigurationFile.InteractionPolicy.NEW) {
                          configInteractionPolicy = ConfigurationFile.InteractionPolicy.DISCARD;
                      }
                  } 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 new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
                      String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
                      if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
                      String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
                      if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  }  else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
                      String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
                      if (urlSpec == null || !processProperties(arg, urlSpec,systemProperties)) {
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } 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) {
                          STDERR.println(ServerLogger.ROOT_LOGGER.noArgValue(arg));
                          usage();
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
                      value = fixPossibleIPv6URL(value);
                      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) {
                          STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
                          usage();
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
                      value = fixPossibleIPv6URL(value);
  
                      systemProperties.setProperty(ServerEnvironment.JBOSS_DEFAULT_MULTICAST_ADDRESS, value);
                  } else if (CommandLineConstants.ADMIN_ONLY.equals(arg)) {
                      if(startModeSet) {
                          STDERR.println(ServerLogger.ROOT_LOGGER.cannotSetBothAdminOnlyAndStartMode());
                          usage();
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      startModeSet = true;
                      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.startsWith(CommandLineConstants.START_MODE)) {
                      if(startModeSet) {
                          STDERR.println(ServerLogger.ROOT_LOGGER.cannotSetBothAdminOnlyAndStartMode());
                          usage();
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      startModeSet = true;
                      int idx = arg.indexOf('=');
                      if (idx == arg.length() - 1) {
                          STDERR.println(ServerLogger.ROOT_LOGGER.noArgValue(arg));
                          usage();
                          return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                      String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
                      value = value.toLowerCase(Locale.ENGLISH);
                      switch (value) {
                          case CommandLineConstants.ADMIN_ONLY_MODE:
                              runningMode = RunningMode.ADMIN_ONLY;
                          break;
                          case CommandLineConstants.SUSPEND_MODE:
                              startSuspended = true;
                          break;
                          case CommandLineConstants.NORMAL_MODE:
                              break;
                          default:
                              STDERR.println(ServerLogger.ROOT_LOGGER.unknownStartMode(value));
                              usage();
                              return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                      }
                  } 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 if (arg.equals(CommandLineConstants.SECMGR)) {
                      // 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 == -1) {
                          final int next = i + 1;
                          if (next < argsLength) {
                              gitRepository = args[next];
                              i++;
                          } else {
                              STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
                              usage();
                              return null;
                          }
                      } else {
                          gitRepository = arg.substring(idx + 1, arg.length());
                      }
                  } else if(arg.startsWith(CommandLineConstants.GIT_AUTH)) {
                      int idx = arg.indexOf("=");
                      if (idx == -1) {
                         final int next = i + 1;
                          if (next < argsLength) {
                              gitAuthConfiguration = args[next];
                              i++;
                          } else {
                              STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
                              usage();
                              return null;
                          }
                      } else {
                          gitAuthConfiguration = arg.substring(idx + 1, arg.length());
                      }
                  } else if(arg.startsWith(CommandLineConstants.GIT_BRANCH)) {
                      int idx = arg.indexOf("=");
                      if (idx == -1) {
                         final int next = i + 1;
                          if (next < argsLength) {
                              gitBranch = args[next];
                              i++;
                          } else {
                              STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
                              usage();
                              return null;
                          }
                      } else {
                          gitBranch = arg.substring(idx + 1, arg.length());
                      }
                  }else {
                      STDERR.println(ServerLogger.ROOT_LOGGER.invalidCommandLineOption(arg));
                      usage();
                      return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
                  }
              } catch (IndexOutOfBoundsException e) {
                  STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg));
                  usage();
                  return new ServerEnvironmentWrapper(ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR);
              }
          }
  
          String hostControllerName = null; // No host controller unless in domain mode.
          productConfig = ProductConfig.fromFilesystemSlot(Module.getBootModuleLoader(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), systemProperties);
          return new ServerEnvironmentWrapper(new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment,
                  serverConfig, configInteractionPolicy, launchType, runningMode, productConfig, startTime, startSuspended,
                  gitRepository, gitBranch, gitAuthConfiguration));
      }