Search in sources :

Example 1 with AbstractModule

use of com.google.inject.AbstractModule in project whirr by apache.

the class ComputeServiceContextBuilder method build.

public static ComputeServiceContext build(ClusterSpec spec) throws IOException {
    Set<AbstractModule> wiring = ImmutableSet.of(new JschSshClientModule(), new Log4JLoggingModule());
    ComputeServiceContext context = new ComputeServiceContextFactory().createContext(spec.getProvider(), spec.getIdentity(), spec.getCredential(), wiring);
    return context;
}
Also used : Log4JLoggingModule(org.jclouds.logging.log4j.config.Log4JLoggingModule) JschSshClientModule(org.jclouds.ssh.jsch.config.JschSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ComputeServiceContextFactory(org.jclouds.compute.ComputeServiceContextFactory) AbstractModule(com.google.inject.AbstractModule)

Example 2 with AbstractModule

use of com.google.inject.AbstractModule in project che by eclipse.

the class SubversionProjectImporterTest method setUp.

@Before
public void setUp() throws Exception {
    // Bind components
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            Multibinder.newSetBinder(binder(), ProjectImporter.class).addBinding().to(SubversionProjectImporter.class);
            Multibinder.newSetBinder(binder(), ProjectTypeDef.class).addBinding().to(SubversionProjectType.class);
            Multibinder.newSetBinder(binder(), ValueProviderFactory.class).addBinding().to(SubversionValueProviderFactory.class);
            bind(SshKeyProvider.class).toInstance(sshKeyProvider);
            bind(ProfileDao.class).toInstance(userProfileDao);
            bind(RepositoryUrlProvider.class).toInstance(repositoryUrlProvider);
        }
    });
    // Init virtual file system
    VirtualFileSystem virtualFileSystem = TestUtils.createVirtualFileSystem();
    root = virtualFileSystem.getRoot();
    // Create the test user
    TestUtils.createTestUser(userProfileDao);
    // Create the Subversion repository
    repoRoot = TestUtils.createGreekTreeRepository();
    projectImporter = injector.getInstance(SubversionProjectImporter.class);
}
Also used : VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) Injector(com.google.inject.Injector) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) AbstractModule(com.google.inject.AbstractModule) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) Before(org.junit.Before)

Example 3 with AbstractModule

use of com.google.inject.AbstractModule in project gerrit by GerritCodeReview.

the class SiteProgram method getDbType.

private String getDbType(Provider<DataSource> dsProvider) {
    String dbProductName;
    try (Connection conn = dsProvider.get().getConnection()) {
        dbProductName = conn.getMetaData().getDatabaseProductName().toLowerCase();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    List<Module> modules = new ArrayList<>();
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
        }
    });
    modules.add(new GerritServerConfigModule());
    modules.add(new DataSourceModule());
    Injector i = Guice.createInjector(modules);
    List<Binding<DataSourceType>> dsTypeBindings = i.findBindingsByType(new TypeLiteral<DataSourceType>() {
    });
    for (Binding<DataSourceType> binding : dsTypeBindings) {
        Annotation annotation = binding.getKey().getAnnotation();
        if (annotation instanceof Named) {
            if (((Named) annotation).value().toLowerCase().contains(dbProductName)) {
                return ((Named) annotation).value();
            }
        }
    }
    throw new IllegalStateException(String.format("Cannot guess database type from the database product name '%s'", dbProductName));
}
Also used : Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) Binding(com.google.inject.Binding) Named(com.google.inject.name.Named) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) AbstractModule(com.google.inject.AbstractModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) 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)

Example 4 with AbstractModule

use of com.google.inject.AbstractModule in project guice by google.

the class ModuleAnnotatedMethodScannerTest method testWithSource.

public void testWithSource() throws Exception {
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            binder().withSource("source").install(new AbstractModule() {

                @Override
                protected void configure() {
                }

                @TestProvides
                @Named("foo")
                String foo() {
                    return "foo";
                }
            });
        }
    };
    Injector injector = Guice.createInjector(module, NamedMunger.module());
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) Module(com.google.inject.Module) PrivateModule(com.google.inject.PrivateModule) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule)

Example 5 with AbstractModule

use of com.google.inject.AbstractModule in project guice by google.

the class ModuleAnnotatedMethodScannerTest method testPrivateModule_skipSourcesForPrivateModule.

public void testPrivateModule_skipSourcesForPrivateModule() {
    Injector injector = Guice.createInjector(NamedMunger.module(), new AbstractModule() {

        @Override
        protected void configure() {
            binder().skipSources(getClass()).install(new PrivateModule() {

                @Override
                protected void configure() {
                }

                @Exposed
                @TestProvides
                @Named("foo")
                String foo() {
                    return "foo";
                }
            });
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule) AbstractModule(com.google.inject.AbstractModule)

Aggregations

AbstractModule (com.google.inject.AbstractModule)1027 Injector (com.google.inject.Injector)615 Module (com.google.inject.Module)285 CreationException (com.google.inject.CreationException)175 Test (org.junit.Test)162 Provider (com.google.inject.Provider)66 Key (com.google.inject.Key)64 ConfigModule (co.cask.cdap.common.guice.ConfigModule)62 PrivateModule (com.google.inject.PrivateModule)59 Before (org.junit.Before)59 TypeLiteral (com.google.inject.TypeLiteral)56 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)52 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)48 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)48 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)47 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)45 CConfiguration (co.cask.cdap.common.conf.CConfiguration)43 Map (java.util.Map)42 BeforeClass (org.junit.BeforeClass)41 DefaultOwnerAdmin (co.cask.cdap.security.impersonation.DefaultOwnerAdmin)37