From c565df96f5c6a7e8ca9a5aaeaf39f05b4ae611ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 13 Jun 2023 14:25:32 +0200 Subject: [PATCH] Remove System.out calls in PreComputeFieldFeature Closes gh-30571 --- .../nativex/feature/PreComputeFieldFeature.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java b/spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java index d548d6ff3d9..258a90785e1 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java @@ -26,12 +26,18 @@ import org.graalvm.nativeimage.hosted.Feature; * GraalVM {@link Feature} that substitutes boolean field values that match a certain pattern * with values pre-computed AOT without causing class build-time initialization. * + *

It is possible to pass

-Dspring.aot.precompute=verbose
as a + *
native-image
compiler build argument to display detailed logs + * about pre-computed fields.

+ * * @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")), @@ -64,10 +70,14 @@ class PreComputeFieldFeature implements Feature { 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()); + } } } }