Browse Source

Merge branch '2.7.x' into 3.0.x

pull/35611/head
Phillip Webb 3 years ago
parent
commit
2c27ec5b7b
  1. 4
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java
  2. 3
      spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java
  3. 18
      spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/DisabledOnOs.java
  4. 33
      spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/DisabledOnOsCondition.java

4
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java

@ -36,7 +36,6 @@ import org.apache.commons.compress.utils.IOUtils; @@ -36,7 +36,6 @@ import org.apache.commons.compress.utils.IOUtils;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.springframework.boot.buildpack.platform.docker.DockerApi;
@ -47,6 +46,7 @@ import org.springframework.boot.buildpack.platform.docker.type.VolumeName; @@ -47,6 +46,7 @@ import org.springframework.boot.buildpack.platform.docker.type.VolumeName;
import org.springframework.boot.buildpack.platform.io.FilePermissions;
import org.springframework.boot.gradle.junit.GradleCompatibility;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable;
import static org.assertj.core.api.Assertions.assertThat;
@ -60,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -60,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@GradleCompatibility(configurationCache = true)
@DisabledIfDockerUnavailable
@org.springframework.boot.testsupport.junit.DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The builder image has no ARM support")
class BootBuildImageIntegrationTests {

3
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java

@ -33,6 +33,7 @@ import org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi; @@ -33,6 +33,7 @@ import org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi;
import org.springframework.boot.buildpack.platform.docker.type.ImageName;
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
import org.springframework.boot.buildpack.platform.docker.type.VolumeName;
import org.springframework.boot.testsupport.junit.DisabledOnOs;
import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable;
import static org.assertj.core.api.Assertions.assertThat;
@ -46,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -46,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@ExtendWith(MavenBuildExtension.class)
@DisabledIfDockerUnavailable
@org.springframework.boot.testsupport.junit.DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The builder image has no ARM support")
class BuildImageTests extends AbstractArchiveIntegrationTests {

18
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/DisabledOnOs.java

@ -37,16 +37,22 @@ import org.junit.jupiter.api.extension.ExtendWith; @@ -37,16 +37,22 @@ import org.junit.jupiter.api.extension.ExtendWith;
public @interface DisabledOnOs {
/**
* See {@link org.junit.jupiter.api.condition.DisabledOnOs#value()}.
* @return os
* The operating systems on which the annotated class or method should be disabled.
* @return the operating systems where the test is disabled
*/
OS[] os();
OS[] value() default {};
/**
* Architecture of the operating system.
* @return architecture
* The operating systems on which the annotated class or method should be disabled.
* @return the operating systems where the test is disabled
*/
String architecture();
OS[] os() default {};
/**
* The architectures on which the annotated class or method should be disabled.
* @return the architectures where the test is disabled
*/
String[] architecture() default {};
/**
* See {@link org.junit.jupiter.api.condition.DisabledOnOs#disabledReason()}.

33
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/DisabledOnOsCondition.java

@ -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));

Loading…
Cancel
Save