diff --git a/core/src/main/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHints.java b/core/src/main/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHints.java new file mode 100644 index 00000000..04a5cd09 --- /dev/null +++ b/core/src/main/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHints.java @@ -0,0 +1,28 @@ +package org.springframework.ldap.aot.hint; + +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.ldap.core.support.AbstractContextSource; +import org.springframework.ldap.core.support.DefaultDirObjectFactory; + +/** + * A {@link RuntimeHintsRegistrar} for LDAP Core classes + * + * @author Marcus Da Coregio + * @since 3.0 + */ +class LdapCoreRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + hints.reflection().registerType(TypeReference.of("com.sun.jndi.ldap.LdapCtxFactory"), + (builder) -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); + hints.reflection().registerType(AbstractContextSource.class, (builder) -> builder + .withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); + hints.reflection().registerType(DefaultDirObjectFactory.class, + (builder) -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); + } + +} diff --git a/core/src/main/resources/META-INF/spring/aot.factories b/core/src/main/resources/META-INF/spring/aot.factories new file mode 100644 index 00000000..ae69601f --- /dev/null +++ b/core/src/main/resources/META-INF/spring/aot.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar=\ +org.springframework.ldap.aot.hint.LdapCoreRuntimeHints diff --git a/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java b/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java new file mode 100644 index 00000000..9e51dfc7 --- /dev/null +++ b/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java @@ -0,0 +1,49 @@ +package org.springframework.ldap.aot.hint; + +import org.junit.Before; +import org.junit.Test; + +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.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.ldap.core.support.AbstractContextSource; +import org.springframework.ldap.core.support.DefaultDirObjectFactory; +import org.springframework.util.ClassUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link LdapCoreRuntimeHints} + */ +public class LdapCoreRuntimeHintsTests { + + private final RuntimeHints hints = new RuntimeHints(); + + @Before + public void setup() { + SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories").load(RuntimeHintsRegistrar.class) + .forEach((registrar) -> registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader())); + } + + @Test + public void ldapCtxFactoryHasHints() { + assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("com.sun.jndi.ldap.LdapCtxFactory")).withMemberCategories(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) + .accepts(this.hints); + } + + @Test + public void abstractContextSourceHasHints() { + assertThat(RuntimeHintsPredicates.reflection().onType(AbstractContextSource.class).withMemberCategories(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)) + .accepts(this.hints); + } + + @Test + public void defaultDirObjectFactoryHasHints() { + assertThat(RuntimeHintsPredicates.reflection().onType(DefaultDirObjectFactory.class).withMemberCategories(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) + .accepts(this.hints); + } + +}