Package jetbrains.buildServer
Interface ExtensionsProvider
-
- All Known Subinterfaces:
BuildServerEx
,ExtensionHolder
,SBuildServer
,ServerExtensionHolder
- All Known Implementing Classes:
BaseServerTestCase.TestBuildServerImpl
,BuildServerImpl
,BuildServerServiceLocator
,ExtendableServiceLocator
public interface ExtensionsProvider
Main class that could be used to get extensions of given type. It's highly recommended to use it instead ofExtensionHolder
- Since:
- 8.0
- Author:
- Eugene Petrenko (eugene.petrenko@jetbrains.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ExtensionsProvider.ExtensionAction<T extends TeamCityExtension>
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <T extends TeamCityExtension>
voidforeachExtension(Class<T> agentExtensionClass, ExtensionsProvider.ExtensionAction<T> action)
Iterates over extensions of some class and executes some action on them.<T extends TeamCityExtension>
TgetExtension(Class<T> extensionClass, String sourceId)
Retrieves extension registered with specified type and id<T extends TeamCityExtension>
Collection<T>getExtensions(Class<T> extensionClass)
Get list of extensions for some extension point.default <T extends TeamCityExtension>
ExtensionsCollection<T>getExtensionsCollection(Class<T> extensionClass)
Live collection of extensions.default <T extends TeamCityExtension,TARGET>
ExtensionsCollection<TARGET>getExtensionsCollection(Class<T> extensionClass, Converter<TARGET,T> converter)
Live collection of extensions.<T extends TeamCityExtension>
Collection<String>getExtensionSources(Class<T> extensionClass)
Returns identifiers of the extensions of specified type<T extends TeamCityExtension,CONTEXT,TARGET>
StampedExtensionsSupplier<CONTEXT,TARGET>getStampedExtensionsSupplier(Class<T> extensionClass, Function<StampedExtensionsSupplier.StoredData<CONTEXT,Collection<T>>,TARGET> converter)
Live suppler of extensions.
-
-
-
Method Detail
-
getExtensions
@NotNull <T extends TeamCityExtension> Collection<T> getExtensions(@NotNull Class<T> extensionClass)
Get list of extensions for some extension point. TeamCity checks all registered Spring beans for extensions- Parameters:
extensionClass
- class of the extension, which defines the extension point type- Returns:
- list of extensions for specified extension point
-
foreachExtension
<T extends TeamCityExtension> void foreachExtension(@NotNull Class<T> agentExtensionClass, @NotNull ExtensionsProvider.ExtensionAction<T> action)
Iterates over extensions of some class and executes some action on them. Exceptions fromExtensionsProvider.ExtensionAction.action(T)
are catched and logged- Parameters:
agentExtensionClass
- extension classaction
- action to execute
-
getExtensionSources
@NotNull <T extends TeamCityExtension> Collection<String> getExtensionSources(@NotNull Class<T> extensionClass)
Returns identifiers of the extensions of specified type- Parameters:
extensionClass
- type of the extension- Returns:
- identifiers
-
getExtension
@Nullable <T extends TeamCityExtension> T getExtension(@NotNull Class<T> extensionClass, @NotNull String sourceId)
Retrieves extension registered with specified type and id- Parameters:
extensionClass
- extension typesourceId
- id- Returns:
- extension or null
-
getExtensionsCollection
@NotNull default <T extends TeamCityExtension> ExtensionsCollection<T> getExtensionsCollection(@NotNull Class<T> extensionClass)
Live collection of extensions. This collection can be stored in a field of some class. It is updated automatically if a new extension of a given class is registered.- Parameters:
extensionClass
- extension class- Returns:
- collection of extension
- Since:
- 2017.2
-
getExtensionsCollection
@NotNull default <T extends TeamCityExtension,TARGET> ExtensionsCollection<TARGET> getExtensionsCollection(@NotNull Class<T> extensionClass, @NotNull Converter<TARGET,T> converter)
Live collection of extensions. This collection can be stored in a field of some class. It is updated automatically if a new extension of a given class is registered.- Parameters:
extensionClass
- extension classconverter
- function to convert the base extension. Will be automatically applied if underlying collection should be reset (eg if a new extension is registered).- Returns:
- collection of extension
- Since:
- 2019.2
-
getStampedExtensionsSupplier
@NotNull <T extends TeamCityExtension,CONTEXT,TARGET> StampedExtensionsSupplier<CONTEXT,TARGET> getStampedExtensionsSupplier(@NotNull Class<T> extensionClass, @NotNull Function<StampedExtensionsSupplier.StoredData<CONTEXT,Collection<T>>,TARGET> converter)
Live suppler of extensions. This supplier can be safely stored in a field of some class. It is updated automatically if a new extension of a given class is registered or if outer context was changed. For example this supplier is very useful if some internal property is used to select a single extension implementation which should be used:StampedExtensionsSupplier<String, MyExtension> supplier = extensionsProvider.getStampedExtensionsSupplier(MyExtension.class, extensions -> { for (MyExtension ext : extensions.data) { if (ext.getClass().getName().equals(extensions.context)) return ext; } return new DefaultMyExtension(); }); MyExtension currentlyUsedExtension = supplier.get(TeamCityProperties.getProperty("myextension.implementationClass"));
here with each change of the "myextension.implementationClass" property the supplier will reset the internal cache and will call the provided function with the registered extensions collection and with the current context (the parameter value in this example). The internal cache is also reset automatically if the registered extensions collection changes. Without the getStampedExtensionsSupplier method, same code could be implemented with getExtensionsCollection(), but will require filtering the collection each time:ExtensionsCollection<MyExtension> allExtensions = extensionsProvider.getExtensionsCollection(MyExtension.class); MyExtension currentlyUsedExtension = null; for (MyExtension ext : allExtensions.getExtensions()) { if (ext.getClass().getName().equals(TeamCityProperties.getProperty("myextension.implementationClass"))) { currentlyUsedExtension = ext; break; } } if (currentlyUsedExtension == null) currentlyUsedExtension = new DefaultMyExtension()
- Parameters:
extensionClass
- extension classconverter
- function to convert the base extension. Will be automatically applied if underlying collection should be reset (eg if a new extension is registered).- Returns:
- collection of extension
- Since:
- 2020.2.1
-
-