From 193c1d7acf1a9534dcd472f1a6f606df50cb4cdc Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 26 Jul 2022 18:06:35 +0200 Subject: [PATCH] Adapt to changes in DefaultGenerationContext See https://github.com/spring-projects/spring-framework/issues/28877 --- .../ChildManagementContextInitializerAotTests.java | 10 +++------- .../java/org/springframework/boot/AotProcessor.java | 4 ++-- .../org/springframework/boot/AotProcessorTests.java | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java index ce8a6bb79e8..a71bb0ff415 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java @@ -25,9 +25,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.aot.generate.ClassNameGenerator; -import org.springframework.aot.generate.DefaultGenerationContext; -import org.springframework.aot.generate.InMemoryGeneratedFiles; import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; @@ -45,6 +42,7 @@ import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.aot.ApplicationContextAotGenerator; import org.springframework.context.support.GenericApplicationContext; import org.springframework.javapoet.ClassName; +import org.springframework.test.aot.generate.TestGenerationContext; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.StringUtils; @@ -76,14 +74,12 @@ class ChildManagementContextInitializerAotTests { ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class, EndpointAutoConfiguration.class)); contextRunner.withPropertyValues("server.port=0", "management.server.port=0").prepare((context) -> { - InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); - DefaultGenerationContext generationContext = new DefaultGenerationContext( - new ClassNameGenerator(TestTarget.class), generatedFiles); + TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class); ClassName className = new ApplicationContextAotGenerator().generateApplicationContext( (GenericApplicationContext) context.getSourceApplicationContext(), generationContext); generationContext.writeGeneratedContent(); TestCompiler compiler = TestCompiler.forSystem(); - compiler.withFiles(generatedFiles).compile((compiled) -> { + compiler.withFiles(generationContext.getGeneratedFiles()).compile((compiled) -> { ServletWebServerApplicationContext freshApplicationContext = new ServletWebServerApplicationContext(); TestPropertyValues.of("server.port=0", "management.server.port=0").applyTo(freshApplicationContext); ApplicationContextInitializer initializer = compiled diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java index 9cc5b8470dc..264fe63f43a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java @@ -101,7 +101,7 @@ public class AotProcessor { /** * Trigger the processing of the application managed by this instance. */ - public void process() { + public void process() throws IOException { deleteExistingOutput(); AotProcessorHook hook = new AotProcessorHook(); SpringApplicationHooks.withHook(hook, this::callApplicationMainMethod); @@ -142,7 +142,7 @@ public class AotProcessor { } } - private void performAotProcessing(GenericApplicationContext applicationContext) { + private void performAotProcessing(GenericApplicationContext applicationContext) throws IOException { FileSystemGeneratedFiles generatedFiles = new FileSystemGeneratedFiles(this::getRoot); DefaultGenerationContext generationContext = new DefaultGenerationContext( new ClassNameGenerator(this.application), generatedFiles); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/AotProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/AotProcessorTests.java index 30ffabee4cb..fe60cbc29ff 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/AotProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/AotProcessorTests.java @@ -45,7 +45,7 @@ class AotProcessorTests { } @Test - void processApplicationInvokesRunMethod(@TempDir Path directory) { + void processApplicationInvokesRunMethod(@TempDir Path directory) throws IOException { String[] arguments = new String[] { "1", "2" }; AotProcessor processor = new AotProcessor(SampleApplication.class, arguments, directory.resolve("source"), directory.resolve("resource"), directory.resolve("class"), "com.example", "example");