Search in sources :

Example 1 with NullInputStream

use of org.jboss.stdio.NullInputStream in project wildfly by wildfly.

the class Main method main.

/**
     * The main method.
     *
     * @param args the command-line arguments
     */
public static void main(String[] args) {
    if (java.util.logging.LogManager.getLogManager().getClass().getName().equals("org.jboss.logmanager.LogManager")) {
        // Make sure our original stdio is properly captured.
        try {
            Class.forName(org.jboss.logmanager.handlers.ConsoleHandler.class.getName(), true, org.jboss.logmanager.handlers.ConsoleHandler.class.getClassLoader());
        } catch (Throwable ignored) {
        }
        // Install JBoss Stdio to avoid any nasty crosstalk, after command line arguments are processed.
        StdioContext.install();
        final StdioContext context = StdioContext.create(new NullInputStream(), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stdout"), org.jboss.logmanager.Level.INFO), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stderr"), org.jboss.logmanager.Level.ERROR));
        StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));
    }
    try {
        Module.registerURLStreamHandlerFactoryModule(Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.vfs")));
        final ParsedOptions options = determineEnvironment(args, new Properties(WildFlySecurityManager.getSystemPropertiesPrivileged()), WildFlySecurityManager.getSystemEnvironmentPrivileged(), ServerEnvironment.LaunchType.APPCLIENT);
        if (options == null) {
            //this happens if --version was specified
            return;
        }
        ServerEnvironment serverEnvironment = options.environment;
        final List<String> clientArgs = options.clientArguments;
        if (clientArgs.isEmpty()) {
            STDERR.println(AppClientLogger.ROOT_LOGGER.appClientNotSpecified());
            usage();
            abort(null);
        } else {
            final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server");
            final String file = clientArgs.get(0);
            final List<String> params = clientArgs.subList(1, clientArgs.size());
            final String deploymentName;
            final String earPath;
            int pos = file.lastIndexOf("#");
            if (pos == -1) {
                earPath = file;
                deploymentName = null;
            } else {
                deploymentName = file.substring(pos + 1);
                earPath = file.substring(0, pos);
            }
            File realFile = new File(earPath);
            if (!realFile.exists()) {
                throw AppClientLogger.ROOT_LOGGER.cannotFindAppClientFile(realFile.getAbsoluteFile());
            }
            final Bootstrap bootstrap = Bootstrap.Factory.newInstance();
            final Bootstrap.Configuration configuration = new Bootstrap.Configuration(serverEnvironment);
            configuration.setModuleLoader(Module.getBootModuleLoader());
            final ExtensionRegistry extensionRegistry = configuration.getExtensionRegistry();
            final AppClientXml parser = new AppClientXml(Module.getBootModuleLoader(), extensionRegistry);
            final Bootstrap.ConfigurationPersisterFactory configurationPersisterFactory = new Bootstrap.ConfigurationPersisterFactory() {

                @Override
                public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
                    ApplicationClientConfigurationPersister persister = new ApplicationClientConfigurationPersister(earPath, deploymentName, options.hostUrl, options.propertiesFile, params, serverEnvironment.getServerConfigurationFile().getBootFile(), rootElement, parser);
                    for (Namespace namespace : Namespace.domainValues()) {
                        if (!namespace.equals(Namespace.CURRENT)) {
                            persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "server"), parser);
                        }
                    }
                    extensionRegistry.setWriterRegistry(persister);
                    return persister;
                }
            };
            configuration.setConfigurationPersisterFactory(configurationPersisterFactory);
            bootstrap.bootstrap(configuration, Collections.<ServiceActivator>emptyList()).get();
        }
    } catch (Throwable t) {
        abort(t);
    }
}
Also used : StdioContext(org.jboss.stdio.StdioContext) Properties(java.util.Properties) ExtensionRegistry(org.jboss.as.controller.extension.ExtensionRegistry) ServerEnvironment(org.jboss.as.server.ServerEnvironment) Bootstrap(org.jboss.as.server.Bootstrap) NullInputStream(org.jboss.stdio.NullInputStream) QName(javax.xml.namespace.QName) LoggingOutputStream(org.jboss.stdio.LoggingOutputStream) ServiceActivator(org.jboss.msc.service.ServiceActivator) Namespace(org.jboss.as.controller.parsing.Namespace) SimpleStdioContextSelector(org.jboss.stdio.SimpleStdioContextSelector) AppClientXml(org.jboss.as.appclient.subsystem.parsing.AppClientXml) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File)

Aggregations

File (java.io.File)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 QName (javax.xml.namespace.QName)1 AppClientXml (org.jboss.as.appclient.subsystem.parsing.AppClientXml)1 ExtensionRegistry (org.jboss.as.controller.extension.ExtensionRegistry)1 Namespace (org.jboss.as.controller.parsing.Namespace)1 Bootstrap (org.jboss.as.server.Bootstrap)1 ServerEnvironment (org.jboss.as.server.ServerEnvironment)1 ServiceActivator (org.jboss.msc.service.ServiceActivator)1 LoggingOutputStream (org.jboss.stdio.LoggingOutputStream)1 NullInputStream (org.jboss.stdio.NullInputStream)1 SimpleStdioContextSelector (org.jboss.stdio.SimpleStdioContextSelector)1 StdioContext (org.jboss.stdio.StdioContext)1