Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HUDSON-8817: SmoothiePluginStrategy should also query custom Extensio…

…nFinders
  • Loading branch information...
commit 80084981c1c2d6c4bf1c98825d899dc37c9cfc10 1 parent a71a58a
@mcculls authored
View
71 ...on-inject/src/main/java/org/hudsonci/inject/internal/extension/SezPozExtensionModule.java
@@ -21,6 +21,7 @@
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import hudson.Extension;
+import hudson.ExtensionFinder.Sezpoz;
import hudson.ExtensionPoint;
import hudson.model.Descriptor;
import net.java.sezpoz.SpaceIndex;
@@ -74,36 +75,10 @@ public void configure( final Binder binder )
{
try
{
- switch ( item.kind() )
+ // ignore the legacy SezPoz ExtensionFinder
+ if ( !Sezpoz.class.equals( item.element() ) )
{
- case TYPE:
- {
- final Class impl = (Class) item.element();
- binder.bind( impl ).in( Scopes.SINGLETON );
- bindHierarchy( binder, Key.get( impl ) );
-
- break;
- }
- case METHOD:
- {
- final Method method = (Method) item.element();
- final Named name = Names.named( method.getDeclaringClass().getName() + '.' + method.getName() );
- final Key key = Key.get( method.getReturnType(), name );
- bindProvider(binder, item, key);
-
- break;
- }
- case FIELD:
- {
- final Field field = (Field) item.element();
- final Named name = Names.named( field.getDeclaringClass().getName() + '.' + field.getName() );
- final Key key = Key.get( field.getType(), name );
- bindProvider(binder, item, key);
-
- break;
- }
- default:
- break;
+ bindItem( binder, item );
}
}
catch ( final Throwable e )
@@ -117,6 +92,44 @@ public void configure( final Binder binder )
}
}
+ // ----------------------------------------------------------------------
+ // Implementation methods
+ // ----------------------------------------------------------------------
+
+ private void bindItem( final Binder binder, final SpaceIndexItem<?, ?> item )
+ throws InstantiationException
+ {
+ switch ( item.kind() )
+ {
+ case TYPE:
+ {
+ final Class impl = (Class) item.element();
+ binder.bind( impl ).in( Scopes.SINGLETON );
+ bindHierarchy( binder, Key.get( impl ) );
+
+ break;
+ }
+ case METHOD:
+ {
+ final Method method = (Method) item.element();
+ final Named name = Names.named( method.getDeclaringClass().getName() + '.' + method.getName() );
+ bindProvider(binder, item, Key.get( method.getReturnType(), name ));
+
+ break;
+ }
+ case FIELD:
+ {
+ final Field field = (Field) item.element();
+ final Named name = Names.named( field.getDeclaringClass().getName() + '.' + field.getName() );
+ bindProvider(binder, item, Key.get( field.getType(), name ));
+
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
private void bindProvider(final Binder binder, final SpaceIndexItem item, final Key key) {
binder.bind(key).toProvider(new Provider() {
public Object get() {
View
28 hudson-inject/src/main/java/org/hudsonci/inject/internal/plugin/SmoothiePluginStrategy.java
@@ -28,6 +28,7 @@
import org.hudsonci.inject.internal.extension.ExtensionLocator;
import hudson.ExtensionComponent;
+import hudson.ExtensionFinder;
import hudson.Plugin;
import hudson.PluginStrategy;
import hudson.PluginWrapper;
@@ -66,12 +67,18 @@
private final PluginWrapperFactory pluginFactory;
private final ExtensionLocator extensionLocator;
+
+ private final List<ExtensionFinder> extensionFinders;
@Inject
- public SmoothiePluginStrategy(final SmoothieContainer container, final PluginWrapperFactory pluginFactory, final @Named("default") ExtensionLocator extensionLocator) {
+ public SmoothiePluginStrategy(final SmoothieContainer container,
+ final PluginWrapperFactory pluginFactory,
+ final @Named("default") ExtensionLocator extensionLocator,
+ final List<ExtensionFinder> extensionFinders) {
this.container = checkNotNull(container);
this.pluginFactory = checkNotNull(pluginFactory);
this.extensionLocator = checkNotNull(extensionLocator);
+ this.extensionFinders = checkNotNull(extensionFinders);
}
private String basename(String name) {
@@ -233,6 +240,23 @@ public void initializeComponents(final PluginWrapper plugin) {
}
public <T> List<ExtensionComponent<T>> findComponents(final Class<T> type, final Hudson hudson) {
- return extensionLocator.locate(type);
+ List<ExtensionComponent<T>> components = extensionLocator.locate(type);
+
+ for (ExtensionFinder finder : extensionFinders) {
+ try {
+ try {
+ components.addAll(finder._find(type, hudson));
+ } catch (AbstractMethodError e) {
+ // support legacy finders that only have the old method
+ for (T instance : finder.findExtensions(type, hudson)) {
+ components.add(new ExtensionComponent<T>(instance));
+ }
+ }
+ } catch (Throwable e) {
+ log.warn("Failed to query ExtensionFinder: "+finder, e);
+ }
+ }
+
+ return components;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.