|
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; |
| 30 | +import org.springframework.context.annotation.Conditional; |
24 | 31 | import org.springframework.context.annotation.Configuration; |
25 | 32 | import org.springframework.context.annotation.Import; |
| 33 | +import org.springframework.core.io.Resource; |
| 34 | +import org.springframework.core.type.AnnotatedTypeMetadata; |
26 | 35 |
|
27 | 36 | /** |
28 | | - * {@link EnableAutoConfiguration Auto-configuration} for Hazelcast. Creates a |
| 37 | + * {@link EnableAutoConfiguration Auto-configuration} for Hazelcast IMDG. Creates a |
29 | 38 | * {@link HazelcastInstance} based on explicit configuration or when a default |
30 | 39 | * configuration file is found in the environment. |
31 | 40 | * |
|
35 | 44 | * @see HazelcastConfigResourceCondition |
36 | 45 | */ |
37 | 46 | @Configuration(proxyBeanMethods = false) |
| 47 | +@Conditional(HazelcastDataGridCondition.class) |
38 | 48 | @ConditionalOnClass(HazelcastInstance.class) |
39 | 49 | @EnableConfigurationProperties(HazelcastProperties.class) |
40 | 50 | @Import({ HazelcastClientConfiguration.class, HazelcastServerConfiguration.class }) |
41 | 51 | public class HazelcastAutoConfiguration { |
42 | 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 | + |
43 | 69 | } |
0 commit comments