@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 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("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)); }
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) { 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 aContext, AnnotatedTypeMetadata aMetadata) { String property = aContext.getEnvironment().getProperty("piper.worker.enabled"); boolean result = Boolean.valueOf(property); return new ConditionOutcome(result,ConditionMessage.forCondition(ConditionalOnWorker.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")); }
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 md) { String sourceClass = ""; if (md instanceof ClassMetadata) { sourceClass = ((ClassMetadata) md).getClassName(); } ConditionMessage.Builder message = ConditionMessage.forCondition("ZipkinSender", sourceClass); String property = context.getEnvironment() .getProperty("spring.zipkin.sender.type"); if (StringUtils.isEmpty(property)) { return ConditionOutcome.match(message.because("automatic sender type")); } String senderType = getType(((AnnotationMetadata) md).getClassName()); if (property.equalsIgnoreCase(senderType)) { return ConditionOutcome.match(message.because(property + " sender type")); } return ConditionOutcome.noMatch(message.because(property + " sender type")); }
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) { ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); ConditionMessage.Builder message = ConditionMessage .forCondition("LogbackLoggingCondition"); if (loggerFactory instanceof LoggerContext) { return ConditionOutcome.match( message.because("ILoggerFactory is a Logback LoggerContext")); } return ConditionOutcome .noMatch(message.because("ILoggerFactory is an instance of " + loggerFactory.getClass().getCanonicalName())); }
AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("DevTools DataSource Condition"); String[] dataSourceBeanNames = context.getBeanFactory() .getBeanNamesForType(DataSource.class); if (dataSourceBeanNames.length != 1) { return ConditionOutcome .noMatch(message.didNotFind("a single DataSource bean").atAll()); if (context.getBeanFactory() .getBeanNamesForType(DataSourceProperties.class).length != 1) { return ConditionOutcome.noMatch( message.didNotFind("a single DataSourceProperties bean").atAll()); BeanDefinition dataSourceDefinition = context.getRegistry() .getBeanDefinition(dataSourceBeanNames[0]); if (dataSourceDefinition instanceof AnnotatedBeanDefinition .getName() + ".DataSourceConfiguration$")) { return ConditionOutcome .match(message.foundExactly("auto-configured DataSource")); .noMatch(message.didNotFind("an auto-configured DataSource").atAll());
protected ConditionOutcome getEndpointOutcome(ConditionContext context, String endpointName) { Environment environment = context.getEnvironment(); String enabledProperty = this.prefix + endpointName + ".enabled"; if (environment.containsProperty(enabledProperty)) { boolean match = environment.getProperty(enabledProperty, Boolean.class, true); return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType).because( this.prefix + endpointName + ".enabled is " + match)); } return null; }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); ConditionMessage.Builder message = ConditionMessage .forCondition("LogbackLoggingCondition"); if (loggerFactory instanceof LoggerContext) { return ConditionOutcome.match( message.because("ILoggerFactory is a Logback LoggerContext")); } return ConditionOutcome .noMatch(message.because("ILoggerFactory is an instance of " + loggerFactory.getClass().getCanonicalName())); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { final ConditionMessage.Builder message = ConditionMessage.forCondition(this.single); final Environment environment = conditionContext.getEnvironment(); return HierarchicalPropertiesEvaluator.evaluate(environment, this.group, this.single) ? ConditionOutcome.match(message.because("enabled")) : ConditionOutcome.noMatch(message.because("not enabled")); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); AnnotationAttributes attributes = getEndpointAttributes(context, metadata); EndpointId id = EndpointId.of(attributes.getString("id")); String key = "management.endpoint." + id.toLowerCaseString() + ".enabled"; Boolean userDefinedEnabled = environment.getProperty(key, Boolean.class); if (userDefinedEnabled != null) { return new ConditionOutcome(userDefinedEnabled, ConditionMessage.forCondition(ConditionalOnEnabledEndpoint.class) .because("found property " + key + " with value " + userDefinedEnabled)); } Boolean userDefinedDefault = isEnabledByDefault(environment); if (userDefinedDefault != null) { return new ConditionOutcome(userDefinedDefault, ConditionMessage.forCondition(ConditionalOnEnabledEndpoint.class) .because("no property " + key + " found so using user defined default from " + ENABLED_BY_DEFAULT_KEY)); } boolean endpointDefault = attributes.getBoolean("enableByDefault"); return new ConditionOutcome(endpointDefault, ConditionMessage.forCondition(ConditionalOnEnabledEndpoint.class).because( "no property " + key + " found so using endpoint default")); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("JmmsDataSource"); if (anyMatches(context, metadata, this.anyPropertyCondition)) { return ConditionOutcome.noMatch(message.foundExactly("supported data source")); }else { return ConditionOutcome.match(message.foundExactly("jmms data source")); } } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("Okta Api Token Condition"); String tokenValue = context.getEnvironment().getProperty("okta.client.token"); if (StringUtils.hasText(tokenValue)) { return ConditionOutcome.match(message.foundExactly("provided API token")); } return ConditionOutcome.noMatch(message.didNotFind("provided API token").atAll()); } }
@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")); }