Package hudson

Class ExtensionList<T>

Type Parameters:
T - Type of the extension point. This class holds instances of the subtypes of 'T'.
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, OnMaster
Direct Known Subclasses:
DescriptorExtensionList

public class ExtensionList<T> extends AbstractList<T> implements OnMaster
Retains the known extension instances for the given type 'T'.

Extensions are loaded lazily on demand and automatically by using ExtensionFinder, but this class also provides a mechanism to provide compatibility with the older DescriptorList-based manual registration,

All ExtensionList instances should be owned by Jenkins, even though extension points can be defined by anyone on any type. Use Jenkins.getExtensionList(Class) and Jenkins.getDescriptorList(Class) to obtain the instances.

Since:
1.286
Author:
Kohsuke Kawaguchi
See Also:
  • Field Details

    • hudson

      @Deprecated public final Hudson hudson
      Deprecated.
      as of 1.417 Use jenkins
    • jenkins

      @CheckForNull public final Jenkins jenkins
    • extensionType

      public final Class<T> extensionType
  • Constructor Details

  • Method Details

    • addListener

      public void addListener(@NonNull ExtensionListListener listener)
      Add a listener to the extension list.
      Parameters:
      listener - The listener.
    • get

      @CheckForNull public <U extends T> U get(@NonNull Class<U> type)
      Looks for the extension instance of the given type (subclasses excluded), or return null.
    • getInstance

      @NonNull public <U extends T> U getInstance(@NonNull Class<U> type) throws IllegalStateException
      Looks for the extension instance of the given type (subclasses excluded), or throws an IllegalStateException. Meant to simplify call inside @Extension annotated class to retrieve their own instance.
      Throws:
      IllegalStateException
    • iterator

      @NonNull public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class AbstractList<T>
    • getComponents

      public List<ExtensionComponent<T>> getComponents()
      Gets the same thing as the 'this' list represents, except as ExtensionComponents.
    • get

      public T get(int index)
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
    • reverseView

      public List<T> reverseView()
      Gets the read-only view of this ExtensionList where components are reversed.
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractCollection<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface List<T>
      Overrides:
      removeAll in class AbstractCollection<T>
    • remove

      public final T remove(int index)
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractList<T>
    • add

      @Deprecated public boolean add(T t)
      Deprecated.
      since 2009-02-23. Prefer automatic registration.
      Write access will put the instance into a legacy store.
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
    • add

      public void add(int index, T element)
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
    • getDynamic

      public T getDynamic(String className)
      Used to bind extension to URLs by their class names.
      Since:
      1.349
    • getLoadLock

      protected Object getLoadLock()
      Chooses the object that locks the loading of the extension instances.
    • refresh

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean refresh(ExtensionComponentSet delta)
      Used during Jenkins.refreshExtensions() to add new components into existing ExtensionLists. Do not call from anywhere else.
      Returns:
      true if fireOnChangeListeners() should be called on this after all lists have been refreshed.
    • fireOnChangeListeners

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void fireOnChangeListeners()
    • load

      protected List<ExtensionComponent<T>> load()
      Loads all the extensions.
    • load

      Picks up extensions that we care from the given list.
    • sort

      If the ExtensionList implementation requires sorting extensions, override this method to do so.

      The implementation should copy a list, do a sort, and return the new instance.

    • create

      @Deprecated public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type)
      Deprecated.
      as of 1.416 Use create(Jenkins, Class)
    • create

      public static <T> ExtensionList<T> create(Jenkins jenkins, Class<T> type)
    • lookup

      @NonNull public static <T> ExtensionList<T> lookup(Class<T> type)
      Gets the extension list for a given type. Normally calls Jenkins.getExtensionList(Class) but falls back to an empty list in case Jenkins.getInstanceOrNull() is null. Thus it is useful to call from all() methods which need to behave gracefully during startup or shutdown.
      Parameters:
      type - the extension point type
      Returns:
      some list
      Since:
      1.572
    • lookupSingleton

      @NonNull public static <U> U lookupSingleton(Class<U> type)
      Convenience method allowing lookup of the only instance of a given type. Equivalent to ExtensionList.lookup(Class).get(Class) if there is one instance, and throws an IllegalStateException otherwise.
      Parameters:
      type - The type to look up.
      Returns:
      the singleton instance of the given type in its list.
      Throws:
      IllegalStateException - if there are no instances, or more than one
      Since:
      2.87
    • lookupFirst

      @NonNull public static <U> U lookupFirst(Class<U> type)
      Convenience method allowing lookup of the instance of a given type with the highest ordinal. Equivalent to ExtensionList.lookup(type).get(0) if there is at least one instance, and throws an IllegalStateException otherwise if no instance could be found.
      Parameters:
      type - The type to look up.
      Returns:
      the singleton instance of the given type in its list.
      Throws:
      IllegalStateException - if there are no instances
      Since:
      2.435
    • clearLegacyInstances

      public static void clearLegacyInstances()
      Exposed for the test harness to clear all legacy extension instances.