From fe1f9b30022994ed9456688887a3cacda68693b1 Mon Sep 17 00:00:00 2001 From: Leonid Bogdanov Date: Thu, 5 Dec 2024 13:49:44 +1100 Subject: [PATCH 1/2] Only set imagePlatform if it has text See gh-43424 --- .../src/main/java/org/springframework/boot/maven/Image.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java index a72373c06b7f..e90d901fc474 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java @@ -257,7 +257,7 @@ private BuildRequest customize(BuildRequest request) { if (StringUtils.hasText(this.runImage)) { request = request.withRunImage(ImageReference.of(this.runImage)); } - if (this.env != null && !this.env.isEmpty()) { + if (!CollectionUtils.isEmpty(this.env)) { request = request.withEnv(this.env); } if (this.cleanCache != null) { @@ -295,10 +295,10 @@ private BuildRequest customize(BuildRequest request) { if (StringUtils.hasText(this.applicationDirectory)) { request = request.withApplicationDirectory(this.applicationDirectory); } - if (this.securityOptions != null) { + if (!CollectionUtils.isEmpty(this.securityOptions)) { request = request.withSecurityOptions(this.securityOptions); } - if (this.imagePlatform != null) { + if (StringUtils.hasText(this.imagePlatform)) { request = request.withImagePlatform(this.imagePlatform); } return request; From 4dca6ee5d3fa188a56d74c71787cd86226b75652 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 5 Dec 2024 11:03:14 +0100 Subject: [PATCH 2/2] Polish "Only set imagePlatform if it has text" See gh-43424 --- .../main/java/org/springframework/boot/maven/Image.java | 2 +- .../java/org/springframework/boot/maven/ImageTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java index e90d901fc474..a681b031906f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java @@ -295,7 +295,7 @@ private BuildRequest customize(BuildRequest request) { if (StringUtils.hasText(this.applicationDirectory)) { request = request.withApplicationDirectory(this.applicationDirectory); } - if (!CollectionUtils.isEmpty(this.securityOptions)) { + if (this.securityOptions != null) { request = request.withSecurityOptions(this.securityOptions); } if (StringUtils.hasText(this.imagePlatform)) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java index 053ec87bd8eb..12b376054365 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java @@ -49,6 +49,7 @@ * @author Scott Frederick * @author Jeroen Meijer * @author Rafael Ceccone + * @author Moritz Halbritter */ class ImageTests { @@ -290,6 +291,14 @@ void getBuildRequestWhenHasImagePlatformUsesImagePlatform() { assertThat(request.getImagePlatform()).isEqualTo(ImagePlatform.of("linux/arm64")); } + @Test + void getBuildRequestWhenImagePlatformIsEmptyDoesntSetImagePlatform() { + Image image = new Image(); + image.imagePlatform = ""; + BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent()); + assertThat(request.getImagePlatform()).isNull(); + } + private Artifact createArtifact() { return new DefaultArtifact("com.example", "my-app", VersionRange.createFromVersion("0.0.1-SNAPSHOT"), "compile", "jar", null, new DefaultArtifactHandler());