@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(); } }
); 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 ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) { ClientProperties clientProperties = getClientProperties(context); if (!clientProperties.isEnabled()) { return ConditionOutcome.noMatch( "Spring Boot Client is disabled, because 'spring.boot.admin.client.enabled' is false."); } if (clientProperties.getUrl().length == 0) { return ConditionOutcome.noMatch( "Spring Boot Client is disabled, because 'spring.boot.admin.client.url' is empty."); } return ConditionOutcome.match(); }
@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 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(); }
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) { boolean match = Boolean.valueOf(context.getEnvironment() .getProperty(this.prefix + "defaults.enabled", "true")); return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType).because( this.prefix + "defaults.enabled is considered " + match)); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("Initialized Restarter Condition"); Restarter restarter = getRestarter(); if (restarter == null) { return ConditionOutcome.noMatch(message.because("unavailable")); } if (restarter.getInitialUrls() == null) { return ConditionOutcome.noMatch(message.because("initialized without URLs")); } return ConditionOutcome.match(message.because("available and initialized")); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { boolean isRequired = (boolean) metadata .getAnnotationAttributes(annotationClass.getName()) .get("value"); String expression = isRequired ? wrapIfNecessary(requiredExpression) : wrapIfNecessary(notRequiredExpression); String rawExpression = expression; expression = context.getEnvironment().resolvePlaceholders(expression); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); BeanExpressionResolver resolver = (beanFactory != null) ? beanFactory.getBeanExpressionResolver() : null; BeanExpressionContext expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, null) : null; if (resolver == null) { resolver = new StandardBeanExpressionResolver(); } boolean result = (Boolean) resolver.evaluate(expression, expressionContext); return new ConditionOutcome(result, ConditionMessage .forCondition(annotationClass, "(" + rawExpression + ")") .resultedIn(result)); }
@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"); } }
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(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"); }
@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 protected ConditionOutcome buildOutcome(boolean anyMatch, String message) { return new ConditionOutcome(!anyMatch, message); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionOutcome propertiesSet = super.getMatchOutcome(context, metadata); return ConditionOutcome.inverse(propertiesSet); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); if (hasProperty(environment, "encrypt.key-store.location")) { if (hasProperty(environment, "encrypt.key-store.password")) { return ConditionOutcome.match("Keystore found in Environment"); } return ConditionOutcome .noMatch("Keystore found but no password in Environment"); } else if (hasProperty(environment, "encrypt.key")) { return ConditionOutcome.match("Key found in Environment"); } return ConditionOutcome.noMatch("Keystore nor key found in Environment"); }
@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) { ConditionMessage.Builder message = ConditionMessage .forCondition("Logging System"); String loggingSystem = System.getProperty(LoggingSystem.SYSTEM_PROPERTY); if (LoggingSystem.NONE.equals(loggingSystem)) { return ConditionOutcome.noMatch(message.because("system property " + LoggingSystem.SYSTEM_PROPERTY + " is set to none")); } return ConditionOutcome.match(message.because("enabled")); }
protected ConditionOutcome getMatchOutcome(Environment environment) { boolean velocityEnabled = environment.getProperty(VELOCITY_ENABLED_PROPERTY_NAME, boolean.class, true); if (!velocityEnabled) { return ConditionOutcome.noMatch("The velocity layout is disabled , caused by " + VELOCITY_ENABLED_PROPERTY_NAME + " = false"); } boolean velocityLayoutEnabled = environment.getProperty(VELOCITY_LAYOUT_ENABLED_PROPERTY_NAME, boolean.class, DEFAULT_VELOCITY_LAYOUT_ENABLED_VALUE); if (!velocityLayoutEnabled) { return ConditionOutcome.noMatch("The velocity layout is disabled , caused by " + VELOCITY_LAYOUT_ENABLED_PROPERTY_NAME + " = false"); } return ConditionOutcome.match("The velocity layout is enabled !"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableThriftServer.class); for (String name : enablers) { if (context.getBeanFactory().isTypeMatch(name, ThriftServerService.class)) { return ConditionOutcome.match("found @EnableThriftServer on a ThriftServerService"); } } return ConditionOutcome.noMatch("found no @EnableThriftServer on a ThriftServerService"); } }
@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-inbound-auth-header", String.class); final String yamlProperty = resolver.getProperty("msdashboard.security.strategies.forward-inbound-auth-header[0]", String.class); return new ConditionOutcome(propertiesProperty != null || yamlProperty != null, "Conditional on forward-inbound-auth-header value"); } }