Add RuntimeHints for Core classes
Closes gh-699
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
2
core/src/main/resources/META-INF/spring/aot.factories
Normal file
2
core/src/main/resources/META-INF/spring/aot.factories
Normal file
@@ -0,0 +1,2 @@
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.ldap.aot.hint.LdapCoreRuntimeHints
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user