From a0cb69742dc641480c0204c0e6cbe5dd7fe8b426 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Fri, 5 Aug 2022 16:25:03 +0200 Subject: [PATCH] Add runtime hints. Removed unused dependency. --- spring-cloud-zookeeper-core/pom.xml | 4 --- .../zookeeper/ZookeeperAutoConfiguration.java | 35 +++++++++++++++++++ .../resources/META-INF/spring/aot.factories | 2 ++ .../ZookeeperDiscoveryAutoConfiguration.java | 23 ++++++++++++ .../resources/META-INF/spring/aot.factories | 2 ++ src/checkstyle/checkstyle-suppressions.xml | 2 +- 6 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/aot.factories create mode 100644 spring-cloud-zookeeper-discovery/src/main/resources/META-INF/spring/aot.factories diff --git a/spring-cloud-zookeeper-core/pom.xml b/spring-cloud-zookeeper-core/pom.xml index 0f109a8a..b1018cef 100644 --- a/spring-cloud-zookeeper-core/pom.xml +++ b/spring-cloud-zookeeper-core/pom.xml @@ -53,10 +53,6 @@ spring-boot-starter-actuator true - - org.springframework.boot - spring-boot-starter-validation - org.springframework.cloud spring-cloud-commons diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java index 50a50ea0..606cd512 100644 --- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java +++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java @@ -22,12 +22,19 @@ import org.apache.curator.RetryPolicy; import org.apache.curator.drivers.TracerDriver; import org.apache.curator.ensemble.EnsembleProvider; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.x.discovery.UriSpec; +import org.apache.zookeeper.ClientCnxnSocketNIO; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.ClassUtils; /** * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration @@ -67,3 +74,31 @@ public class ZookeeperAutoConfiguration { } } + +// TODO: remove after GraalVM metadata PR merged +class ZookeeperCoreHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + if (!ClassUtils.isPresent("org.apache.zookeeper.ZooKeeper", classLoader)) { + return; + } + hints.reflection().registerType(TypeReference.of(ClientCnxnSocketNIO.class), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + hints.reflection() + .registerType(TypeReference.of("org.apache.curator.x.discovery.details.OldServiceInstance"), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS)); + hints.reflection() + .registerType(TypeReference.of("org.apache.curator.x.discovery.UriSpec"), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS)); + hints.reflection().registerType(TypeReference.of(UriSpec.Part.class), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS)); + hints.reflection() + .registerType(TypeReference.of("org.apache.curator.x.discovery.ServiceInstance"), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS)); + } +} diff --git a/spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/aot.factories new file mode 100644 index 00000000..c2fe4ff2 --- /dev/null +++ b/spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/aot.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar=\ +org.springframework.cloud.zookeeper.ZookeeperCoreHints \ No newline at end of file diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java index c4299119..f59eb5f3 100644 --- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java +++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java @@ -19,6 +19,10 @@ package org.springframework.cloud.zookeeper.discovery; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.x.discovery.ServiceDiscovery; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -32,6 +36,7 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.ClassUtils; /** * @author Spencer Gibb @@ -81,3 +86,21 @@ public class ZookeeperDiscoveryAutoConfiguration { } } + +class ZookeeperDiscoveryHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + if (!ClassUtils.isPresent("org.apache.zookeeper.ZooKeeper", classLoader)) { + return; + } + hints.reflection() + .registerType(TypeReference.of(ZookeeperInstance.class), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_METHODS)); + hints.reflection().registerType(TypeReference.of(ZookeeperServiceInstance.class), + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + } +} + diff --git a/spring-cloud-zookeeper-discovery/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-zookeeper-discovery/src/main/resources/META-INF/spring/aot.factories new file mode 100644 index 00000000..cd162f1b --- /dev/null +++ b/spring-cloud-zookeeper-discovery/src/main/resources/META-INF/spring/aot.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar=\ +org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryHints \ No newline at end of file diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 02a33e7b..6a8d857d 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -3,5 +3,5 @@ "-//Puppy Crawl//DTD Suppressions 1.1//EN" "https://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> - + \ No newline at end of file