use of com.google.inject.CreationException in project graylog2-server by Graylog2.
the class CmdLineTool method setupInjector.
protected Injector setupInjector(NamedConfigParametersModule configModule, Module... otherModules) {
try {
final ImmutableList.Builder<Module> modules = ImmutableList.builder();
modules.add(configModule);
modules.addAll(getSharedBindingsModules());
modules.addAll(getCommandBindings());
modules.addAll(Arrays.asList(otherModules));
modules.add(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(String.class).annotatedWith(Names.named("BootstrapCommand")).toInstance(commandName);
}
});
return GuiceInjectorHolder.createInjector(modules.build());
} catch (CreationException e) {
annotateInjectorCreationException(e);
return null;
} catch (Exception e) {
LOG.error("Injector creation failed!", e);
return null;
}
}
use of com.google.inject.CreationException in project gerrit by GerritCodeReview.
the class BaseInit method createSiteInit.
private SiteInit createSiteInit() {
final ConsoleUI ui = getConsoleUI();
final Path sitePath = getSitePath();
final List<Module> m = new ArrayList<>();
final SecureStoreInitData secureStoreInitData = discoverSecureStoreClass();
final String currentSecureStoreClassName = getConfiguredSecureStoreClass();
if (secureStoreInitData != null && currentSecureStoreClassName != null && !currentSecureStoreClassName.equals(secureStoreInitData.className)) {
String err = String.format("Different secure store was previously configured: %s. " + "Use SwitchSecureStore program to switch between implementations.", currentSecureStoreClassName);
throw die(err);
}
m.add(new GerritServerConfigModule());
m.add(new InitModule(standalone, initDb));
m.add(new AbstractModule() {
@Override
protected void configure() {
bind(ConsoleUI.class).toInstance(ui);
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
List<String> plugins = MoreObjects.firstNonNull(getInstallPlugins(), new ArrayList<String>());
bind(new TypeLiteral<List<String>>() {
}).annotatedWith(InstallPlugins.class).toInstance(plugins);
bind(new TypeLiteral<Boolean>() {
}).annotatedWith(InstallAllPlugins.class).toInstance(installAllPlugins());
bind(PluginsDistribution.class).toInstance(pluginsDistribution);
String secureStoreClassName;
if (secureStoreInitData != null) {
secureStoreClassName = secureStoreInitData.className;
} else {
secureStoreClassName = currentSecureStoreClassName;
}
if (secureStoreClassName != null) {
ui.message("Using secure store: %s\n", secureStoreClassName);
}
bind(SecureStoreInitData.class).toProvider(Providers.of(secureStoreInitData));
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(secureStoreClassName));
bind(SecureStore.class).toProvider(SecureStoreProvider.class).in(SINGLETON);
bind(new TypeLiteral<List<String>>() {
}).annotatedWith(LibraryDownload.class).toInstance(getSkippedDownloads());
bind(Boolean.class).annotatedWith(LibraryDownload.class).toInstance(skipAllDownloads());
bind(MetricMaker.class).to(DisabledMetricMaker.class);
}
});
try {
return Guice.createInjector(PRODUCTION, m).getInstance(SiteInit.class);
} catch (CreationException ce) {
final Message first = ce.getErrorMessages().iterator().next();
Throwable why = first.getCause();
if (why instanceof Die) {
throw (Die) why;
}
final StringBuilder buf = new StringBuilder(ce.getMessage());
while (why != null) {
buf.append("\n");
buf.append(why.getMessage());
why = why.getCause();
if (why != null) {
buf.append("\n caused by ");
}
}
throw die(buf.toString(), new RuntimeException("InitInjector failed", ce));
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testManyMethods.
public void testManyMethods() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(ManyMethods.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(ManyMethods.class.getName() + " may not declare any new methods, but declared " + Arrays.asList(ManyMethods.class.getDeclaredMethods()), Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testCxtorWithSuperclassExceptionFails.
public void testCxtorWithSuperclassExceptionFails() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(RemoteProvider.class, Foo.class).providing(SuperclassExceptionFoo.class);
}
});
fail();
} catch (CreationException ce) {
assertEquals(IOException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + ", " + BindException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testProviderMethodWithWrongException.
public void testProviderMethodWithWrongException() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
String foo() throws InterruptedException {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
Aggregations