Java Code Examples for org.springframework.boot.autoconfigure.condition.ConditionOutcome

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionOutcome. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sofa-ark   Source File: OnSpringBootVersion.java    License: Apache License 2.0 8 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Map<String, Object> springBootVersion = metadata
        .getAnnotationAttributes(ConditionalOnSpringBootVersion.class.getCanonicalName());
    if (springBootVersion == null || springBootVersion.get("version") == null) {
        return new ConditionOutcome(false, "No specified spring boot version.");
    }
    ConditionalOnSpringBootVersion.Version version = (ConditionalOnSpringBootVersion.Version) springBootVersion
        .get("version");
    if (ConditionalOnSpringBootVersion.Version.ANY.equals(version)) {
        return new ConditionOutcome(true, "Conditional on Any Spring Boot.");
    } else if (ConditionalOnSpringBootVersion.Version.OneX.equals(version)) {
        if (SpringBootVersion.getVersion().startsWith("1")) {
            return new ConditionOutcome(true, "Conditional on OneX Spring Boot.");
        } else {
            return new ConditionOutcome(false, "Conditional on OneX Spring Boot.");
        }
    } else if (ConditionalOnSpringBootVersion.Version.TwoX.equals(version)) {
        if (SpringBootVersion.getVersion().startsWith("2")) {
            return new ConditionOutcome(true, "Conditional on TwoX Spring Boot.");
        } else {
            return new ConditionOutcome(false, "Conditional on TwoX Spring Boot.");
        }
    }
    throw new IllegalStateException("Error Spring Boot Version.");
}
 
Example 2
Source Project: jeecg-boot-with-activiti   Source File: OSSCondition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String sourceClass = "";
	if (metadata instanceof ClassMetadata) {
		sourceClass = ((ClassMetadata) metadata).getClassName();
	}
	ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
	Environment environment = context.getEnvironment();
	try {
		BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
		if (!specified.isBound()) {
			return ConditionOutcome.match(message.because("automatic OSS type"));
		}
		OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
		if (specified.get() == required) {
			return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
		}
	}
	catch (BindException ex) {
	}
	return ConditionOutcome.noMatch(message.because("unknown OSS type"));
}
 
Example 3
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 !");

    }
 
Example 4
Source Project: cola-cloud   Source File: EnableWebSecurityCondition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String[] enablers = context.getBeanFactory()
            .getBeanNamesForAnnotation(EnableWebSecurity.class);
    ConditionMessage.Builder message = ConditionMessage
            .forCondition("@EnableWebSecurity Condition");
    if (enablers != null && enablers.length > 0) {
        return ConditionOutcome.match(message
                .found("@EnableWebSecurity annotation on Application")
                .items(enablers));
    }

    return ConditionOutcome.noMatch(message.didNotFind(
            "@EnableWebSecurity annotation " + "on Application")
            .atAll());
}
 
Example 5
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth TokenInfo Condition");
	Environment environment = context.getEnvironment();
	Boolean preferTokenInfo = environment.getProperty("security.oauth2.resource.prefer-token-info",
			Boolean.class);
	if (preferTokenInfo == null) {
		preferTokenInfo = environment.resolvePlaceholders("${OAUTH2_RESOURCE_PREFERTOKENINFO:true}")
				.equals("true");
	}
	String tokenInfoUri = environment.getProperty("security.oauth2.resource.token-info-uri");
	String userInfoUri = environment.getProperty("security.oauth2.resource.user-info-uri");
	if (!StringUtils.hasLength(userInfoUri) && !StringUtils.hasLength(tokenInfoUri)) {
		return ConditionOutcome.match(message.didNotFind("user-info-uri property").atAll());
	}
	if (StringUtils.hasLength(tokenInfoUri) && preferTokenInfo) {
		return ConditionOutcome.match(message.foundExactly("preferred token-info-uri property"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("token info").atAll());
}
 
Example 6
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String type = context.getEnvironment().getProperty("redisson.type");
    if (type == null || type.isEmpty() || type.trim().isEmpty()) {
        type = RedissonType.SINGLE.name();
    }
    ConditionMessage.Builder condition = ConditionMessage.forCondition("RedissonCondition",
            String.format("(redisson.type=%s)", type));
    if (type.equalsIgnoreCase(RedissonType.NONE.name())) {
        return noMatch(condition.found("matched value").items(Style.QUOTE, type));
    }
    Set<String> relaxedTypes = Arrays.stream(RedissonType.values())
            .filter(t -> t != RedissonType.NONE)
            .map(Enum::name)
            .map(name -> Arrays.asList(name, name.toLowerCase(), name.toUpperCase()))
            .flatMap(List::stream)
            .collect(toSet());
    if (relaxedTypes.contains(type)) {
        return match(condition.found("matched value").items(Style.QUOTE, type));
    } else {
        return noMatch(condition.because("has unrecognized value '" + type + "'"));
    }
}
 
