Allow http and ssh plugins to provide DynamicItem
The plugin guice environment already allows an HttpPlugin or SshPlugin to provide a DynamicSet or DynamicMap, but not a DynamicItem. Add the missing DynamicItem support. We only plan to use this soon for http plugins (to allow replacing the WebSession implementation). Adding it for ssh plugins while at it makes the code more symmetrical. Change-Id: I27c8eb283b1a066f069b28d214788706183dffba
This commit is contained in:
@@ -82,6 +82,8 @@ public class PluginGuiceEnvironment {
|
||||
private Provider<ModuleGenerator> httpGen;
|
||||
|
||||
private Map<TypeLiteral<?>, DynamicItem<?>> sysItems;
|
||||
private Map<TypeLiteral<?>, DynamicItem<?>> sshItems;
|
||||
private Map<TypeLiteral<?>, DynamicItem<?>> httpItems;
|
||||
|
||||
private Map<TypeLiteral<?>, DynamicSet<?>> sysSets;
|
||||
private Map<TypeLiteral<?>, DynamicSet<?>> sshSets;
|
||||
@@ -119,7 +121,9 @@ public class PluginGuiceEnvironment {
|
||||
}
|
||||
|
||||
boolean hasDynamicItem(TypeLiteral<?> type) {
|
||||
return sysItems.containsKey(type);
|
||||
return sysItems.containsKey(type)
|
||||
|| (sshItems != null && sshItems.containsKey(type))
|
||||
|| (httpItems != null && httpItems.containsKey(type));
|
||||
}
|
||||
|
||||
boolean hasDynamicSet(TypeLiteral<?> type) {
|
||||
@@ -154,6 +158,7 @@ public class PluginGuiceEnvironment {
|
||||
public void setSshInjector(Injector injector) {
|
||||
sshModule = copy(injector);
|
||||
sshGen = injector.getProvider(ModuleGenerator.class);
|
||||
sshItems = dynamicItemsOf(injector);
|
||||
sshSets = dynamicSetsOf(injector);
|
||||
sshMaps = dynamicMapsOf(injector);
|
||||
onStart.addAll(listeners(injector, StartPluginListener.class));
|
||||
@@ -175,6 +180,7 @@ public class PluginGuiceEnvironment {
|
||||
public void setHttpInjector(Injector injector) {
|
||||
httpModule = copy(injector);
|
||||
httpGen = injector.getProvider(ModuleGenerator.class);
|
||||
httpItems = dynamicItemsOf(injector);
|
||||
httpSets = dynamicSetsOf(injector);
|
||||
httpMaps = dynamicMapsOf(injector);
|
||||
onStart.addAll(listeners(injector, StartPluginListener.class));
|
||||
@@ -209,6 +215,8 @@ public class PluginGuiceEnvironment {
|
||||
RequestContext oldContext = enter(plugin);
|
||||
try {
|
||||
attachItem(sysItems, plugin.getSysInjector(), plugin);
|
||||
attachItem(sshItems, plugin.getSshInjector(), plugin);
|
||||
attachItem(httpItems, plugin.getHttpInjector(), plugin);
|
||||
|
||||
attachSet(sysSets, plugin.getSysInjector(), plugin);
|
||||
attachSet(sshSets, plugin.getSshInjector(), plugin);
|
||||
@@ -274,6 +282,8 @@ public class PluginGuiceEnvironment {
|
||||
reattachSet(old, httpSets, newPlugin.getHttpInjector(), newPlugin);
|
||||
|
||||
reattachItem(old, sysItems, newPlugin.getSysInjector(), newPlugin);
|
||||
reattachItem(old, sshItems, newPlugin.getSshInjector(), newPlugin);
|
||||
reattachItem(old, httpItems, newPlugin.getHttpInjector(), newPlugin);
|
||||
} finally {
|
||||
exit(oldContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user