Skip to content

Commit 103d41f

Browse files
committed
Resolve package cycle between repository and aot packages.
Closes #2707
1 parent 0fe04e3 commit 103d41f

15 files changed

+87
-78
lines changed

src/main/java/org/springframework/data/aot/AuditingBeanRegistrationAotProcessor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.springframework.core.DecoratingProxy;
2626
import org.springframework.data.domain.AuditorAware;
2727
import org.springframework.data.domain.ReactiveAuditorAware;
28-
import org.springframework.data.repository.util.ReactiveWrappers;
29-
import org.springframework.data.repository.util.ReactiveWrappers.ReactiveLibrary;
3028
import org.springframework.lang.Nullable;
3129
import org.springframework.util.ClassUtils;
3230

@@ -40,6 +38,9 @@
4038
*/
4139
class AuditingBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
4240

41+
private static final boolean PROJECT_REACTOR_PRESENT = ClassUtils.isPresent("reactor.core.publisher.Flux",
42+
AuditingBeanRegistrationAotProcessor.class.getClassLoader());
43+
4344
@Nullable
4445
@Override
4546
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
@@ -49,7 +50,7 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
4950
generationContext.getRuntimeHints());
5051
}
5152

52-
if (ReactiveWrappers.isAvailable(ReactiveLibrary.PROJECT_REACTOR) && isReactiveAuditorAware(registeredBean)) {
53+
if (PROJECT_REACTOR_PRESENT && isReactiveAuditorAware(registeredBean)) {
5354
return (generationContext, beanRegistrationCode) -> registerSpringProxy(ReactiveAuditorAware.class,
5455
generationContext.getRuntimeHints());
5556
}

src/main/java/org/springframework/data/aot/AotRepositoryContext.java renamed to src/main/java/org/springframework/data/repository/aot/AotRepositoryContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.Set;
2020

2121
import org.springframework.core.annotation.MergedAnnotation;
22+
import org.springframework.data.aot.AotContext;
2223
import org.springframework.data.repository.core.RepositoryInformation;
2324

2425
/**

src/main/java/org/springframework/data/aot/AotRepositoryInformation.java renamed to src/main/java/org/springframework/data/repository/aot/AotRepositoryInformation.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.lang.reflect.Method;
1919
import java.util.Collection;
@@ -43,29 +43,29 @@ class AotRepositoryInformation extends RepositoryInformationSupport implements R
4343
this.fragments = fragments;
4444
}
4545

46+
/**
47+
* @return configured repository fragments.
48+
* @since 3.0
49+
*/
50+
@Override
51+
public Set<RepositoryFragment<?>> getFragments() {
52+
return new LinkedHashSet<>(fragments.get());
53+
}
54+
55+
// Not required during AOT processing.
4656
@Override
4757
public boolean isCustomMethod(Method method) {
48-
// TODO:
4958
return false;
5059
}
5160

5261
@Override
5362
public boolean isBaseClassMethod(Method method) {
54-
// TODO
5563
return false;
5664
}
5765

5866
@Override
5967
public Method getTargetClassMethod(Method method) {
60-
// TODO
6168
return method;
6269
}
6370

64-
/**
65-
* @return configured repository fragments.
66-
* @since 3.0
67-
*/
68-
public Set<RepositoryFragment<?>> getFragments() {
69-
return new LinkedHashSet<>(fragments.get());
70-
}
7171
}

src/main/java/org/springframework/data/aot/DefaultAotRepositoryContext.java renamed to src/main/java/org/springframework/data/repository/aot/DefaultAotRepositoryContext.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.LinkedHashSet;
@@ -22,6 +22,9 @@
2222

2323
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2424
import org.springframework.core.annotation.MergedAnnotation;
25+
import org.springframework.data.aot.AotContext;
26+
import org.springframework.data.aot.TypeCollector;
27+
import org.springframework.data.aot.TypeUtils;
2528
import org.springframework.data.repository.core.RepositoryInformation;
2629
import org.springframework.data.util.Lazy;
2730

@@ -104,12 +107,12 @@ public Set<Class<?>> getResolvedTypes() {
104107
}
105108

106109
@Override
107-
public TypeIntrospector introspectType(String typeName) {
110+
public AotContext.TypeIntrospector introspectType(String typeName) {
108111
return aotContext.introspectType(typeName);
109112
}
110113

111114
@Override
112-
public IntrospectedBeanDefinition introspectBeanDefinition(String beanName) {
115+
public AotContext.IntrospectedBeanDefinition introspectBeanDefinition(String beanName) {
113116
return aotContext.introspectBeanDefinition(beanName);
114117
}
115118

src/main/java/org/springframework/data/aot/RepositoryBeanDefinitionReader.java renamed to src/main/java/org/springframework/data/repository/aot/RepositoryBeanDefinitionReader.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.util.ArrayList;
1919
import java.util.Collection;
@@ -81,9 +81,8 @@ private static Supplier<Class<?>> repositoryBaseClass(RepositoryConfiguration me
8181
}));
8282
}
8383

84-
static Supplier<org.springframework.data.repository.core.RepositoryMetadata> metadataSupplier(
84+
private static Supplier<org.springframework.data.repository.core.RepositoryMetadata> metadataSupplier(
8585
RepositoryConfiguration<?> metadata, ConfigurableListableBeanFactory beanFactory) {
86-
8786
return Lazy.of(() -> new DefaultRepositoryMetadata(forName(metadata.getRepositoryInterface(), beanFactory)));
8887
}
8988

src/main/java/org/springframework/data/aot/RepositoryRegistrationAotContribution.java renamed to src/main/java/org/springframework/data/repository/aot/RepositoryRegistrationAotContribution.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.io.Serializable;
1919
import java.lang.annotation.Annotation;
@@ -41,7 +41,9 @@
4141
import org.springframework.core.DecoratingProxy;
4242
import org.springframework.core.ResolvableType;
4343
import org.springframework.core.annotation.AnnotationUtils;
44-
import org.springframework.core.annotation.MergedAnnotation;
44+
import org.springframework.data.aot.AotContext;
45+
import org.springframework.data.aot.TypeContributor;
46+
import org.springframework.data.aot.TypeUtils;
4547
import org.springframework.data.projection.EntityProjectionIntrospector;
4648
import org.springframework.data.projection.TargetAware;
4749
import org.springframework.data.repository.Repository;
@@ -73,7 +75,7 @@ public class RepositoryRegistrationAotContribution implements BeanRegistrationAo
7375
* which this contribution was created.
7476
* @return a new instance of {@link RepositoryRegistrationAotContribution}.
7577
* @throws IllegalArgumentException if the {@link RepositoryRegistrationAotProcessor} is {@literal null}.
76-
* @see org.springframework.data.aot.RepositoryRegistrationAotProcessor
78+
* @see RepositoryRegistrationAotProcessor
7779
*/
7880
public static RepositoryRegistrationAotContribution fromProcessor(
7981
RepositoryRegistrationAotProcessor repositoryRegistrationAotProcessor) {
@@ -94,7 +96,7 @@ public static RepositoryRegistrationAotContribution fromProcessor(
9496
* @param repositoryRegistrationAotProcessor reference back to the {@link RepositoryRegistrationAotProcessor} from
9597
* which this contribution was created.
9698
* @throws IllegalArgumentException if the {@link RepositoryRegistrationAotProcessor} is {@literal null}.
97-
* @see org.springframework.data.aot.RepositoryRegistrationAotProcessor
99+
* @see RepositoryRegistrationAotProcessor
98100
*/
99101
protected RepositoryRegistrationAotContribution(
100102
RepositoryRegistrationAotProcessor repositoryRegistrationAotProcessor) {
@@ -232,10 +234,6 @@ protected void enhanceRepositoryBeanDefinition(RegisteredBean repositoryBean,
232234
}
233235
}
234236

235-
private boolean isRepositoryWithTypeParameters(ResolvableType type) {
236-
return type.getGenerics().length == 3;
237-
}
238-
239237
/**
240238
* {@link BiConsumer Callback} for data module specific contributions.
241239
*
@@ -380,24 +378,14 @@ static boolean isJavaOrPrimitiveType(Class<?> type) {
380378
|| ClassUtils.isPrimitiveArray(type); //
381379
}
382380

383-
static boolean isSpringDataManagedAnnotation(@Nullable MergedAnnotation<?> annotation) {
384-
385-
return annotation != null && (isInSpringDataNamespace(annotation.getType())
386-
|| annotation.getMetaTypes().stream().anyMatch(RepositoryRegistrationAotContribution::isInSpringDataNamespace));
387-
}
388-
389-
static boolean isInSpringDataNamespace(Class<?> type) {
390-
return type.getPackage().getName().startsWith(TypeContributor.DATA_NAMESPACE);
391-
}
392-
393-
static void contributeType(Class<?> type, GenerationContext generationContext) {
394-
TypeContributor.contribute(type, it -> true, generationContext);
395-
}
396-
397381
// TODO What was this meant to be used for? Was this type filter maybe meant to be used in
398382
// the TypeContributor.contribute(:Class, :Predicate :GenerationContext) method
399383
// used in the contributeType(..) method above?
400384
public Predicate<Class<?>> typeFilter() { // like only document ones. // TODO: As in MongoDB?
401385
return it -> true;
402386
}
387+
388+
private static boolean isRepositoryWithTypeParameters(ResolvableType type) {
389+
return type.getGenerics().length == 3;
390+
}
403391
}

src/main/java/org/springframework/data/aot/RepositoryRegistrationAotProcessor.java renamed to src/main/java/org/springframework/data/repository/aot/RepositoryRegistrationAotProcessor.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.repository.aot;
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.Collections;
@@ -35,6 +35,7 @@
3535
import org.springframework.beans.factory.support.RegisteredBean;
3636
import org.springframework.beans.factory.support.RootBeanDefinition;
3737
import org.springframework.core.annotation.MergedAnnotation;
38+
import org.springframework.data.aot.TypeContributor;
3839
import org.springframework.data.repository.config.RepositoryConfiguration;
3940
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
4041
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
@@ -83,11 +84,11 @@ protected void contribute(AotRepositoryContext repositoryContext, GenerationCont
8384

8485
repositoryContext.getResolvedTypes().stream()
8586
.filter(it -> !RepositoryRegistrationAotContribution.isJavaOrPrimitiveType(it))
86-
.forEach(it -> RepositoryRegistrationAotContribution.contributeType(it, generationContext));
87+
.forEach(it -> RepositoryRegistrationAotProcessor.contributeType(it, generationContext));
8788

8889
repositoryContext.getResolvedAnnotations().stream()
89-
.filter(RepositoryRegistrationAotContribution::isSpringDataManagedAnnotation).map(MergedAnnotation::getType)
90-
.forEach(it -> RepositoryRegistrationAotContribution.contributeType(it, generationContext));
90+
.filter(RepositoryRegistrationAotProcessor::isSpringDataManagedAnnotation).map(MergedAnnotation::getType)
91+
.forEach(it -> RepositoryRegistrationAotProcessor.contributeType(it, generationContext));
9192
}
9293

9394
private boolean isRepositoryBean(RegisteredBean bean) {
@@ -161,4 +162,18 @@ protected void logDebug(String message, Object... arguments) {
161162
protected void logTrace(String message, Object... arguments) {
162163
logAt(Log::isTraceEnabled, Log::trace, message, arguments);
163164
}
165+
166+
private static boolean isSpringDataManagedAnnotation(@Nullable MergedAnnotation<?> annotation) {
167+
168+
return annotation != null && (isInSpringDataNamespace(annotation.getType())
169+
|| annotation.getMetaTypes().stream().anyMatch(RepositoryRegistrationAotProcessor::isInSpringDataNamespace));
170+
}
171+
172+
private static void contributeType(Class<?> type, GenerationContext generationContext) {
173+
TypeContributor.contribute(type, it -> true, generationContext);
174+
}
175+
176+
private static boolean isInSpringDataNamespace(Class<?> type) {
177+
return type.getPackage().getName().startsWith(TypeContributor.DATA_NAMESPACE);
178+
}
164179
}

src/main/java/org/springframework/data/aot/hint/RepositoryRuntimeHints.java renamed to src/main/java/org/springframework/data/repository/aot/hint/RepositoryRuntimeHints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot.hint;
16+
package org.springframework.data.repository.aot.hint;
1717

1818
import java.util.Arrays;
1919
import java.util.Properties;

src/main/java/org/springframework/data/aot/hint/package-info.java renamed to src/main/java/org/springframework/data/repository/aot/hint/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* Predefined Runtime Hints.
33
*/
44
@org.springframework.lang.NonNullApi
5-
package org.springframework.data.aot.hint;
5+
package org.springframework.data.repository.aot.hint;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Support for processing of repositories with Ahead of Time compilation.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
package org.springframework.data.repository.aot;

0 commit comments

Comments
 (0)