Skip to content

Commit

Permalink
Remove System.out calls in PreComputeFieldFeature
Browse files Browse the repository at this point in the history
Closes gh-30571
  • Loading branch information
sdeleuze committed Jun 13, 2023
1 parent 4b4a8af commit c565df9
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@
* GraalVM {@link Feature} that substitutes boolean field values that match a certain pattern
* with values pre-computed AOT without causing class build-time initialization.
*
* <p>It is possible to pass <pre style="code">-Dspring.aot.precompute=verbose</pre> as a
* <pre style="code">native-image</pre> compiler build argument to display detailed logs
* about pre-computed fields.</p>
*
* @author Sebastien Deleuze
* @author Phillip Webb
* @since 6.0
*/
class PreComputeFieldFeature implements Feature {

private static final boolean verbose = "verbose".equals(System.getProperty("spring.aot.precompute"));

private static Pattern[] patterns = {
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#inNativeImage")),
Pattern.compile(Pattern.quote("org.springframework.cglib.core.AbstractClassGenerator#inNativeImage")),
Expand Down Expand Up @@ -64,10 +70,14 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
try {
Object fieldValue = provideFieldValue(field);
access.registerFieldValueTransformer(field, (receiver, originalValue) -> fieldValue);
System.out.println("Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
if (verbose) {
System.out.println("Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
}
}
catch (Throwable ex) {
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime due to this error during build time evaluation: " + ex.getMessage());
if (verbose) {
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime due to this error during build time evaluation: " + ex.getMessage());
}
}
}
}
Expand Down

0 comments on commit c565df9

Please sign in to comment.