|
|
|
|
@ -16,42 +16,49 @@
@@ -16,42 +16,49 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.testsupport.junit; |
|
|
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.condition.OS; |
|
|
|
|
import org.junit.jupiter.api.extension.ConditionEvaluationResult; |
|
|
|
|
import org.junit.jupiter.api.extension.ExecutionCondition; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtensionContext; |
|
|
|
|
import org.junit.platform.commons.util.AnnotationUtils; |
|
|
|
|
|
|
|
|
|
import org.springframework.core.annotation.MergedAnnotation; |
|
|
|
|
import org.springframework.core.annotation.MergedAnnotations; |
|
|
|
|
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Evaluates {@link DisabledOnOs}. |
|
|
|
|
* |
|
|
|
|
* @author Moritz Halbritter |
|
|
|
|
* @author Phillip Webb |
|
|
|
|
*/ |
|
|
|
|
class DisabledOnOsCondition implements ExecutionCondition { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { |
|
|
|
|
Optional<DisabledOnOs> annotation = AnnotationUtils.findAnnotation(context.getElement(), DisabledOnOs.class); |
|
|
|
|
if (!context.getElement().isPresent()) { |
|
|
|
|
return ConditionEvaluationResult.enabled("No element for @DisabledOnOs found"); |
|
|
|
|
} |
|
|
|
|
MergedAnnotation<DisabledOnOs> annotation = MergedAnnotations |
|
|
|
|
.from(context.getElement().get(), SearchStrategy.TYPE_HIERARCHY) |
|
|
|
|
.get(DisabledOnOs.class); |
|
|
|
|
if (!annotation.isPresent()) { |
|
|
|
|
return ConditionEvaluationResult.enabled("No @DisabledOnOs found"); |
|
|
|
|
} |
|
|
|
|
return evaluate(annotation.get()); |
|
|
|
|
return evaluate(annotation.synthesize()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ConditionEvaluationResult evaluate(DisabledOnOs annotation) { |
|
|
|
|
String architecture = System.getProperty("os.arch"); |
|
|
|
|
String os = System.getProperty("os.name"); |
|
|
|
|
if (annotation.architecture().equals(architecture)) { |
|
|
|
|
for (OS targetOs : annotation.os()) { |
|
|
|
|
if (targetOs.isCurrentOs()) { |
|
|
|
|
String reason = annotation.disabledReason().isEmpty() |
|
|
|
|
? String.format("Disabled on OS = %s, architecture = %s", os, architecture) |
|
|
|
|
: annotation.disabledReason(); |
|
|
|
|
return ConditionEvaluationResult.disabled(reason); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
boolean onDisabledOs = Arrays.stream(annotation.os()).anyMatch(OS::isCurrentOs); |
|
|
|
|
boolean onDisabledArchitecture = Arrays.stream(annotation.architecture()).anyMatch(architecture::equals); |
|
|
|
|
if (onDisabledOs && onDisabledArchitecture) { |
|
|
|
|
String reason = annotation.disabledReason().isEmpty() |
|
|
|
|
? String.format("Disabled on OS = %s, architecture = %s", os, architecture) |
|
|
|
|
: annotation.disabledReason(); |
|
|
|
|
return ConditionEvaluationResult.disabled(reason); |
|
|
|
|
} |
|
|
|
|
return ConditionEvaluationResult |
|
|
|
|
.enabled(String.format("Enabled on OS = %s, architecture = %s", os, architecture)); |
|
|
|
|
|