Search in sources :

Example 26 with Message

use of com.google.inject.spi.Message in project airlift by airlift.

the class Problems method addError.

public void addError(String format, Object... params) {
    Message message = new Message(format(format, params));
    errors.add(message);
    monitor.onError(message);
}
Also used : Message(com.google.inject.spi.Message)

Example 27 with Message

use of com.google.inject.spi.Message in project airlift by airlift.

the class Problems method addError.

public void addError(Throwable e, String format, Object... params) {
    Message message = new Message(emptyList(), format(format, params), e);
    errors.add(message);
    monitor.onError(message);
}
Also used : Message(com.google.inject.spi.Message)

Example 28 with Message

use of com.google.inject.spi.Message in project guice by google.

the class Errors method addMessage.

private Errors addMessage(Throwable cause, String messageFormat, Object... arguments) {
    String message = format(messageFormat, arguments);
    addMessage(new Message(getSources(), message, cause));
    return this;
}
Also used : Message(com.google.inject.spi.Message)

Example 29 with Message

use of com.google.inject.spi.Message 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)

Example 30 with Message

use of com.google.inject.spi.Message in project gerrit by GerritCodeReview.

the class SiteProgram method createDbInjector.

/** @return provides database connectivity and site path. */
protected Injector createDbInjector(final boolean enableMetrics, final DataSourceProvider.Context context) {
    final Path sitePath = getSitePath();
    final List<Module> modules = new ArrayList<>();
    Module sitePathModule = new AbstractModule() {

        @Override
        protected void configure() {
            bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
            bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
        }
    };
    modules.add(sitePathModule);
    if (enableMetrics) {
        modules.add(new DropWizardMetricMaker.ApiModule());
    } else {
        modules.add(new AbstractModule() {

            @Override
            protected void configure() {
                bind(MetricMaker.class).to(DisabledMetricMaker.class);
            }
        });
    }
    modules.add(new LifecycleModule() {

        @Override
        protected void configure() {
            bind(DataSourceProvider.Context.class).toInstance(context);
            if (dsProvider != null) {
                bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(dsProvider).in(SINGLETON);
                if (LifecycleListener.class.isAssignableFrom(dsProvider.getClass())) {
                    listener().toInstance((LifecycleListener) dsProvider);
                }
            } else {
                bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(SiteLibraryBasedDataSourceProvider.class).in(SINGLETON);
                listener().to(SiteLibraryBasedDataSourceProvider.class);
            }
        }
    });
    Module configModule = new GerritServerConfigModule();
    modules.add(configModule);
    Injector cfgInjector = Guice.createInjector(sitePathModule, configModule);
    Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
    String dbType;
    if (dsProvider != null) {
        dbType = getDbType(dsProvider);
    } else {
        dbType = cfg.getString("database", null, "type");
    }
    if (dbType == null) {
        throw new ProvisionException("database.type must be defined");
    }
    final DataSourceType dst = Guice.createInjector(new DataSourceModule(), configModule, sitePathModule).getInstance(Key.get(DataSourceType.class, Names.named(dbType.toLowerCase())));
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(DataSourceType.class).toInstance(dst);
        }
    });
    modules.add(new DatabaseModule());
    modules.add(new SchemaModule());
    modules.add(cfgInjector.getInstance(GitRepositoryManagerModule.class));
    modules.add(new ConfigNotesMigration.Module());
    modules.addAll(LibModuleLoader.loadModules(cfgInjector));
    try {
        return Guice.createInjector(PRODUCTION, modules);
    } catch (CreationException ce) {
        final Message first = ce.getErrorMessages().iterator().next();
        Throwable why = first.getCause();
        if (why instanceof SQLException) {
            throw die("Cannot connect to SQL database", why);
        }
        if (why instanceof OrmException && why.getCause() != null && "Unable to determine driver URL".equals(why.getMessage())) {
            why = why.getCause();
            if (isCannotCreatePoolException(why)) {
                throw die("Cannot connect to SQL database", why.getCause());
            }
            throw die("Cannot connect to SQL database", why);
        }
        final StringBuilder buf = new StringBuilder();
        if (why != null) {
            buf.append(why.getMessage());
            why = why.getCause();
        } else {
            buf.append(first.getMessage());
        }
        while (why != null) {
            buf.append("\n  caused by ");
            buf.append(why.toString());
            why = why.getCause();
        }
        throw die(buf.toString(), new RuntimeException("DbInjector failed", ce));
    }
}
Also used : Message(com.google.inject.spi.Message) SQLException(java.sql.SQLException) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GerritServerConfigModule.getSecureStoreClassName(com.google.gerrit.server.config.GerritServerConfigModule.getSecureStoreClassName) SecureStoreClassName(com.google.gerrit.server.securestore.SecureStoreClassName) ArrayList(java.util.ArrayList) DatabaseModule(com.google.gerrit.server.schema.DatabaseModule) LifecycleListener(com.google.gerrit.extensions.events.LifecycleListener) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) ProvisionException(com.google.inject.ProvisionException) OrmException(com.google.gwtorm.server.OrmException) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) DropWizardMetricMaker(com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SchemaModule(com.google.gerrit.server.schema.SchemaModule) DataSourceProvider(com.google.gerrit.server.schema.DataSourceProvider) CreationException(com.google.inject.CreationException) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AbstractModule(com.google.inject.AbstractModule) ConfigNotesMigration(com.google.gerrit.server.notedb.ConfigNotesMigration) SitePath(com.google.gerrit.server.config.SitePath) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) Module(com.google.inject.Module) DataSourceModule(com.google.gerrit.server.schema.DataSourceModule) DatabaseModule(com.google.gerrit.server.schema.DatabaseModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) AbstractModule(com.google.inject.AbstractModule) DataSourceModule(com.google.gerrit.server.schema.DataSourceModule)

Aggregations

Message (com.google.inject.spi.Message)49 ProvisionException (com.google.inject.ProvisionException)9 CreationException (com.google.inject.CreationException)7 ArrayList (java.util.ArrayList)7 AbstractModule (com.google.inject.AbstractModule)6 Provider (com.google.inject.Provider)5 TypeLiteral (com.google.inject.TypeLiteral)5 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 Errors (com.google.inject.internal.Errors)4 InjectionPoint (com.google.inject.spi.InjectionPoint)4 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)3 GerritServerConfigModule (com.google.gerrit.server.config.GerritServerConfigModule)3 SitePath (com.google.gerrit.server.config.SitePath)3 Test (org.junit.Test)3 JacksonInject (com.fasterxml.jackson.annotation.JacksonInject)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 AnnotatedField (com.fasterxml.jackson.databind.introspect.AnnotatedField)2 Function (com.google.common.base.Function)2 ImmutableList (com.google.common.collect.ImmutableList)2