Example 7
Source Project: loc-framework   Source File: PrefixPropertyCondition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
    AnnotatedTypeMetadata metadata) {
  String prefix = (String) attribute(metadata, "prefix");
  Class<?> value = (Class<?>) attribute(metadata, "value");
  ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
  try {
    new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
        .bind(prefix, Bindable.of(value))
        .orElseThrow(
            () -> new FatalBeanException("Could not bind DataSourceSettings properties"));
    return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
  } catch (Exception e) {
    //ignore
  }
  return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
 
Example 8
/**
 * Determines whether the current runtime environment matches the one passed through the annotation.
 * @param context the spring context at the point in time the condition is being evaluated
 * @param metadata annotation metadata containing all acceptable GCP environments
 * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if no GcpEnvironmentProvider is found in
 * spring context
 */
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

	Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnGcpEnvironment.class.getName());
	GcpEnvironment[] targetEnvironments = (GcpEnvironment[]) attributes.get("value");
	Assert.notNull(targetEnvironments, "Value attribute of ConditionalOnGcpEnvironment cannot be null.");

	GcpEnvironmentProvider environmentProvider = context.getBeanFactory().getBean(GcpEnvironmentProvider.class);
	GcpEnvironment currentEnvironment = environmentProvider.getCurrentEnvironment();

	if (Arrays.stream(targetEnvironments).noneMatch((env) -> env == currentEnvironment)) {
		return new ConditionOutcome(false, "Application is not running on any of "
				+ Arrays.stream(targetEnvironments)
				.map(GcpEnvironment::toString)
				.collect(Collectors.joining(", ")));
	}

	return new ConditionOutcome(true, "Application is running on " + currentEnvironment);
}
 
Example 9
@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();
}
 
Example 10
protected Map<String, ConditionOutcome> getConditionOutcomes() {
    boolean jmsEnabled = environment.getProperty("flowable.task.app.jms-enabled", Boolean.class, false);
    boolean kafkaEnabled = environment.getProperty("flowable.task.app.kafka-enabled", Boolean.class, false);
    boolean rabbitEnabled = environment.getProperty("flowable.task.app.rabbit-enabled", Boolean.class, false);
    Map<String, ConditionOutcome> conditions = new HashMap<>();

    if (!jmsEnabled) {
        conditions.put("org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration",
            ConditionOutcome.noMatch("Property flowable.task.app.jms-enabled was not set to true")
        );
    }

    if (!kafkaEnabled) {
        conditions.put("org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration",
            ConditionOutcome.noMatch("Property flowable.task.app.kafka-enabled was not set to true")
        );
    }

    if (!rabbitEnabled) {
        conditions.put("org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration",
            ConditionOutcome.noMatch("Property flowable.task.app.rabbit-enabled was not set to true")
        );
    }
    return conditions;
}
 
Example 11
Source Project: spring-cloud-dataflow   Source File: OnLocalPlatform.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

	Iterable<CloudProfileProvider> cloudProfileProviders = ServiceLoader.load(CloudProfileProvider.class);
	boolean onLocalPlatform = true;
	for (CloudProfileProvider cloudProfileProvider : cloudProfileProviders) {
		if (cloudProfileProvider.isCloudPlatform(context.getEnvironment())) {
			onLocalPlatform = false;
		}
	}
	if (onLocalPlatform) {
		return new ConditionOutcome(onLocalPlatform, "On local platform.");
	} else {
		return new ConditionOutcome(onLocalPlatform, "On cloud platform.");
	}
}
 
