@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(); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { boolean present = false; int i = 0; while (!present && i < CONDITION_CLASSES.length) { present = ClassUtils.isPresent(CONDITION_CLASSES[i], context.getClassLoader()); i++; } return present; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (!StringUtils.isEmpty(context.getEnvironment().getProperty("fat.titan.url"))) { return true; } else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("uat.titan.url"))) { return true; } else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url"))) { return true; } return false; }
@Override public ConditionOutcome getMatchOutcome(ConditionContext aContext, AnnotatedTypeMetadata aMetadata) { String property = aContext.getEnvironment().getProperty("piper.coordinator.enabled"); boolean result = Boolean.valueOf(property); return new ConditionOutcome(result,ConditionMessage.forCondition(ConditionalOnCoordinator.class, "(" + getClass().getName() + ")").resultedIn(result)); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String iKey = context.getEnvironment().getProperty("azure.application-insights.instrumentation-key"); if (StringUtils.isNoneBlank(iKey)) { return new ConditionOutcome(true, ConditionMessage.of("instrumentation key found")); } iKey = IkeyResolver.getIkeyFromEnvironmentVariables(); if (StringUtils.isNoneBlank(iKey)) { return new ConditionOutcome(true, ConditionMessage.of("instrumentation key found")); } else { return new ConditionOutcome(false, ConditionMessage.of("instrumentation key not found")); } } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> beanAttributes = metadata.getAnnotationAttributes(Bean.class.getName()); String beanName = ((String[]) beanAttributes.get("name"))[0]; if(StringUtils.isEmpty(beanName)) { throw new IllegalStateException("OnMissingBeanCondition can't detect bean name!"); } boolean missingBean = !context.getBeanFactory().containsBean(context.getEnvironment().resolveRequiredPlaceholders(beanName)); return missingBean ? ConditionOutcome.match(beanName + " not found") : ConditionOutcome.noMatch(beanName + " found"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { ConfigTree ct = new ConfigTree((ConfigurableEnvironment) conditionContext.getEnvironment(), "jetcache."); if (match(ct, "local.") || match(ct, "remote.")) { return ConditionOutcome.match(); } else { return ConditionOutcome.noMatch("no match for " + cacheTypes[0]); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Set<String> activeProfiles = Sets.newHashSet(context.getEnvironment().getActiveProfiles()); Set<String> requiredActiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnProfile.class.getName()); Set<String> requiredInactiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnMissingProfile.class .getName()); return Sets.difference(requiredActiveProfiles, activeProfiles).isEmpty() && Sets.intersection(requiredInactiveProfiles, activeProfiles).isEmpty(); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) { return true; } } return false; } return true; }
private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context, String basename) { ConditionMessage.Builder message = ConditionMessage .forCondition("ResourceBundle"); for (String name : StringUtils.commaDelimitedListToStringArray( StringUtils.trimAllWhitespace(basename))) { for (Resource resource : getResources(context.getClassLoader(), name)) { if (resource.exists()) { return ConditionOutcome .match(message.found("bundle").items(resource)); } } } return ConditionOutcome.noMatch( message.didNotFind("bundle with basename " + basename).atAll()); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Assert.isInstanceOf(DefaultListableBeanFactory.class, context.getBeanFactory()); DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) context .getBeanFactory(); int foundSenders = listableBeanFactory .getBeanNamesForType(Sender.class).length; // Previously we supported 1 Sender bean at a time // which could be overridden by another auto-configuration. // Now we support both the overridden bean and our default zipkinSender bean. // Since this config is adapting the old config we're searching for exactly 1 // `Sender` bean before `ZipkinAutoConfiguration` kicks in. if (foundSenders != 1) { return ConditionOutcome.noMatch( "None or multiple Sender beans found - no reason to apply backwards compatibility"); } int foundReporters = listableBeanFactory .getBeanNamesForType(Reporter.class).length; // Check if we need to provide a Reporter bean for the overridden Sender bean if (foundReporters > 0) { return ConditionOutcome.noMatch( "The old config setup already defines its own Reporter bean"); } return ConditionOutcome.match(); }
private ClientProperties getClientProperties(ConditionContext context) { ClientProperties clientProperties = new ClientProperties(context.getEnvironment()); Binder.get(context.getEnvironment()).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties)); return clientProperties; } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return !context.getBeanFactory().containsBeanDefinition("bean1"); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledDetector.class.getName())); final String name = attributes.getString("value"); final String prefix = attributes.getString("prefix"); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix + "." + name + "."); Boolean enabled = resolver.getProperty("enabled", Boolean.class, true); return new ConditionOutcome(enabled, ConditionMessage.forCondition(ConditionalOnEnabledDetector.class, name) .because(enabled ? "enabled" : "disabled")); }
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { String[] expressions = (String[]) metadata.getAnnotationAttributes( AcrossCondition.class.getName() ) .get( "value" ); for ( String expression : expressions ) { if ( !StringUtils.isBlank( expression ) && !evaluate( expression, context.getBeanFactory(), context.getEnvironment() ) ) { return false; } } return true; }
@Override public ConditionOutcome getMatchOutcome(final ConditionContext context, final AnnotatedTypeMetadata metadata) { final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment()); final String propertiesProperty = resolver.getProperty("msdashboard.security.strategies.forward-oauth2-token", String.class); final String yamlProperty = resolver.getProperty("msdashboard.security.strategies.forward-oauth2-token[0]", String.class); return new ConditionOutcome(propertiesProperty != null || yamlProperty != null, "Conditional on forward-oauth2-token value"); } }
@Override public ConditionOutcome getMatchOutcome(final ConditionContext context, final AnnotatedTypeMetadata metadata) { for (String className : CLASS_NAMES) { if (ClassUtils.isPresent(className, context.getClassLoader())) { return ConditionOutcome.match("found EclipselinkEntityManager class"); } } return ConditionOutcome.noMatch("did not find EclipselinkEntityManager class"); }
); logger.warn(failureMessage, e); return new ConditionOutcome(false, failureMessage); ConfigurableListableBeanFactory bf = context.getBeanFactory(); boolean anyMatch = Stream.of(bf.getBeanNamesForType(conditionalClass)) .anyMatch(beanName -> qualifierMatch == isOneMatching(beanName, bf, qualifiers));
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { AnnotationAttributes attributes = (AnnotationAttributes) metadata.getAnnotationAttributes( ConditionalOnAutoConfiguration.class.getName(), true ); val registry = AcrossApplicationAutoConfiguration.retrieve( context.getBeanFactory(), context.getClassLoader() ); List<String> required = new ArrayList<>(); String[] classNames = attributes.getStringArray( "value" ); if ( classNames != null ) { required.addAll( Arrays.asList( classNames ) ); } classNames = attributes.getStringArray( "classNames" ); if ( classNames != null ) { required.addAll( Arrays.asList( classNames ) ); } for ( String className : required ) { if ( !registry.notExcluded( className ) ) { return false; } } return true; } }
private boolean isWebApplicationContext(ConditionContext context) { ResourceLoader resourceLoader = context.getResourceLoader(); if (resourceLoader instanceof ConfigurableReactiveWebApplicationContext) { return true; } if (!ClassUtils.isPresent(CLASS_NAME_WEB_APPLICATION_CONTEXT, context.getClassLoader())) { return false; } return WebApplicationContext.class.isInstance(resourceLoader); }