Search in sources :

Example 1 with PluginGuiceEnvironment

use of com.google.gerrit.server.plugins.PluginGuiceEnvironment in project gerrit by GerritCodeReview.

the class WebAppInitializer method init.

private synchronized void init() {
    if (manager == null) {
        String path = System.getProperty(GERRIT_SITE_PATH);
        if (path != null) {
            sitePath = Paths.get(path);
        } else {
            throw new ProvisionException(GERRIT_SITE_PATH + " must be defined");
        }
        if (System.getProperty("gerrit.init") != null) {
            List<String> pluginsToInstall;
            String installPlugins = System.getProperty("gerrit.install_plugins");
            if (installPlugins == null) {
                pluginsToInstall = null;
            } else {
                pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(installPlugins);
            }
            new SiteInitializer(path, System.getProperty(GERRIT_SITE_PATH), new UnzippedDistribution(servletContext), pluginsToInstall).init();
        }
        try {
            cfgInjector = createCfgInjector();
        } catch (CreationException ce) {
            final Message first = ce.getErrorMessages().iterator().next();
            final StringBuilder buf = new StringBuilder();
            buf.append(first.getMessage());
            Throwable why = first.getCause();
            while (why != null) {
                buf.append("\n  caused by ");
                buf.append(why.toString());
                why = why.getCause();
            }
            if (first.getCause() != null) {
                buf.append("\n");
                buf.append("\nResolve above errors before continuing.");
                buf.append("\nComplete stack trace follows:");
            }
            logger.atSevere().withCause(first.getCause()).log(buf.toString());
            throw new CreationException(Collections.singleton(first));
        }
        dbInjector = createDbInjector();
        initIndexType();
        config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
        sysInjector = createSysInjector();
        if (!sshdOff()) {
            sshInjector = createSshInjector();
        }
        webInjector = createWebInjector();
        PluginGuiceEnvironment env = sysInjector.getInstance(PluginGuiceEnvironment.class);
        env.setDbCfgInjector(dbInjector, cfgInjector);
        if (sshInjector != null) {
            env.setSshInjector(sshInjector);
        }
        env.setHttpInjector(webInjector);
        // Push the Provider<HttpServletRequest> down into the canonical
        // URL provider. Its optional for that provider, but since we can
        // supply one we should do so, in case the administrator has not
        // setup the canonical URL in the configuration file.
        // 
        // Note we have to do this manually as Guice failed to do the
        // injection here because the HTTP environment is not visible
        // to the core server modules.
        // 
        sysInjector.getInstance(HttpCanonicalWebUrlProvider.class).setHttpServletRequest(webInjector.getProvider(HttpServletRequest.class));
        filter = webInjector.getInstance(GuiceFilter.class);
        manager = new LifecycleManager();
        manager.add(dbInjector);
        manager.add(cfgInjector);
        manager.add(sysInjector);
        if (sshInjector != null) {
            manager.add(sshInjector);
        }
        manager.add(webInjector);
    }
}
Also used : PluginGuiceEnvironment(com.google.gerrit.server.plugins.PluginGuiceEnvironment) Message(com.google.inject.spi.Message) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) CreationException(com.google.inject.CreationException) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpCanonicalWebUrlProvider(com.google.gerrit.httpd.HttpCanonicalWebUrlProvider) ProvisionException(com.google.inject.ProvisionException) GuiceFilter(com.google.inject.servlet.GuiceFilter)

Example 2 with PluginGuiceEnvironment

use of com.google.gerrit.server.plugins.PluginGuiceEnvironment in project gerrit by GerritCodeReview.

the class WebAppInitializer method init.

private synchronized void init() {
    if (manager == null) {
        final String path = System.getProperty("gerrit.site_path");
        if (path != null) {
            sitePath = Paths.get(path);
        }
        if (System.getProperty("gerrit.init") != null) {
            List<String> pluginsToInstall;
            String installPlugins = System.getProperty("gerrit.install_plugins");
            if (installPlugins == null) {
                pluginsToInstall = null;
            } else {
                pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(installPlugins);
            }
            new SiteInitializer(path, System.getProperty("gerrit.init_path"), new UnzippedDistribution(servletContext), pluginsToInstall).init();
        }
        try {
            dbInjector = createDbInjector();
        } catch (CreationException ce) {
            final Message first = ce.getErrorMessages().iterator().next();
            final StringBuilder buf = new StringBuilder();
            buf.append(first.getMessage());
            Throwable why = first.getCause();
            while (why != null) {
                buf.append("\n  caused by ");
                buf.append(why.toString());
                why = why.getCause();
            }
            if (first.getCause() != null) {
                buf.append("\n");
                buf.append("\nResolve above errors before continuing.");
                buf.append("\nComplete stack trace follows:");
            }
            log.error(buf.toString(), first.getCause());
            throw new CreationException(Collections.singleton(first));
        }
        cfgInjector = createCfgInjector();
        initIndexType();
        config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
        sysInjector = createSysInjector();
        if (!sshdOff()) {
            sshInjector = createSshInjector();
        }
        webInjector = createWebInjector();
        PluginGuiceEnvironment env = sysInjector.getInstance(PluginGuiceEnvironment.class);
        env.setDbCfgInjector(dbInjector, cfgInjector);
        if (sshInjector != null) {
            env.setSshInjector(sshInjector);
        }
        env.setHttpInjector(webInjector);
        // Push the Provider<HttpServletRequest> down into the canonical
        // URL provider. Its optional for that provider, but since we can
        // supply one we should do so, in case the administrator has not
        // setup the canonical URL in the configuration file.
        //
        // Note we have to do this manually as Guice failed to do the
        // injection here because the HTTP environment is not visible
        // to the core server modules.
        //
        sysInjector.getInstance(HttpCanonicalWebUrlProvider.class).setHttpServletRequest(webInjector.getProvider(HttpServletRequest.class));
        filter = webInjector.getInstance(GuiceFilter.class);
        manager = new LifecycleManager();
        manager.add(dbInjector);
        manager.add(cfgInjector);
        manager.add(sysInjector);
        if (sshInjector != null) {
            manager.add(sshInjector);
        }
        manager.add(webInjector);
    }
}
Also used : PluginGuiceEnvironment(com.google.gerrit.server.plugins.PluginGuiceEnvironment) Message(com.google.inject.spi.Message) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) CreationException(com.google.inject.CreationException) HttpServletRequest(javax.servlet.http.HttpServletRequest) GuiceFilter(com.google.inject.servlet.GuiceFilter)

Aggregations

LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)2 PluginGuiceEnvironment (com.google.gerrit.server.plugins.PluginGuiceEnvironment)2 CreationException (com.google.inject.CreationException)2 GuiceFilter (com.google.inject.servlet.GuiceFilter)2 Message (com.google.inject.spi.Message)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpCanonicalWebUrlProvider (com.google.gerrit.httpd.HttpCanonicalWebUrlProvider)1 ProvisionException (com.google.inject.ProvisionException)1