Example 12
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
    Binder binder = Binder.get(context.getEnvironment());
    Map<String, Object> sslProperties = binder.bind("camel.ssl.config", Bindable.mapOf(String.class, Object.class)).orElse(Collections.emptyMap());
    ConditionMessage.Builder message = ConditionMessage.forCondition("camel.ssl.config");
    if (sslProperties.size() > 0) {
        return ConditionOutcome.match(message.because("enabled"));
    }

    return ConditionOutcome.noMatch(message.because("not enabled"));
}
 
Example 13
Source Project: camel-spring-boot   Source File: GroupCondition.java    License: Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 14
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    // System property for server configuration found, match
    if (System.getProperty(configSystemProperty) != null) {
        return ConditionOutcome.match(
                startConditionMessage().because("System property '" + configSystemProperty + "' is set."));
    }
    // Environment property for server configuration found, match
    if (context.getEnvironment().containsProperty(CONFIG_ENVIRONMENT_PROPERTY)) {
        return ConditionOutcome.match(startConditionMessage()
                .foundExactly("property " + CONFIG_ENVIRONMENT_PROPERTY));
    }
    // System property for client configuration found, no match
    if (System.getProperty(HazelcastJetClientConfigAvailableCondition.CONFIG_SYSTEM_PROPERTY) != null) {
        return ConditionOutcome.noMatch(startConditionMessage().because("System property '"
                + HazelcastJetClientConfigAvailableCondition.CONFIG_SYSTEM_PROPERTY + "' is set."));
    }
    // Environment property for client configuration found, no match
    if (context.getEnvironment()
               .containsProperty(HazelcastJetClientConfigAvailableCondition.CONFIG_ENVIRONMENT_PROPERTY)) {
        return ConditionOutcome.noMatch(startConditionMessage().because("Environment property '"
                + HazelcastJetClientConfigAvailableCondition.CONFIG_ENVIRONMENT_PROPERTY + "' is set."));
    }
    ConditionOutcome resourceOutcome = getResourceOutcome(context, metadata);
    // Found a configuration file for server, match
    if (resourceOutcome.isMatch()) {
        return resourceOutcome;
    }
    // Found a configuration file for client, no match
    ConditionOutcome clientResourceOutcome = clientConfigAvailableCondition.getMatchOutcome(context, metadata);
    if (clientResourceOutcome.isMatch()) {
        return ConditionOutcome.noMatch(clientResourceOutcome.getConditionMessage());
    }
    return ConditionOutcome.match(startConditionMessage().because(
            "No configuration option found, using default configuration."));
}
 
Example 15
Source Project: sds   Source File: MultOnPropertyCondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(MultConditionalOnProperty.
            class.getName());
    String propertyName = (String) annotationAttributes.get("name");
    if (StringUtils.isBlank(propertyName)) {
        propertyName = (String) annotationAttributes.get("value");
    }

    if (StringUtils.isBlank(propertyName)) {
        return new ConditionOutcome(false, "没发现配置name或value");
    }

    String[] values = (String[]) annotationAttributes.get("havingValue");
    if (values.length == 0) {
        return new ConditionOutcome(false, "没发现配置havingValue");
    }

    String propertyValue = context.getEnvironment().getProperty(propertyName);
    if (StringUtils.isBlank(propertyValue)) {
        propertyValue = ((ConfigurableApplicationContext) context.getResourceLoader()).getEnvironment().
                getProperty(propertyName);

        if (StringUtils.isBlank(propertyValue)) {
            return new ConditionOutcome(false, "没发现配置" + propertyName);
        }
    }

    /**
     * 相当于或的关系,只要有一个能匹配就算成功
     */
    for (String havingValue : values) {
        if (propertyValue.equalsIgnoreCase(havingValue)) {
            return new ConditionOutcome(true, "匹配成功");
        }
    }

    return new ConditionOutcome(false, "匹配失败");
}
 
