Expose a system property when AOT processing is running

This commit exposes a "spring.aot.processing" system property when the
AOT engine is running. This can be used by code that need to react
differently when the application is being refreshed for AOT processing.

Closes gh-29340
This commit is contained in:
Stephane Nicoll
2022-10-18 16:57:47 +02:00
parent 004875670b
commit 82a0154bd1
4 changed files with 59 additions and 9 deletions

View File

@@ -27,13 +27,26 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link AbstractAotProcessor}, settings, and builder.
* Tests for {@link AbstractAotProcessor}.
*
* @author Sam Brannen
* @author Stephane Nicoll
* @since 6.0
*/
class AotProcessorTests {
@Test
void springAotProcessingIsAvailableInDoProcess(@TempDir Path tempDir) {
Settings settings = createTestSettings(tempDir);
assertThat(new AbstractAotProcessor<String>(settings) {
@Override
protected String doProcess() {
assertThat(System.getProperty("spring.aot.processing")).isEqualTo("true");
return "Hello";
}
}.process()).isEqualTo("Hello");
}
@Test
void builderRejectsMissingSourceOutput() {
assertThatIllegalArgumentException()
@@ -123,4 +136,14 @@ class AotProcessorTests {
assertThat(settings.getArtifactId()).isEqualTo("my-artifact");
}
private static Settings createTestSettings(Path tempDir) {
return Settings.builder()
.sourceOutput(tempDir)
.resourceOutput(tempDir)
.classOutput(tempDir)
.groupId("my-group")
.artifactId("my-artifact")
.build();
}
}