Skip to content

Commit

Permalink
Introduce StashNotifierDefault annotation
Browse files Browse the repository at this point in the history
Simplifies HttpNotifierSelector implementations by allowing authors to
easily inject the plugin's default to fall back to.
  • Loading branch information
sghill committed Oct 25, 2021
1 parent 7ad59f8 commit fa3ca08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jenkinsci.plugins.stashNotifier;

import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Use this annotation to inject the default value of
* {@link HttpNotifierSelector} or {@link HttpNotifier}.
*/
@Qualifier
@Target({ FIELD, PARAMETER, METHOD })
@Retention(RUNTIME)
public @interface StashNotifierDefault {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ protected void configure() {

@Provides
@Singleton
@Named("fallback")
HttpNotifierSelector providesDefaultApacheHttpNotifierSelector() {
return new DefaultHttpNotifierSelector(new DefaultApacheHttpNotifier());
@StashNotifierDefault
HttpNotifier providesDefaultHttpNotifier() {
return new DefaultApacheHttpNotifier();
}

@Provides
@Singleton
@StashNotifierDefault
HttpNotifierSelector providesDefaultApacheHttpNotifierSelector(@StashNotifierDefault HttpNotifier httpNotifier) {
return new DefaultHttpNotifierSelector(httpNotifier);
}

@Provides
Expand All @@ -33,7 +40,7 @@ List<HttpNotifierSelector> providesHttpNotifierSelectors() {

@Provides
@Singleton
HttpNotifierSelector providesHttpNotifierSelector(@Named("fallback") HttpNotifierSelector fallback,
HttpNotifierSelector providesHttpNotifierSelector(@StashNotifierDefault HttpNotifierSelector fallback,
@Named("preferredHttpNotifierSelector") String preferredHttpNotifierSelector,
List<HttpNotifierSelector> httpNotifierSelectors) {
HttpNotifierSelector selector = httpNotifierSelectors.stream()
Expand Down

0 comments on commit fa3ca08

Please sign in to comment.