Skip to content

Commit 15aab1f

Browse files
Add RuntimeHints for Core classes
Closes gh-699
1 parent 65dfead commit 15aab1f

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.springframework.ldap.aot.hint;
2+
3+
import org.springframework.aot.hint.MemberCategory;
4+
import org.springframework.aot.hint.RuntimeHints;
5+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
6+
import org.springframework.aot.hint.TypeReference;
7+
import org.springframework.ldap.core.support.AbstractContextSource;
8+
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
9+
10+
/**
11+
* A {@link RuntimeHintsRegistrar} for LDAP Core classes
12+
*
13+
* @author Marcus Da Coregio
14+
* @since 3.0
15+
*/
16+
class LdapCoreRuntimeHints implements RuntimeHintsRegistrar {
17+
18+
@Override
19+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
20+
hints.reflection().registerType(TypeReference.of("com.sun.jndi.ldap.LdapCtxFactory"),
21+
(builder) -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
22+
hints.reflection().registerType(AbstractContextSource.class, (builder) -> builder
23+
.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
24+
hints.reflection().registerType(DefaultDirObjectFactory.class,
25+
(builder) -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
26+
}
27+
28+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
org.springframework.ldap.aot.hint.LdapCoreRuntimeHints
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.springframework.ldap.aot.hint;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import org.springframework.aot.hint.MemberCategory;
7+
import org.springframework.aot.hint.RuntimeHints;
8+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
9+
import org.springframework.aot.hint.TypeReference;
10+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
11+
import org.springframework.core.io.support.SpringFactoriesLoader;
12+
import org.springframework.ldap.core.support.AbstractContextSource;
13+
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
14+
import org.springframework.util.ClassUtils;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
/**
19+
* Tests for {@link LdapCoreRuntimeHints}
20+
*/
21+
public class LdapCoreRuntimeHintsTests {
22+
23+
private final RuntimeHints hints = new RuntimeHints();
24+
25+
@Before
26+
public void setup() {
27+
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories").load(RuntimeHintsRegistrar.class)
28+
.forEach((registrar) -> registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
29+
}
30+
31+
@Test
32+
public void ldapCtxFactoryHasHints() {
33+
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("com.sun.jndi.ldap.LdapCtxFactory")).withMemberCategories(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
34+
.accepts(this.hints);
35+
}
36+
37+
@Test
38+
public void abstractContextSourceHasHints() {
39+
assertThat(RuntimeHintsPredicates.reflection().onType(AbstractContextSource.class).withMemberCategories(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS))
40+
.accepts(this.hints);
41+
}
42+
43+
@Test
44+
public void defaultDirObjectFactoryHasHints() {
45+
assertThat(RuntimeHintsPredicates.reflection().onType(DefaultDirObjectFactory.class).withMemberCategories(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
46+
.accepts(this.hints);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)