Package io.micronaut.core.util
Class NativeImageUtils
java.lang.Object
io.micronaut.core.util.NativeImageUtils
Utility class to retrieve information about the context in which code gets executed.
Partial fork of
org.graalvm.nativeimage.ImageInfo
to avoid a dependency on org.graalvm.sdk:nativeimage
.- Since:
- 4.8.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Holds the string that is the name of the system property providing information about the context in which code is currently executing.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing in the context of image building (e.g.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing at image runtime. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns true if (at the time of the call) code is executing in the context of image building (e.g.static boolean
Returns true if (at the time of the call) code is executing in the context of image building or during image runtime, else false.static boolean
Returns true if (at the time of the call) code is executing at image runtime.
-
Field Details
-
PROPERTY_IMAGE_CODE_KEY
Holds the string that is the name of the system property providing information about the context in which code is currently executing. If the property returns the string given byPROPERTY_IMAGE_CODE_VALUE_BUILDTIME
the code is executing in the context of image building (e.g. in a static initializer of a class that will be contained in the image). If the property returns the string given byPROPERTY_IMAGE_CODE_VALUE_RUNTIME
the code is executing at image runtime. Otherwise, the property is not set.- See Also:
-
PROPERTY_IMAGE_CODE_VALUE_BUILDTIME
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing in the context of image building (e.g. in a static initializer of class that will be contained in the image).- See Also:
-
PROPERTY_IMAGE_CODE_VALUE_RUNTIME
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing at image runtime.- See Also:
-
-
Method Details
-
inImageCode
public static boolean inImageCode()Returns true if (at the time of the call) code is executing in the context of image building or during image runtime, else false. This method will be const-folded so that it can be used to hide parts of an application that only work when running on the JVM. For example:if (!ImageInfo.inImageCode()) { ... JVM specific code here ... }
- Returns:
- true if (at the time of the call) code is executing in the context of image building or during image runtime, else false
-
inImageRuntimeCode
public static boolean inImageRuntimeCode()Returns true if (at the time of the call) code is executing at image runtime. This method will be const-folded. It can be used to hide parts of an application that only work when running as native image.- Returns:
- true if (at the time of the call) code is executing at image runtime.
-
inImageBuildtimeCode
public static boolean inImageBuildtimeCode()Returns true if (at the time of the call) code is executing in the context of image building (e.g. in a static initializer of class that will be contained in the image).- Returns:
- true if (at the time of the call) code is executing in the context of image building
-