Skip to content

Commit

Permalink
Use AbstractAotProcessor.AOT_PROCESSING instead of duplicate constant
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Oct 18, 2024
1 parent 5806915 commit b7979cf
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Stop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.core.log.LogMessage;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -95,7 +96,7 @@ class DockerComposeLifecycleManager {
}

void start() {
if (Boolean.getBoolean("spring.aot.processing") || AotDetector.useGeneratedArtifacts()) {
if (Boolean.getBoolean(AbstractAotProcessor.AOT_PROCESSING) || AotDetector.useGeneratedArtifacts()) {
logger.trace("Docker Compose support disabled with AOT and native images");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.FileCopyUtils;

Expand Down Expand Up @@ -126,7 +127,7 @@ void startWhenEnabledFalseDoesNotStart() {

@Test
void startWhenAotProcessingDoesNotStart() {
withSystemProperty("spring.aot.processing", "true", () -> {
withSystemProperty(AbstractAotProcessor.AOT_PROCESSING, "true", () -> {
EventCapturingListener listener = new EventCapturingListener();
this.eventListeners.add(listener);
setUpRunningServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.context.ApplicationListener;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.log.LogMessage;
Expand Down Expand Up @@ -103,7 +104,7 @@ else if (this.startables.get() == Startables.STARTED) {
}

private boolean isAotProcessingInProgress() {
return Boolean.getBoolean("spring.aot.processing");
return Boolean.getBoolean(AbstractAotProcessor.AOT_PROCESSING);
}

private void initializeStartables(Startable startableBean, String startableBeanName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
import org.testcontainers.containers.Container;

import org.springframework.boot.origin.Origin;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.test.context.ContextConfigurationAttributes;
Expand Down Expand Up @@ -96,7 +97,7 @@ private Object getFieldValue(Field field) {
}

private boolean isAotProcessingInProgress() {
return Boolean.getBoolean("spring.aot.processing");
return Boolean.getBoolean(AbstractAotProcessor.AOT_PROCESSING);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.env.MapPropertySource;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -149,7 +150,7 @@ void doesNotStartContainersWhenAotProcessingIsInProgress() {
GenericContainer<?> container = mock(GenericContainer.class);
AnnotationConfigApplicationContext applicationContext = createApplicationContext(container);
then(container).shouldHaveNoInteractions();
withSystemProperty("spring.aot.processing", "true",
withSystemProperty(AbstractAotProcessor.AOT_PROCESSING, "true",
() -> applicationContext.refreshForAotProcessing(new RuntimeHints()));
then(container).shouldHaveNoInteractions();
applicationContext.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.CollectionFactory;
import org.springframework.core.NativeDetector;
import org.springframework.core.io.ByteArrayResource;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void processModel(Model model) {
}

private boolean isAotProcessingInProgress() {
return Boolean.getBoolean("spring.aot.processing");
return Boolean.getBoolean(AbstractAotProcessor.AOT_PROCESSING);
}

static final class LogbackConfigurationAotContribution implements BeanFactoryInitializationAotContribution {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.springframework.aot.test.generate.TestGenerationContext;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
import org.springframework.boot.logging.logback.SpringBootJoranConfigurator.LogbackConfigurationAotContribution;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.io.InputStreamSource;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -287,7 +288,7 @@ private void applyContribution(Model model, Consumer<LoggerContext> contextCusto
contextCustomizer.accept(context);
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(null);
configurator.setContext(context);
withSystemProperty("spring.aot.processing", "true", () -> configurator.processModel(model));
withSystemProperty(AbstractAotProcessor.AOT_PROCESSING, "true", () -> configurator.processModel(model));
LogbackConfigurationAotContribution contribution = (LogbackConfigurationAotContribution) context
.getObject(BeanFactoryInitializationAotContribution.class.getName());
contribution.applyTo(generationContext, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.context.support.TestPropertySourceUtils;

Expand Down Expand Up @@ -221,7 +222,7 @@ void springPropertyInInclude() throws Exception {

@Test
void addsAotContributionToContextDuringAotProcessing() throws Exception {
withSystemProperty("spring.aot.processing", "true", () -> {
withSystemProperty(AbstractAotProcessor.AOT_PROCESSING, "true", () -> {
initialize("property.xml");
Object contribution = this.context.getObject(BeanFactoryInitializationAotContribution.class.getName());
assertThat(contribution).isNotNull();
Expand Down
1 change: 1 addition & 0 deletions src/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!-- Logging -->
<subpackage name="logging">
<allow pkg="org.springframework.boot.context.properties.bind" />
<allow pkg="org.springframework.context.aot" />
<disallow pkg="org.springframework.context" />
<disallow pkg="org.springframework.boot.context" />
</subpackage>
Expand Down

0 comments on commit b7979cf

Please sign in to comment.