junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledInNativeImage.java
raw symbols SCIP| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api.condition; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.STABLE; |
| 14 | |
| 15 | import java.lang.annotation.Documented; |
| 16 | import java.lang.annotation.ElementType; |
| 17 | import java.lang.annotation.Retention; |
| 18 | import java.lang.annotation.RetentionPolicy; |
| 19 | import java.lang.annotation.Target; |
| 20 | |
| 21 | import org.apiguardian.api.API; |
| 22 | |
| 23 | /** |
| 24 | * {@code @DisabledInNativeImage} is used to signal that the annotated test class |
| 25 | * or test method is only <em>disabled</em> when executing within a GraalVM native |
| 26 | * image. |
| 27 | * |
| 28 | * <p>When applied at the class level, all test methods within that class will |
| 29 | * be disabled within a native image. |
| 30 | * |
| 31 | * <p>This annotation is not {@link java.lang.annotation.Inherited @Inherited}. |
| 32 | * Consequently, if you wish to apply the same semantics to a subclass, this |
| 33 | * annotation must be redeclared on the subclass. |
| 34 | * |
| 35 | * <p>If a test method is disabled via this annotation, that does not prevent |
| 36 | * the test class from being instantiated. Rather, it prevents the execution of |
| 37 | * the test method and method-level lifecycle callbacks such as {@code @BeforeEach} |
| 38 | * methods, {@code @AfterEach} methods, and corresponding extension APIs. |
| 39 | * |
| 40 | * <p>This annotation may be used as a meta-annotation in order to create a |
| 41 | * custom <em>composed annotation</em> that inherits the semantics of this |
| 42 | * annotation. |
| 43 | * |
| 44 | * <h2>Technical Details</h2> |
| 45 | * |
| 46 | * <p>JUnit detects whether tests are executing within a GraalVM native image by |
| 47 | * checking for the presence of the {@code org.graalvm.nativeimage.imagecode} |
| 48 | * system property (see |
| 49 | * <a href="https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java">org.graalvm.nativeimage.ImageInfo</a> |
| 50 | * for details). The GraalVM compiler sets the property to {@code buildtime} while |
| 51 | * compiling a native image; the property is set to {@code runtime} while a native |
| 52 | * image is executing; and the Gradle and Maven plug-ins in the GraalVM |
| 53 | * <a href="https://graalvm.github.io/native-build-tools/latest/">Native Build Tools</a> |
| 54 | * project set the property to {@code agent} while executing tests with the GraalVM |
| 55 | * <a href="https://www.graalvm.org/reference-manual/native-image/metadata/AutomaticMetadataCollection/">tracing agent</a>. |
| 56 | * |
| 57 | * @since 5.9.1 |
| 58 | * @see org.junit.jupiter.api.condition.EnabledIf |
| 59 | * @see org.junit.jupiter.api.condition.DisabledIf |
| 60 | * @see org.junit.jupiter.api.condition.EnabledOnOs |
| 61 | * @see org.junit.jupiter.api.condition.DisabledOnOs |
| 62 | * @see org.junit.jupiter.api.condition.EnabledOnJre |
| 63 | * @see org.junit.jupiter.api.condition.DisabledOnJre |
| 64 | * @see org.junit.jupiter.api.condition.EnabledForJreRange |
| 65 | * @see org.junit.jupiter.api.condition.DisabledForJreRange |
| 66 | * @see org.junit.jupiter.api.condition.EnabledInNativeImage |
| 67 | * @see org.junit.jupiter.api.condition.EnabledIfSystemProperty |
| 68 | * @see org.junit.jupiter.api.condition.DisabledIfSystemProperty |
| 69 | * @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable |
| 70 | * @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable |
| 71 | * @see org.junit.jupiter.api.Disabled |
| 72 | */ |
| 73 | @Target({ ElementType.TYPE, ElementType.METHOD }) |
| 74 | @Retention(RetentionPolicy.RUNTIME) |
| 75 | @Documented |
| 76 | @DisabledIfSystemProperty(named = "org.graalvm.nativeimage.imagecode", matches = ".+", // |
| 77 | disabledReason = "Currently executing within a GraalVM native image") |
| 78 | @API(status = STABLE, since = "5.9.1") |
| 79 | public @interface DisabledInNativeImage { |
| 80 | } |