use of com.google.inject.Binder 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.Binder in project xtext-core by eclipse.
the class WrappingInjectorProvider method createInjector.
protected Injector createInjector() {
Injector delegateInjector = delegate.getInjector();
final Map<Key<?>, Binding<?>> bindings = delegateInjector.getBindings();
Injector injector = Guice.createInjector(Modules.override(new Module() {
@Override
public void configure(Binder binder) {
for (Binding<?> binding : bindings.values()) {
Type typeLiteral = binding.getKey().getTypeLiteral().getType();
if (!Injector.class.equals(typeLiteral) && !Logger.class.equals(typeLiteral)) {
binding.applyTo(binder);
}
}
}
}).with(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(IParser.class).toInstance(new TestDataProvider());
}
}));
return injector;
}
use of com.google.inject.Binder in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createBindingMethod.
private StringConcatenationClient createBindingMethod(final GuiceModuleAccess.Binding it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
if (((!it.getValue().isProvider()) && it.getValue().getStatements().isEmpty())) {
_builder.append("// contributed by ");
String _contributedBy = it.getContributedBy();
_builder.append(_contributedBy);
_builder.newLineIfNotEmpty();
{
boolean _isSingleton = it.getKey().isSingleton();
if (_isSingleton) {
_builder.append("@");
_builder.append(SingletonBinding.class);
{
boolean _isEagerSingleton = it.getKey().isEagerSingleton();
if (_isEagerSingleton) {
_builder.append("(eager=true)");
}
}
}
}
_builder.newLineIfNotEmpty();
_builder.append("public ");
{
Object _expression = it.getValue().getExpression();
boolean _tripleEquals = (_expression == null);
if (_tripleEquals) {
_builder.append("Class<? extends ");
TypeReference _type = it.getKey().getType();
_builder.append(_type);
_builder.append(">");
} else {
TypeReference _type_1 = it.getKey().getType();
_builder.append(_type_1);
}
}
_builder.append(" ");
CharSequence _bindMethodName = XtextGeneratorTemplates.this.getBindMethodName(it);
_builder.append(_bindMethodName);
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return ");
{
Object _expression_1 = it.getValue().getExpression();
boolean _tripleNotEquals = (_expression_1 != null);
if (_tripleNotEquals) {
Object _expression_2 = it.getValue().getExpression();
_builder.append(_expression_2, "\t");
} else {
TypeReference _type_2 = it.getValue().getType();
_builder.append(_type_2, "\t");
_builder.append(".class");
}
}
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
} else {
boolean _isEmpty = it.getValue().getStatements().isEmpty();
if (_isEmpty) {
_builder.append("// contributed by ");
String _contributedBy_1 = it.getContributedBy();
_builder.append(_contributedBy_1);
_builder.newLineIfNotEmpty();
{
boolean _isSingleton_1 = it.getKey().isSingleton();
if (_isSingleton_1) {
_builder.append("@");
_builder.append(SingletonBinding.class);
{
boolean _isEagerSingleton_1 = it.getKey().isEagerSingleton();
if (_isEagerSingleton_1) {
_builder.append("(eager=true)");
}
}
}
}
_builder.newLineIfNotEmpty();
_builder.append("public ");
{
Object _expression_3 = it.getValue().getExpression();
boolean _tripleEquals_1 = (_expression_3 == null);
if (_tripleEquals_1) {
_builder.append("Class<? extends ");
_builder.append(Provider.class);
_builder.append("<? extends ");
TypeReference _type_3 = it.getKey().getType();
_builder.append(_type_3);
_builder.append(">>");
} else {
_builder.append(Provider.class);
_builder.append("<? extends ");
TypeReference _type_4 = it.getKey().getType();
_builder.append(_type_4);
_builder.append(">");
}
}
_builder.append(" ");
CharSequence _bindMethodName_1 = XtextGeneratorTemplates.this.getBindMethodName(it);
_builder.append(_bindMethodName_1);
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return ");
{
Object _expression_4 = it.getValue().getExpression();
boolean _tripleNotEquals_1 = (_expression_4 != null);
if (_tripleNotEquals_1) {
Object _expression_5 = it.getValue().getExpression();
_builder.append(_expression_5, "\t");
} else {
TypeReference _type_5 = it.getValue().getType();
_builder.append(_type_5, "\t");
_builder.append(".class");
}
}
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
} else {
_builder.append("// contributed by ");
String _contributedBy_2 = it.getContributedBy();
_builder.append(_contributedBy_2);
_builder.newLineIfNotEmpty();
_builder.append("public void ");
CharSequence _bindMethodName_2 = XtextGeneratorTemplates.this.getBindMethodName(it);
_builder.append(_bindMethodName_2);
_builder.append("(");
_builder.append(Binder.class);
_builder.append(" binder) {");
_builder.newLineIfNotEmpty();
{
List<Object> _statements = it.getValue().getStatements();
for (final Object statement : _statements) {
_builder.append("\t");
_builder.append(statement, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
}
}
}
}
};
return _client;
}
use of com.google.inject.Binder in project xtext-core by eclipse.
the class UriBasedReaderTest method testIssuesInOtherResource.
@Test
public void testIssuesInOtherResource() throws Exception {
UriBasedReader reader = new UriBasedReader() {
{
getValidator().setStopOnError(false);
}
};
reader.setClasspathURIContext(getClass());
reader.addRegister(new XtextStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {
@Override
public void configureFileExtensions(Binder binder) {
binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("xtexterror");
}
});
}
@Override
public void register(Injector injector) {
EPackage.Registry.INSTANCE.put(XtextPackage.eINSTANCE.getNsURI(), XtextPackage.eINSTANCE);
IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", resourceFactory);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", serviceProvider);
}
});
final String errorURI = (getClass().getName() + "ResourceWithError").replace('.', '/') + ".xtexterror";
final String loadingURI = "classpath:/" + (getClass().getName() + "LoadingResourceWithError").replace('.', '/') + ".xtexterror";
reader.addUri(loadingURI);
SlotEntry slotEntry = new SlotEntry();
slotEntry.setType("Grammar");
slotEntry.setFirstOnly(true);
reader.addLoad(slotEntry);
WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
IssuesImpl issues = new IssuesImpl();
reader.checkConfiguration(issues);
assertFalse(issues.toString(), issues.hasErrors());
reader.invoke(ctx, new NullProgressMonitor(), issues);
assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
assertEquals(1, issues.getErrors().length);
final String errorString = issues.getErrors()[0].toString();
assertFalse(errorString, errorString.contains(loadingURI));
assertTrue(errorString, errorString.contains(errorURI));
}
use of com.google.inject.Binder in project druid by druid-io.
the class SpnegoFilterConfigTest method testserde.
@Test
public void testserde() {
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
binder.install(new ConfigModule());
binder.install(new DruidGuiceExtensions());
JsonConfigProvider.bind(binder, "druid.hadoop.security.spnego", SpnegoFilterConfig.class);
}
@Provides
@LazySingleton
public ObjectMapper jsonMapper() {
return new DefaultObjectMapper();
}
});
Properties props = injector.getInstance(Properties.class);
SpnegoFilterConfig config = injector.getInstance(SpnegoFilterConfig.class);
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.principal"), config.getPrincipal());
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.keytab"), config.getKeytab());
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.authToLocal"), config.getAuthToLocal());
}
Aggregations