autoScanModules = Boolean.parseBoolean(properties.get("errai.auto_scan_modules"));
}
if (autoScanModules) {
// Search for Errai extensions.
visitAllTargets(configRootTargets, new ConfigVisitor() {
public void visit(Class<?> loadClass) {
if (ErraiConfigExtension.class.isAssignableFrom(loadClass)
&& loadClass.isAnnotationPresent(ExtensionComponent.class) && !loadedComponents.contains(loadClass.getName())) {
loadedComponents.add(loadClass.getName());
// We have an annotated ErraiConfigExtension. So let's configure it.
final Class<? extends ErraiConfigExtension> clazz =
loadClass.asSubclass(ErraiConfigExtension.class);
log.info("found extension " + clazz.getName());
try {
final Runnable create = new Runnable() {
public void run() {
AbstractModule module = new AbstractModule() {
@Override
protected void configure() {
bind(ErraiConfigExtension.class).to(clazz);
bind(ErraiServiceConfigurator.class).toInstance(configInst);
bind(MessageBus.class).toInstance(bus);
// Add any extension bindings.
for (Map.Entry<Class, Provider> entry : extensionBindings.entrySet()) {
bind(entry.getKey()).toProvider(entry.getValue());
}
}
};
Guice.createInjector(module)
.getInstance(ErraiConfigExtension.class)
.configure(extensionBindings, resourceProviders);
}
};
try {
create.run();
}
catch (CreationException e) {
log.info("extension " + clazz.getName() + " cannot be bound yet, deferring ...");
deferred.add(create);
}
}
catch (Throwable e) {
throw new ErraiBootstrapFailure("could not initialize extension: " + loadClass.getName(), e);
}
}
}
});
for (Class bindingType : extensionBindings.keySet()) {
log.info("added extension binding: " + bindingType.getName());
}
log.info("total extension binding: " + extensionBindings.keySet().size());
visitAllTargets(configRootTargets,
new ConfigVisitor() {
public void visit(final Class<?> loadClass) {
if (loadedComponents.contains(loadClass.getName())) return;
if (Module.class.isAssignableFrom(loadClass)) {