Browse Source

Rename ApplicationContextAotGenerator entry point

Closes gh-28927
pull/28937/head
Stephane Nicoll 2 years ago
parent
commit
2cc4486e3d
  1. 11
      spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java
  2. 2
      spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java
  3. 10
      spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java
  4. 2
      spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java

11
spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java

@ -36,14 +36,15 @@ import org.springframework.javapoet.ClassName; @@ -36,14 +36,15 @@ import org.springframework.javapoet.ClassName;
public class ApplicationContextAotGenerator {
/**
* Refresh the specified {@link GenericApplicationContext} and generate the
* necessary code to restore the state of its {@link BeanFactory}, using the
* specified {@link GenerationContext}.
* @param applicationContext the application context to handle
* Process the specified {@link GenericApplicationContext} instance
* ahead-of-time using the specified {@link GenerationContext}.
* <p>Return the {@link ClassName} of the {@link ApplicationContextInitializer}
* to use to restore an optimized state of the application context.
* @param applicationContext the non-refreshed application context to handle
* @param generationContext the generation context to use
* @return the class name of the {@link ApplicationContextInitializer} entry point
*/
public ClassName generateApplicationContext(GenericApplicationContext applicationContext,
public ClassName processAheadOfTime(GenericApplicationContext applicationContext,
GenerationContext generationContext) {
applicationContext.refreshForAotProcessing();
DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory();

2
spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java

@ -186,7 +186,7 @@ class ApplicationContextAotGeneratorTests { @@ -186,7 +186,7 @@ class ApplicationContextAotGeneratorTests {
BiConsumer<ApplicationContextInitializer<GenericApplicationContext>, Compiled> result) {
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
TestGenerationContext generationContext = new TestGenerationContext();
generator.generateApplicationContext(applicationContext, generationContext);
generator.processAheadOfTime(applicationContext, generationContext);
generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
result.accept(compiled.getInstance(ApplicationContextInitializer.class), compiled));

10
spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java

@ -63,7 +63,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { @@ -63,7 +63,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
void shouldProcessRegistrarOnConfiguration() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithHints.class);
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
@ -72,7 +72,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { @@ -72,7 +72,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
void shouldProcessRegistrarOnBeanMethod() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithBeanDeclaringHints.class);
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
@ -82,7 +82,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { @@ -82,7 +82,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
GenericApplicationContext applicationContext = createApplicationContext();
applicationContext.setClassLoader(
new TestSpringFactoriesClassLoader("test-runtime-hints-aot.factories"));
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
@ -97,7 +97,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { @@ -97,7 +97,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
applicationContext.setClassLoader(
new TestSpringFactoriesClassLoader("test-duplicated-runtime-hints-aot.factories"));
IncrementalRuntimeHintsRegistrar.counter.set(0);
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
RuntimeHints runtimeHints = this.generationContext.getRuntimeHints();
assertThat(runtimeHints.resources().resourceBundles().map(ResourceBundleHint::getBaseName))
@ -109,7 +109,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { @@ -109,7 +109,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
void shouldRejectRuntimeHintsRegistrarWithoutDefaultConstructor() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithIllegalRegistrar.class);
assertThatThrownBy(() -> this.generator.generateApplicationContext(
assertThatThrownBy(() -> this.generator.processAheadOfTime(
applicationContext, this.generationContext))
.isInstanceOf(BeanInstantiationException.class);
}

2
spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java

@ -109,7 +109,7 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { @@ -109,7 +109,7 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
private void compile(GenericApplicationContext applicationContext, BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) {
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
TestGenerationContext generationContext = new TestGenerationContext();
generator.generateApplicationContext(applicationContext, generationContext);
generator.processAheadOfTime(applicationContext, generationContext);
generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled -> {
ApplicationContextInitializer instance = compiled.getInstance(ApplicationContextInitializer.class);

Loading…
Cancel
Save