From 685b045c3d0e4dbe3bde1709f1577d8db985dcd2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 18 Mar 2021 14:40:54 -0700 Subject: [PATCH] Polish --- .../platform/build/BuildRequest.java | 5 +++ .../platform/docker/type/Binding.java | 42 +++++++++---------- .../platform/docker/type/ContainerConfig.java | 2 +- .../platform/docker/type/BindingTests.java | 6 +-- .../org/springframework/boot/maven/Image.java | 5 ++- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java index 32d291c61b..93600e49e0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java @@ -211,6 +211,7 @@ public class BuildRequest { * Return a new {@link BuildRequest} with an updated buildpacks setting. * @param buildpacks a collection of buildpacks to use when building the image * @return an updated build request + * @since 2.5.0 */ public BuildRequest withBuildpacks(BuildpackReference... buildpacks) { Assert.notEmpty(buildpacks, "Buildpacks must not be empty"); @@ -221,6 +222,7 @@ public class BuildRequest { * Return a new {@link BuildRequest} with an updated buildpacks setting. * @param buildpacks a collection of buildpacks to use when building the image * @return an updated build request + * @since 2.5.0 */ public BuildRequest withBuildpacks(List buildpacks) { Assert.notNull(buildpacks, "Buildpacks must not be null"); @@ -232,6 +234,7 @@ public class BuildRequest { * Return a new {@link BuildRequest} with updated bindings. * @param bindings a collection of bindings to mount to the build container * @return an updated build request + * @since 2.5.0 */ public BuildRequest withBindings(Binding... bindings) { Assert.notEmpty(bindings, "Bindings must not be empty"); @@ -242,6 +245,7 @@ public class BuildRequest { * Return a new {@link BuildRequest} with updated bindings. * @param bindings a collection of bindings to mount to the build container * @return an updated build request + * @since 2.5.0 */ public BuildRequest withBindings(List bindings) { Assert.notNull(bindings, "Bindings must not be null"); @@ -343,6 +347,7 @@ public class BuildRequest { /** * Return the collection of bindings to mount to the build container. * @return the bindings + * @since 2.5.0 */ public List getBindings() { return this.bindings; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Binding.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Binding.java index 5a1169206c..1c5e9647ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Binding.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Binding.java @@ -34,7 +34,25 @@ public final class Binding { this.value = value; } - public String getValue() { + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Binding)) { + return false; + } + Binding binding = (Binding) obj; + return Objects.equals(this.value, binding.value); + } + + @Override + public int hashCode() { + return Objects.hash(this.value); + } + + @Override + public String toString() { return this.value; } @@ -72,26 +90,4 @@ public final class Binding { return new Binding(source + ":" + destination); } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Binding)) { - return false; - } - Binding binding = (Binding) obj; - return Objects.equals(this.value, binding.value); - } - - @Override - public int hashCode() { - return Objects.hash(this.value); - } - - @Override - public String toString() { - return this.value; - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfig.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfig.java index f432758ff6..da945f6848 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfig.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfig.java @@ -65,7 +65,7 @@ public class ContainerConfig { labels.forEach(labelsNode::put); ObjectNode hostConfigNode = node.putObject("HostConfig"); ArrayNode bindsNode = hostConfigNode.putArray("Binds"); - bindings.forEach((binding) -> bindsNode.add(binding.getValue())); + bindings.forEach((binding) -> bindsNode.add(binding.toString())); this.json = objectMapper.writeValueAsString(node); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java index beda11df1d..c8eb1783d8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java @@ -31,7 +31,7 @@ class BindingTests { @Test void ofReturnsValue() { Binding binding = Binding.of("host-src:container-dest:ro"); - assertThat(binding.getValue()).isEqualTo("host-src:container-dest:ro"); + assertThat(binding).hasToString("host-src:container-dest:ro"); } @Test @@ -43,7 +43,7 @@ class BindingTests { @Test void fromReturnsValue() { Binding binding = Binding.from("host-src", "container-dest"); - assertThat(binding.getValue()).isEqualTo("host-src:container-dest"); + assertThat(binding).hasToString("host-src:container-dest"); } @Test @@ -61,7 +61,7 @@ class BindingTests { @Test void fromVolumeNameSourceReturnsValue() { Binding binding = Binding.from(VolumeName.of("host-src"), "container-dest"); - assertThat(binding.getValue()).isEqualTo("host-src:container-dest"); + assertThat(binding).hasToString("host-src:container-dest"); } @Test 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 dd219ef1d5..0ce0afd83b 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 @@ -31,6 +31,7 @@ import org.springframework.boot.buildpack.platform.docker.type.ImageName; import org.springframework.boot.buildpack.platform.docker.type.ImageReference; import org.springframework.boot.buildpack.platform.io.Owner; import org.springframework.boot.buildpack.platform.io.TarArchive; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** @@ -182,11 +183,11 @@ public class Image { if (this.publish != null) { request = request.withPublish(this.publish); } - if (this.buildpacks != null && !this.buildpacks.isEmpty()) { + if (!CollectionUtils.isEmpty(this.buildpacks)) { request = request .withBuildpacks(this.buildpacks.stream().map(BuildpackReference::of).collect(Collectors.toList())); } - if (this.bindings != null && !this.bindings.isEmpty()) { + if (!CollectionUtils.isEmpty(this.bindings)) { request = request.withBindings(this.bindings.stream().map(Binding::of).collect(Collectors.toList())); } return request;