Interface ExtensionsProvider

    • Method Detail

      • getExtensions

        @NotNull
        <T extends TeamCityExtensionCollection<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
      • getExtensionSources

        @NotNull
        <T extends TeamCityExtensionCollection<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 type
        sourceId - id
        Returns:
        extension or null
      • getExtensionsCollection

        @NotNull
        default <T extends TeamCityExtensionExtensionsCollection<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 class
        converter - 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 class
        converter - 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