Search in sources :

Example 1 with ProductConfig

use of org.jboss.as.version.ProductConfig in project wildfly by wildfly.

the class Main method determineEnvironment.

public static ParsedOptions determineEnvironment(String[] args, Properties systemProperties, Map<String, String> systemEnvironment, ServerEnvironment.LaunchType launchType) {
    List<String> clientArguments = new ArrayList<String>();
    ParsedOptions ret = new ParsedOptions();
    ret.clientArguments = clientArguments;
    final int argsLength = args.length;
    String appClientConfig = "appclient.xml";
    boolean clientArgs = false;
    ProductConfig productConfig;
    boolean hostSet = false;
    for (int i = 0; i < argsLength; i++) {
        final String arg = args[i];
        try {
            if (clientArgs) {
                clientArguments.add(arg);
            } else 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(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), null);
                STDOUT.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.PROPERTIES.equals(arg) || CommandLineConstants.OLD_PROPERTIES.equals(arg) || CommandLineConstants.SHORT_PROPERTIES.equals(arg)) {
                // Set system properties from url/file
                if (!processProperties(arg, args[++i])) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.equals(CommandLineConstants.SHORT_HOST) || arg.equals(CommandLineConstants.HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = args[++i];
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.SHORT_HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = parseValue(arg, CommandLineConstants.SHORT_HOST);
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = parseValue(arg, CommandLineConstants.HOST);
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.CONNECTION_PROPERTIES)) {
                if (hostSet) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                String fileUrl = parseValue(arg, CommandLineConstants.CONNECTION_PROPERTIES);
                ret.propertiesFile = fileUrl;
            } 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);
                WildFlySecurityManager.setPropertyPrivileged(name, value);
            } else if (arg.startsWith(CommandLineConstants.APPCLIENT_CONFIG)) {
                appClientConfig = parseValue(arg, CommandLineConstants.APPCLIENT_CONFIG);
            } else if (CommandLineConstants.SECMGR.equals(arg)) {
            // ignore the argument as it's allowed, but passed to jboss-modules and not used here
            } else {
                if (arg.startsWith("-")) {
                    STDOUT.println(AppClientLogger.ROOT_LOGGER.unknownOption(arg));
                    usage();
                    return null;
                }
                clientArgs = true;
                clientArguments.add(arg);
            }
        } catch (IndexOutOfBoundsException e) {
            STDERR.println(AppClientLogger.ROOT_LOGGER.argumentExpected(arg));
            usage();
            return null;
        }
    }
    // No host controller unless in domain mode.
    String hostControllerName = null;
    productConfig = new ProductConfig(Module.getBootModuleLoader(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), systemProperties);
    ret.environment = new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, appClientConfig, null, launchType, null, productConfig);
    return ret;
}
Also used : ServerEnvironment(org.jboss.as.server.ServerEnvironment) ArrayList(java.util.ArrayList) ProductConfig(org.jboss.as.version.ProductConfig)

Aggregations

ArrayList (java.util.ArrayList)1 ServerEnvironment (org.jboss.as.server.ServerEnvironment)1 ProductConfig (org.jboss.as.version.ProductConfig)1