Skip to content

Commit

Permalink
Introduce failOnError flag in TestContextAotGenerator
Browse files Browse the repository at this point in the history
This commit introduces a `failOnError` flag in TestContextAotGenerator.
When set to `true`, any error encountered during AOT processing will
result in an exception that fails the overall process. When set to
`false` (the default), the previous behavior remains unchanged: a DEBUG
or WARN message will be logged, and processing will continue.

This feature is currently only used for internal testing.

See spring-projectsgh-30861
Closes spring-projectsgh-30898
  • Loading branch information
sbrannen committed Jul 15, 2023
1 parent 361344f commit 8b97d5f
Showing 1 changed file with 20 additions and 0 deletions.
Expand Up @@ -85,6 +85,8 @@ public class TestContextAotGenerator {

private final RuntimeHints runtimeHints;

private final boolean failOnError;


/**
* Create a new {@link TestContextAotGenerator} that uses the supplied
Expand All @@ -102,9 +104,23 @@ public TestContextAotGenerator(GeneratedFiles generatedFiles) {
* @param runtimeHints the {@code RuntimeHints} to use
*/
public TestContextAotGenerator(GeneratedFiles generatedFiles, RuntimeHints runtimeHints) {
this(generatedFiles, runtimeHints, false);
}

/**
* Create a new {@link TestContextAotGenerator} that uses the supplied
* {@link GeneratedFiles}, {@link RuntimeHints}, and {@code failOnError} flag.
* @param generatedFiles the {@code GeneratedFiles} to use
* @param runtimeHints the {@code RuntimeHints} to use
* @param failOnError {@code true} if errors encountered during AOT processing
* should result in an exception that fails the overall process
* @since 6.0.12
*/
TestContextAotGenerator(GeneratedFiles generatedFiles, RuntimeHints runtimeHints, boolean failOnError) {
this.testRuntimeHintsRegistrars = AotServices.factories().load(TestRuntimeHintsRegistrar.class);
this.generatedFiles = generatedFiles;
this.runtimeHints = runtimeHints;
this.failOnError = failOnError;
}


Expand Down Expand Up @@ -210,6 +226,10 @@ private MultiValueMap<ClassName, Class<?>> processAheadOfTime(
generationContext.writeGeneratedContent();
}
catch (Exception ex) {
if (this.failOnError) {
throw new IllegalStateException("Failed to generate AOT artifacts for test classes " +
testClasses.stream().map(Class::getName).toList(), ex);
}
if (logger.isDebugEnabled()) {
logger.debug("Failed to generate AOT artifacts for test classes " +
testClasses.stream().map(Class::getName).toList(), ex);
Expand Down

0 comments on commit 8b97d5f

Please sign in to comment.