Search in sources :

Example 1 with EnvironmentRepository

use of org.springframework.cloud.config.server.environment.EnvironmentRepository in project spring-cloud-config by spring-cloud.

the class OnSearchPathLocatorPresent method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    List<String> types = CompositeUtils.getCompositeTypeList(context.getEnvironment());
    // get EnvironmentRepository types from registered factories
    List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>();
    for (String type : types) {
        String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
        Type[] actualTypeArguments = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
        Class<? extends EnvironmentRepository> repositoryType = (Class<? extends EnvironmentRepository>) actualTypeArguments[0];
        repositoryTypes.add(repositoryType);
    }
    boolean required = metadata.isAnnotated(ConditionalOnSearchPathLocator.class.getName());
    boolean foundSearchPathLocator = repositoryTypes.stream().anyMatch(SearchPathLocator.class::isAssignableFrom);
    if (required && !foundSearchPathLocator) {
        return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class).notAvailable(SearchPathLocator.class.getTypeName()));
    }
    if (!required && foundSearchPathLocator) {
        return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnMissingSearchPathLocator.class).available(SearchPathLocator.class.getTypeName()));
    }
    return ConditionOutcome.match();
}
Also used : EnvironmentRepository(org.springframework.cloud.config.server.environment.EnvironmentRepository) SearchPathLocator(org.springframework.cloud.config.server.environment.SearchPathLocator) ArrayList(java.util.ArrayList) Type(java.lang.reflect.Type) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 EnvironmentRepository (org.springframework.cloud.config.server.environment.EnvironmentRepository)1 SearchPathLocator (org.springframework.cloud.config.server.environment.SearchPathLocator)1