All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.nebula.dependency.recommender.RecommendationStrategyFactory Maven / Gradle / Ivy

Go to download

Allows projects to leave off version numbers in dependencies section and have versions recommended by other sources

There is a newer version: 12.5.1
Show newest version
package netflix.nebula.dependency.recommender;

import netflix.nebula.dependency.recommender.provider.RecommendationProviderContainer;
import org.gradle.api.Project;

/**
 * Creates RecommendationStrategy lazily on demand and caches it.
 * This is used to allow for scoped recommendationStrategies (e.g. per configuration as in DependencyRecommendationsPlugin)
 */
public class RecommendationStrategyFactory {
    private final Project project;
    private RecommendationStrategy recommendationStrategy;

    public RecommendationStrategyFactory(Project project) {
        this.project = project;
    }
    
    public RecommendationStrategy getRecommendationStrategy() {
        if(recommendationStrategy == null) {
            try {
                RecommendationProviderContainer recommendationProviderContainer = project.getExtensions().getByType(RecommendationProviderContainer.class);
                recommendationStrategy = recommendationProviderContainer.getStrategy().getStrategyClass().newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
        return recommendationStrategy;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy