Skip to content

Commit 3702c71

Browse files
snicollbclozel
authored andcommitted
Adapt to Spring AOT changes
1 parent d478a02 commit 3702c71

File tree

11 files changed

+29
-30
lines changed

11 files changed

+29
-30
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import org.springframework.aot.AotDetector;
2929
import org.springframework.aot.test.generate.TestGenerationContext;
30-
import org.springframework.aot.test.generate.compile.CompileWithTargetClassAccess;
31-
import org.springframework.aot.test.generate.compile.TestCompiler;
3230
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
3331
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
3432
import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration;
@@ -43,6 +41,8 @@
4341
import org.springframework.context.ApplicationContextInitializer;
4442
import org.springframework.context.aot.ApplicationContextAotGenerator;
4543
import org.springframework.context.support.GenericApplicationContext;
44+
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
45+
import org.springframework.core.test.tools.TestCompiler;
4646
import org.springframework.javapoet.ClassName;
4747
import org.springframework.test.util.ReflectionTestUtils;
4848
import org.springframework.util.StringUtils;
@@ -65,7 +65,7 @@ void reset() {
6565
}
6666

6767
@Test
68-
@CompileWithTargetClassAccess
68+
@CompileWithForkedClassLoader
6969
@SuppressWarnings("unchecked")
7070
void aotContributedInitializerStartsManagementContext(CapturedOutput output) {
7171
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
@@ -80,7 +80,7 @@ void aotContributedInitializerStartsManagementContext(CapturedOutput output) {
8080
(GenericApplicationContext) context.getSourceApplicationContext(), generationContext);
8181
generationContext.writeGeneratedContent();
8282
TestCompiler compiler = TestCompiler.forSystem();
83-
compiler.withFiles(generationContext.getGeneratedFiles()).compile((compiled) -> {
83+
compiler.with(generationContext).compile((compiled) -> {
8484
ServletWebServerApplicationContext freshApplicationContext = new ServletWebServerApplicationContext();
8585
TestPropertyValues.of("server.port=0", "management.server.port=0").applyTo(freshApplicationContext);
8686
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootContextLoaderAotTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
import org.springframework.aot.AotDetector;
2424
import org.springframework.aot.generate.InMemoryGeneratedFiles;
25-
import org.springframework.aot.test.generate.compile.CompileWithTargetClassAccess;
26-
import org.springframework.aot.test.generate.compile.TestCompiler;
25+
import org.springframework.aot.test.generate.CompilerFiles;
2726
import org.springframework.beans.factory.config.BeanDefinition;
2827
import org.springframework.beans.factory.support.GenericBeanDefinition;
2928
import org.springframework.boot.SpringBootConfiguration;
@@ -32,6 +31,8 @@
3231
import org.springframework.context.ConfigurableApplicationContext;
3332
import org.springframework.context.annotation.Import;
3433
import org.springframework.context.support.GenericApplicationContext;
34+
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
35+
import org.springframework.core.test.tools.TestCompiler;
3536
import org.springframework.test.context.BootstrapUtils;
3637
import org.springframework.test.context.MergedContextConfiguration;
3738
import org.springframework.test.context.TestContextBootstrapper;
@@ -49,7 +50,7 @@
4950
*
5051
* @author Phillip Webb
5152
*/
52-
@CompileWithTargetClassAccess
53+
@CompileWithForkedClassLoader
5354
class SpringBootContextLoaderAotTests {
5455

5556
@Test
@@ -58,7 +59,7 @@ void loadContextForAotProcessingAndAotRuntime() {
5859
TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles);
5960
Class<?> testClass = ExampleTest.class;
6061
generator.processAheadOfTime(Stream.of(testClass));
61-
TestCompiler.forSystem().withFiles(generatedFiles).printFiles(System.out)
62+
TestCompiler.forSystem().with(CompilerFiles.from(generatedFiles))
6263
.compile(ThrowingConsumer.of((compiled) -> assertCompiledTest(testClass)));
6364
}
6465

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void deleteExistingOutput(Path... paths) {
125125
private void performAotProcessing(GenericApplicationContext applicationContext) {
126126
FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this::getRoot);
127127
DefaultGenerationContext generationContext = new DefaultGenerationContext(
128-
new ClassNameGenerator(this.application), generatedFiles);
128+
new ClassNameGenerator(ClassName.get(this.application)), generatedFiles);
129129
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
130130
ClassName generatedInitializerClassName = generator.processAheadOfTime(applicationContext, generationContext);
131131
registerEntryPointHint(generationContext, generatedInitializerClassName);

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrationAotProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
2929
import org.springframework.beans.factory.aot.BeanRegistrationCode;
3030
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragments;
31+
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragmentsDecorator;
3132
import org.springframework.beans.factory.config.BeanDefinition;
3233
import org.springframework.beans.factory.support.InstanceSupplier;
3334
import org.springframework.beans.factory.support.RegisteredBean;
@@ -48,7 +49,7 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
4849
if (!isImmutableConfigurationPropertiesBeanDefinition(registeredBean.getMergedBeanDefinition())) {
4950
return null;
5051
}
51-
return BeanRegistrationAotContribution.ofBeanRegistrationCodeFragmentsCustomizer(
52+
return BeanRegistrationAotContribution.withCustomCodeFragments(
5253
(codeFragments) -> new ConfigurationPropertiesBeanRegistrationCodeFragments(codeFragments,
5354
registeredBean));
5455

@@ -59,7 +60,8 @@ private boolean isImmutableConfigurationPropertiesBeanDefinition(BeanDefinition
5960
&& BindMethod.VALUE_OBJECT.equals(beanDefinition.getAttribute(BindMethod.class.getName()));
6061
}
6162

62-
private static class ConfigurationPropertiesBeanRegistrationCodeFragments extends BeanRegistrationCodeFragments {
63+
private static class ConfigurationPropertiesBeanRegistrationCodeFragments
64+
extends BeanRegistrationCodeFragmentsDecorator {
6365

6466
private static final Predicate<String> INCLUDE_BIND_METHOD_ATTRIBUTE_FILTER = (name) -> name
6567
.equals(BindMethod.class.getName());

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/AotProcessorTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ private Consumer<Path> hasGeneratedAssetsForSampleApplication() {
110110
assertThat(directory.resolve(
111111
"source/org/springframework/boot/AotProcessorTests_SampleApplication__ApplicationContextInitializer.java"))
112112
.exists().isRegularFile();
113-
assertThat(directory.resolve(
114-
"source/org/springframework/boot/AotProcessorTests_SampleApplication__BeanDefinitions.java"))
115-
.exists().isRegularFile();
113+
assertThat(directory.resolve("source/org/springframework/boot/AotProcessorTests__BeanDefinitions.java"))
114+
.exists().isRegularFile();
116115
assertThat(directory.resolve(
117116
"source/org/springframework/boot/AotProcessorTests_SampleApplication__BeanFactoryRegistrations.java"))
118117
.exists().isRegularFile();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.boot.DefaultBootstrapContext;
3434
import org.springframework.boot.logging.DeferredLogFactory;
3535
import org.springframework.core.env.PropertySource;
36-
import org.springframework.core.mock.MockSpringFactoriesLoader;
36+
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
3737
import org.springframework.mock.env.MockPropertySource;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.springframework.core.Ordered;
3838
import org.springframework.core.annotation.Order;
3939
import org.springframework.core.io.DefaultResourceLoader;
40-
import org.springframework.core.mock.MockSpringFactoriesLoader;
40+
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
4141

4242
import static org.assertj.core.api.Assertions.assertThat;
4343
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationRuntimeHintsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.boot.env.PropertySourceLoader;
3030
import org.springframework.boot.env.YamlPropertySourceLoader;
3131
import org.springframework.core.io.support.SpringFactoriesLoader;
32-
import org.springframework.core.mock.MockSpringFactoriesLoader;
32+
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
3535

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626

2727
import org.junit.jupiter.api.Test;
2828

29-
import org.springframework.aot.generate.ClassNameGenerator;
30-
import org.springframework.aot.generate.DefaultGenerationContext;
3129
import org.springframework.aot.generate.GenerationContext;
32-
import org.springframework.aot.generate.InMemoryGeneratedFiles;
3330
import org.springframework.aot.hint.ExecutableHint;
3431
import org.springframework.aot.hint.RuntimeHints;
3532
import org.springframework.aot.hint.TypeHint;
3633
import org.springframework.aot.hint.TypeReference;
3734
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
35+
import org.springframework.aot.test.generate.TestGenerationContext;
3836
import org.springframework.beans.factory.aot.AotServices;
3937
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
4038
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
@@ -278,8 +276,7 @@ private RuntimeHints process(Class<?>... types) {
278276
private RuntimeHints process(ConfigurableListableBeanFactory beanFactory) {
279277
BeanFactoryInitializationAotContribution contribution = this.processor.processAheadOfTime(beanFactory);
280278
assertThat(contribution).isNotNull();
281-
GenerationContext generationContext = new DefaultGenerationContext(new ClassNameGenerator(Object.class),
282-
new InMemoryGeneratedFiles());
279+
GenerationContext generationContext = new TestGenerationContext();
283280
contribution.applyTo(generationContext, mock(BeanFactoryInitializationCode.class));
284281
return generationContext.getRuntimeHints();
285282
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrationAotProcessorTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.aot.test.generate.TestGenerationContext;
25-
import org.springframework.aot.test.generate.compile.CompileWithTargetClassAccess;
26-
import org.springframework.aot.test.generate.compile.TestCompiler;
2725
import org.springframework.beans.factory.aot.AotServices;
2826
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
2927
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
@@ -38,6 +36,8 @@
3836
import org.springframework.context.annotation.Configuration;
3937
import org.springframework.context.aot.ApplicationContextAotGenerator;
4038
import org.springframework.context.support.GenericApplicationContext;
39+
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
40+
import org.springframework.core.test.tools.TestCompiler;
4141
import org.springframework.javapoet.ClassName;
4242
import org.springframework.test.context.support.TestPropertySourceUtils;
4343

@@ -90,7 +90,7 @@ private BeanRegistrationAotContribution process(Class<?> type) {
9090
}
9191

9292
@Test
93-
@CompileWithTargetClassAccess
93+
@CompileWithForkedClassLoader
9494
void aotContributedInitializerBindsValueObject() {
9595
compile(createContext(ValueObjectSampleBeanConfiguration.class), (freshContext) -> {
9696
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "test.name=Hello");
@@ -101,7 +101,7 @@ void aotContributedInitializerBindsValueObject() {
101101
}
102102

103103
@Test
104-
@CompileWithTargetClassAccess
104+
@CompileWithForkedClassLoader
105105
void aotContributedInitializerBindsJavaBean() {
106106
compile(createContext(JavaBeanSampleBeanConfiguration.class), (freshContext) -> {
107107
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "test.name=Hello");
@@ -112,7 +112,7 @@ void aotContributedInitializerBindsJavaBean() {
112112
}
113113

114114
@Test
115-
@CompileWithTargetClassAccess
115+
@CompileWithForkedClassLoader
116116
void aotContributedInitializerBindsScannedValueObject() {
117117
compile(createContext(ScanTestConfiguration.class), (freshContext) -> {
118118
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "b.first.name=Hello");
@@ -123,7 +123,7 @@ void aotContributedInitializerBindsScannedValueObject() {
123123
}
124124

125125
@Test
126-
@CompileWithTargetClassAccess
126+
@CompileWithForkedClassLoader
127127
void aotContributedInitializerBindsScannedJavaBean() {
128128
compile(createContext(ScanTestConfiguration.class), (freshContext) -> {
129129
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "b.second.number=42");
@@ -145,7 +145,7 @@ private void compile(GenericApplicationContext context, Consumer<GenericApplicat
145145
TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class);
146146
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext);
147147
generationContext.writeGeneratedContent();
148-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile((compiled) -> {
148+
TestCompiler.forSystem().with(generationContext).compile((compiled) -> {
149149
GenericApplicationContext freshApplicationContext = new GenericApplicationContext();
150150
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
151151
.getInstance(ApplicationContextInitializer.class, className.toString());

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.context.EnvironmentAware;
2828
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2929
import org.springframework.core.env.Environment;
30-
import org.springframework.core.mock.MockSpringFactoriesLoader;
30+
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
3333
import static org.mockito.ArgumentMatchers.same;

0 commit comments

Comments
 (0)