Example 16
Source Project: joyqueue   Source File: MsgQueryEnabledCondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    MsgQueryConfigurationProperties msgQueryConfigurationProperties=getMsgQueryProperties(context);
    if(!msgQueryConfigurationProperties.getEnabled()){
        logger.warn("message query function is disabled, because [message.query.enabled = false]");
        return ConditionOutcome.noMatch("message query function is disabled, because [message.query.enabled = false]");
    }
    logger.info("message query function is enabled");
    return ConditionOutcome.match();
}
 
Example 17
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	if (AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment()) {
		return ConditionOutcome.match();
	}
	return ConditionOutcome.noMatch("not running in aws environment");
}
 
Example 18
Source Project: sofa-ark   Source File: OnArkEnabled.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String currentClassLoader = this.getClass().getClassLoader().getClass().getName();
    if (ARK_TEST_CLASSLOADER_NAME.equals(currentClassLoader)
        || ARK_BIZ_CLASSLOADER_NAME.equals(currentClassLoader)
        || ARK_PLUGIN_CLASSLOADER_NAME.equals(currentClassLoader)) {
        return new ConditionOutcome(true, "SOFAArk has started.");
    } else {
        return new ConditionOutcome(false, "SOFAArk has not started.");
    }
}
 
Example 19
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT Condition");
	Environment environment = context.getEnvironment();
	String keyValue = environment.getProperty("security.oauth2.resource.jwt.key-value");
	String keyUri = environment.getProperty("security.oauth2.resource.jwt.key-uri");
	if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) {
		return ConditionOutcome.match(message.foundExactly("provided public key"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("provided public key").atAll());
}
 
Example 20
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWK Condition");
	Environment environment = context.getEnvironment();
	String keyUri = environment.getProperty("security.oauth2.resource.jwk.key-set-uri");
	if (StringUtils.hasText(keyUri)) {
		return ConditionOutcome.match(message.foundExactly("provided jwk key set URI"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("key jwk set URI not provided").atAll());
}
 
Example 21
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT KeyStore Condition");
	Environment environment = context.getEnvironment();
	String keyStore = environment.getProperty("security.oauth2.resource.jwt.key-store");
	if (StringUtils.hasText(keyStore)) {
		return ConditionOutcome.match(message.foundExactly("provided key store location"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("key store location not provided").atAll());
}
 
Example 22
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth ResourceServer Condition");
	Environment environment = context.getEnvironment();
	if (!(environment instanceof ConfigurableEnvironment)) {
		return ConditionOutcome.noMatch(message.didNotFind("A ConfigurableEnvironment").atAll());
	}
	if (hasOAuthClientId(environment)) {
		return ConditionOutcome.match(message.foundExactly("client-id property"));
	}
	Binder binder = Binder.get(environment);
	String prefix = "security.oauth2.resource.";
	if (binder.bind(prefix + "jwt", STRING_OBJECT_MAP).isBound()) {
		return ConditionOutcome.match(message.foundExactly("JWT resource configuration"));
	}
	if (binder.bind(prefix + "jwk", STRING_OBJECT_MAP).isBound()) {
		return ConditionOutcome.match(message.foundExactly("JWK resource configuration"));
	}
	if (StringUtils.hasText(environment.getProperty(prefix + "user-info-uri"))) {
		return ConditionOutcome.match(message.foundExactly("user-info-uri property"));
	}
	if (StringUtils.hasText(environment.getProperty(prefix + "token-info-uri"))) {
		return ConditionOutcome.match(message.foundExactly("token-info-uri property"));
	}
	if (ClassUtils.isPresent(AUTHORIZATION_ANNOTATION, null)) {
		if (AuthorizationServerEndpointsConfigurationBeanCondition.matches(context)) {
			return ConditionOutcome.match(message.found("class").items(AUTHORIZATION_ANNOTATION));
		}
	}
	return ConditionOutcome
			.noMatch(message.didNotFind("client ID, JWT resource or authorization server").atAll());
}
 
Example 23
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String clientId = context.getEnvironment().getProperty("security.oauth2.client.client-id");
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth Client ID");
	if (StringUtils.hasLength(clientId)) {
		return ConditionOutcome.match(message.foundExactly("security.oauth2.client.client-id property"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("security.oauth2.client.client-id property").atAll());
}
 
Example 24
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableOAuth2Sso.class);
	ConditionMessage.Builder message = ConditionMessage.forCondition("@EnableOAuth2Sso Condition");
	for (String name : enablers) {
		if (context.getBeanFactory().isTypeMatch(name, WebSecurityConfigurerAdapter.class)) {
			return ConditionOutcome.match(
					message.found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter").items(name));
		}
	}
	return ConditionOutcome.noMatch(
			message.didNotFind("@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter").atAll());
}
 
Example 25
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT Condition");
	Environment environment = context.getEnvironment();
	String keyValue = environment.getProperty("security.oauth2.authorization.jwt.key-value");
	if (StringUtils.hasText(keyValue)) {
		return ConditionOutcome.match(message.foundExactly("provided private or symmetric key"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("provided private or symmetric key").atAll());
}
 
Example 26
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT KeyStore Condition");
	Environment environment = context.getEnvironment();
	String keyStore = environment.getProperty("security.oauth2.authorization.jwt.key-store");
	if (StringUtils.hasText(keyStore)) {
		return ConditionOutcome.match(message.foundExactly("provided key store location"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("provided key store location").atAll());
}
 
Example 27
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableEnvironment environment = (ConfigurableEnvironment) context
			.getEnvironment();

	String protocol = environment.getProperty("dubbo.registry.protocol");

	if (PROTOCOL.equals(protocol)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.protocol'");
	}

	String address = environment.getProperty("dubbo.registry.address");

	if (StringUtils.startsWithIgnoreCase(address, PROTOCOL)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.address'");
	}

	Map<String, Object> properties = getSubProperties(
			environment.getPropertySources(), "dubbo.registries.");

	boolean found = properties.entrySet().stream().anyMatch(entry -> {
		String key = entry.getKey();
		String value = String.valueOf(entry.getValue());
		return (key.endsWith(".address") && value.startsWith(PROTOCOL))
				|| (key.endsWith(".protocol") && PROTOCOL.equals(value));

	});

	return found
			? ConditionOutcome.noMatch(
					"'spring-cloud' protocol was found in 'dubbo.registries.*'")
			: ConditionOutcome.match();
}
 
Example 28
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("FlexyPoolConfigurationAvailable");
    String propertiesFilePath = System.getProperty(PropertyLoader.PROPERTIES_FILE_PATH);
    if (propertiesFilePath != null && ClassLoaderUtils.getResource(propertiesFilePath) != null) {
        return ConditionOutcome.match(message.found("FlexyPool configuration file").items(propertiesFilePath));
    }
    if (ClassLoaderUtils.getResource(PropertyLoader.PROPERTIES_FILE_NAME) != null) {
        return ConditionOutcome.match(message.found("FlexyPool configuration file").items(PropertyLoader.PROPERTIES_FILE_NAME));
    }
    return ConditionOutcome.noMatch(message.didNotFind("FlexyPool configuration file").atAll());
}
 
Example 29
@Override
protected ConditionOutcome getResourceOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	if (System.getProperty(configSystemProperty) != null) {
		return ConditionOutcome.match(startConditionMessage()
				.because("System property '" + configSystemProperty + "' is set."));
	}
	return super.getResourceOutcome(context, metadata);
}
 
Example 30
@Test
public void testGetResourceOutcomeForSystemProperty() {
	System.setProperty("anyProperty", "anyValue");
	QuickFixJConfigResourceCondition resourceCondition =
			new ClientConfigAvailableCondition("anyProperty");

	ConditionOutcome conditionOutcome =
			resourceCondition.getResourceOutcome(mock(ConditionContext.class), mock(AnnotatedTypeMetadata.class));
	assertThat(conditionOutcome).isNotNull();
	assertThat(conditionOutcome.getMessage()).contains("ResourceCondition (quickfixj.client) System property 'anyProperty' is set.");
}