Exclude local and anonymous classes from AOT type inspection.

Also update the type filter that would not mach types directly present in the given package.
Modify type contribution method to allow store specific override.

Closes: #2744
Original pull request: #2746
This commit is contained in:
Christoph Strobl
2022-12-06 14:41:59 +01:00
committed by Mark Paluch
parent b417268fb6
commit 0e2fb7e108
3 changed files with 15 additions and 8 deletions

View File

@@ -82,11 +82,11 @@ public class RepositoryRegistrationAotProcessor implements BeanRegistrationAotPr
repositoryContext.getResolvedTypes().stream()
.filter(it -> !RepositoryRegistrationAotContribution.isJavaOrPrimitiveType(it))
.forEach(it -> RepositoryRegistrationAotProcessor.contributeType(it, generationContext));
.forEach(it -> contributeType(it, generationContext));
repositoryContext.getResolvedAnnotations().stream()
.filter(RepositoryRegistrationAotProcessor::isSpringDataManagedAnnotation).map(MergedAnnotation::getType)
.forEach(it -> RepositoryRegistrationAotProcessor.contributeType(it, generationContext));
.forEach(it -> contributeType(it, generationContext));
}
private boolean isRepositoryBean(RegisteredBean bean) {
@@ -167,7 +167,7 @@ public class RepositoryRegistrationAotProcessor implements BeanRegistrationAotPr
|| annotation.getMetaTypes().stream().anyMatch(RepositoryRegistrationAotProcessor::isInSpringDataNamespace));
}
private static void contributeType(Class<?> type, GenerationContext generationContext) {
protected void contributeType(Class<?> type, GenerationContext generationContext) {
TypeContributor.contribute(type, it -> true, generationContext);
}

View File

@@ -48,16 +48,18 @@ public class TypeCollector {
private static final Log logger = LogFactory.getLog(TypeCollector.class);
static final Set<String> EXCLUDED_DOMAINS = new HashSet<>(Arrays.asList("java", "sun.", "jdk.", "reactor.",
"kotlinx.", "kotlin.", "org.springframework.core.", "org.springframework.data.mapping.",
"org.springframework.data.repository.", "org.springframework.boot.", "org.springframework.core."));
static final Set<String> EXCLUDED_DOMAINS = new HashSet<>(
Arrays.asList("java", "sun.", "jdk.", "reactor.", "kotlinx.", "kotlin.", "org.springframework.core.",
"org.springframework.data.mapping.", "org.springframework.data.repository.", "org.springframework.boot.",
"org.springframework.context.", "org.springframework.beans."));
private final Predicate<Class<?>> excludedDomainsFilter = type -> {
String packageName = type.getPackageName();
String packageName = type.getPackageName() + ".";
return EXCLUDED_DOMAINS.stream().noneMatch(packageName::startsWith);
};
private Predicate<Class<?>> typeFilter = excludedDomainsFilter;
private Predicate<Class<?>> typeFilter = excludedDomainsFilter
.and(it -> !it.isLocalClass() && !it.isAnonymousClass());
private final Predicate<Method> methodFilter = createMethodFilter();

View File

@@ -61,4 +61,9 @@ public class TypeCollectorUnitTests {
WithDeclaredClass.SomeEnum.class);
}
@Test // GH-2744
void skipsCoreFrameworkType() {
assertThat(TypeCollector.inspect(org.springframework.core.AliasRegistry.class).list()).isEmpty();
}
}