Skip to content

Commit

Permalink
Rename ApplicationContextAotGenerator entry point
Browse files Browse the repository at this point in the history
Closes gh-28927
  • Loading branch information
snicoll committed Aug 5, 2022
1 parent 2475523 commit 2cc4486
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void testCompiledResult(GenericApplicationContext applicationContext,
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setup() {
void shouldProcessRegistrarOnConfiguration() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithHints.class);
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
Expand All @@ -72,7 +72,7 @@ void shouldProcessRegistrarOnConfiguration() {
void shouldProcessRegistrarOnBeanMethod() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithBeanDeclaringHints.class);
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
Expand All @@ -82,7 +82,7 @@ void shouldProcessRegistrarInSpringFactory() {
GenericApplicationContext applicationContext = createApplicationContext();
applicationContext.setClassLoader(
new TestSpringFactoriesClassLoader("test-runtime-hints-aot.factories"));
this.generator.generateApplicationContext(applicationContext,
this.generator.processAheadOfTime(applicationContext,
this.generationContext);
assertThatSampleRegistrarContributed();
}
Expand All @@ -97,7 +97,7 @@ void shouldProcessDuplicatedRegistrarsOnlyOnce() {
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))
Expand All @@ -109,7 +109,7 @@ void shouldProcessDuplicatedRegistrarsOnlyOnce() {
void shouldRejectRuntimeHintsRegistrarWithoutDefaultConstructor() {
GenericApplicationContext applicationContext = createApplicationContext(
ConfigurationWithIllegalRegistrar.class);
assertThatThrownBy(() -> this.generator.generateApplicationContext(
assertThatThrownBy(() -> this.generator.processAheadOfTime(
applicationContext, this.generationContext))
.isInstanceOf(BeanInstantiationException.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
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);
Expand Down

0 comments on commit 2cc4486

Please sign in to comment.