|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import com.hazelcast.core.HazelcastInstance;
|
20 | 20 |
|
21 | 21 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
| 22 | +import org.springframework.boot.autoconfigure.condition.ConditionMessage; |
| 23 | +import org.springframework.boot.autoconfigure.condition.ConditionMessage.Builder; |
| 24 | +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
22 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
| 26 | +import org.springframework.boot.autoconfigure.condition.SpringBootCondition; |
| 27 | +import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration.HazelcastDataGridCondition; |
23 | 28 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
| 29 | +import org.springframework.context.annotation.ConditionContext; |
24 | 30 | import org.springframework.context.annotation.Conditional;
|
25 | 31 | import org.springframework.context.annotation.Configuration;
|
26 | 32 | import org.springframework.context.annotation.Import;
|
| 33 | +import org.springframework.core.io.Resource; |
| 34 | +import org.springframework.core.type.AnnotatedTypeMetadata; |
27 | 35 |
|
28 | 36 | /**
|
29 |
| - * {@link EnableAutoConfiguration Auto-configuration} for Hazelcast. Creates a |
| 37 | + * {@link EnableAutoConfiguration Auto-configuration} for Hazelcast IMDG. Creates a |
30 | 38 | * {@link HazelcastInstance} based on explicit configuration or when a default
|
31 | 39 | * configuration file is found in the environment.
|
32 | 40 | *
|
|
36 | 44 | * @see HazelcastConfigResourceCondition
|
37 | 45 | */
|
38 | 46 | @Configuration(proxyBeanMethods = false)
|
39 |
| -@Conditional(HazelcastJetConfigMissingCondition.class) |
| 47 | +@Conditional(HazelcastDataGridCondition.class) |
40 | 48 | @ConditionalOnClass(HazelcastInstance.class)
|
41 | 49 | @EnableConfigurationProperties(HazelcastProperties.class)
|
42 | 50 | @Import({ HazelcastClientConfiguration.class, HazelcastServerConfiguration.class })
|
43 | 51 | public class HazelcastAutoConfiguration {
|
44 | 52 |
|
| 53 | + static class HazelcastDataGridCondition extends SpringBootCondition { |
| 54 | + |
| 55 | + private static final String HAZELCAST_JET_CONFIG_FILE = "classpath:/hazelcast-jet-default.yaml"; |
| 56 | + |
| 57 | + @Override |
| 58 | + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { |
| 59 | + Builder message = ConditionMessage.forCondition(HazelcastDataGridCondition.class.getSimpleName()); |
| 60 | + Resource resource = context.getResourceLoader().getResource(HAZELCAST_JET_CONFIG_FILE); |
| 61 | + if (resource.exists()) { |
| 62 | + return ConditionOutcome.noMatch(message.because("Found Hazelcast Jet on the classpath")); |
| 63 | + } |
| 64 | + return ConditionOutcome.match(message.because("Hazelcast Jet not found on the classpath")); |
| 65 | + } |
| 66 | + |
| 67 | + } |
| 68 | + |
45 | 69 | }
|
0 commit comments