Skip to content

Commit

Permalink
Merge pull request #43424 from vonZeppelin
Browse files Browse the repository at this point in the history
* pr/43424:
  Polish "Only set imagePlatform if it has text"
  Only set imagePlatform if it has text

Closes gh-43424
  • Loading branch information
mhalbritter committed Dec 5, 2024
2 parents 48bc3b6 + 4dca6ee commit efee347
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -298,7 +298,7 @@ private BuildRequest customize(BuildRequest request) {
if (this.securityOptions != null) {
request = request.withSecurityOptions(this.securityOptions);
}
if (this.imagePlatform != null) {
if (StringUtils.hasText(this.imagePlatform)) {
request = request.withImagePlatform(this.imagePlatform);
}
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @author Scott Frederick
* @author Jeroen Meijer
* @author Rafael Ceccone
* @author Moritz Halbritter
*/
class ImageTests {

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit efee347

Please sign in to comment.