| 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 | import org.junit.jupiter.api.extension.ExtendWith; |
| 23 | |
| 24 | /** |
| 25 | * {@code @DisabledOnOs} is used to signal that the annotated test class or |
| 26 | * test method is <em>disabled</em> on one or more specified |
| 27 | * {@linkplain #value operating systems} or on one or more specified |
| 28 | * {@linkplain #architectures architectures} |
| 29 | * |
| 30 | * <p>If operating systems <em>and</em> architectures are specified, the annotated |
| 31 | * test class or test method is disabled if both conditions apply. |
| 32 | * |
| 33 | * <p>When applied at the class level, all test methods within that class |
| 34 | * will be disabled on the same specified operating systems, architectures, or |
| 35 | * the specified combinations of both. |
| 36 | * |
| 37 | * <p>This annotation is not {@link java.lang.annotation.Inherited @Inherited}. |
| 38 | * Consequently, if you wish to apply the same semantics to a subclass, this |
| 39 | * annotation must be redeclared on the subclass. |
| 40 | * |
| 41 | * <p>If a test method is disabled via this annotation, that does not prevent |
| 42 | * the test class from being instantiated. Rather, it prevents the execution of |
| 43 | * the test method and method-level lifecycle callbacks such as {@code @BeforeEach} |
| 44 | * methods, {@code @AfterEach} methods, and corresponding extension APIs. |
| 45 | * |
| 46 | * <p>This annotation may be used as a meta-annotation in order to create a |
| 47 | * custom <em>composed annotation</em> that inherits the semantics of this |
| 48 | * annotation. |
| 49 | * |
| 50 | * <h2>Warning</h2> |
| 51 | * |
| 52 | * <p>As of JUnit Jupiter 5.1, this annotation can only be declared once on an |
| 53 | * {@link java.lang.reflect.AnnotatedElement AnnotatedElement} (i.e., test |
| 54 | * interface, test class, or test method). If this annotation is directly |
| 55 | * present, indirectly present, or meta-present multiple times on a given |
| 56 | * element, only the first such annotation discovered by JUnit will be used; |
| 57 | * any additional declarations will be silently ignored. Note, however, that |
| 58 | * this annotation may be used in conjunction with other {@code @Enabled*} or |
| 59 | * {@code @Disabled*} annotations in this package. |
| 60 | * |
| 61 | * @since 5.1 |
| 62 | * @see OS |
| 63 | * @see org.junit.jupiter.api.condition.EnabledIf |
| 64 | * @see org.junit.jupiter.api.condition.DisabledIf |
| 65 | * @see org.junit.jupiter.api.condition.EnabledOnOs |
| 66 | * @see org.junit.jupiter.api.condition.EnabledOnJre |
| 67 | * @see org.junit.jupiter.api.condition.DisabledOnJre |
| 68 | * @see org.junit.jupiter.api.condition.EnabledForJreRange |
| 69 | * @see org.junit.jupiter.api.condition.DisabledForJreRange |
| 70 | * @see org.junit.jupiter.api.condition.EnabledInNativeImage |
| 71 | * @see org.junit.jupiter.api.condition.DisabledInNativeImage |
| 72 | * @see org.junit.jupiter.api.condition.EnabledIfSystemProperty |
| 73 | * @see org.junit.jupiter.api.condition.DisabledIfSystemProperty |
| 74 | * @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable |
| 75 | * @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable |
| 76 | * @see org.junit.jupiter.api.Disabled |
| 77 | */ |
| 78 | @Target({ ElementType.TYPE, ElementType.METHOD }) |
| 79 | @Retention(RetentionPolicy.RUNTIME) |
| 80 | @Documented |
| 81 | @ExtendWith(DisabledOnOsCondition.class) |
| 82 | @API(status = STABLE, since = "5.1") |
| 83 | @SuppressWarnings("exports") |
| 84 | public @interface DisabledOnOs { |
| 85 | |
| 86 | /** |
| 87 | * Operating systems on which the annotated class or method should be |
| 88 | * disabled. |
| 89 | * |
| 90 | * @see OS |
| 91 | */ |
| 92 | OS[] value() default {}; |
| 93 | |
| 94 | /** |
| 95 | * Architectures on which the annotated class or method should be disabled. |
| 96 | * |
| 97 | * <p>Each architecture will be compared to the value returned from |
| 98 | * {@code System.getProperty("os.arch")}, ignoring case. |
| 99 | * |
| 100 | * @since 5.9 |
| 101 | */ |
| 102 | @API(status = STABLE, since = "5.9") |
| 103 | String[] architectures() default {}; |
| 104 | |
| 105 | /** |
| 106 | * Custom reason to provide if the test or container is disabled. |
| 107 | * |
| 108 | * <p>If a custom reason is supplied, it will be combined with the default |
| 109 | * reason for this annotation. If a custom reason is not supplied, the default |
| 110 | * reason will be used. |
| 111 | * |
| 112 | * @since 5.7 |
| 113 | */ |
| 114 | @API(status = STABLE, since = "5.7") |
| 115 | String disabledReason() default ""; |
| 116 | |
| 117 | } |