diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java index bd71b38912b..9dc84712b98 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java @@ -76,7 +76,7 @@ public class Builder { * @param log a logger used to record output */ public Builder(BuildLog log) { - this(log, new DockerApi(null, BuildLogDockerLogDelegate.get(log)), null); + this(log, new DockerApi(null, BuildLogAdapter.get(log)), null); } /** @@ -87,7 +87,7 @@ public class Builder { */ public Builder(BuildLog log, DockerConfiguration dockerConfiguration) { this(log, new DockerApi((dockerConfiguration != null) ? dockerConfiguration.getHost() : null, - BuildLogDockerLogDelegate.get(log)), dockerConfiguration); + BuildLogAdapter.get(log)), dockerConfiguration); } Builder(BuildLog log, DockerApi docker, DockerConfiguration dockerConfiguration) { @@ -264,14 +264,13 @@ public class Builder { } /** - * A {@link DockerLog} implementation that delegates logging to a provided - * {@link AbstractBuildLog}. + * A {@link DockerLog} implementation that adapts to an {@link AbstractBuildLog}. */ - static final class BuildLogDockerLogDelegate implements DockerLog { + static final class BuildLogAdapter implements DockerLog { private final AbstractBuildLog log; - private BuildLogDockerLogDelegate(AbstractBuildLog log) { + private BuildLogAdapter(AbstractBuildLog log) { this.log = log; } @@ -284,14 +283,14 @@ public class Builder { * Creates{@link DockerLog} instance based on the provided {@link BuildLog}. *

* If the provided {@link BuildLog} instance is an {@link AbstractBuildLog}, the - * method returns a {@link BuildLogDockerLogDelegate}, otherwise it returns a - * default {@link DockerLog#toSystemOut()}. + * method returns a {@link BuildLogAdapter}, otherwise it returns a default + * {@link DockerLog#toSystemOut()}. * @param log the {@link BuildLog} instance to delegate * @return a {@link DockerLog} instance for logging */ static DockerLog get(BuildLog log) { - if (log instanceof AbstractBuildLog) { - return new BuildLogDockerLogDelegate(((AbstractBuildLog) log)); + if (log instanceof AbstractBuildLog abstractBuildLog) { + return new BuildLogAdapter(abstractBuildLog); } return DockerLog.toSystemOut(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerLog.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerLog.java index 40dd367c6e3..1a3eb0c3e1a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerLog.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerLog.java @@ -48,7 +48,7 @@ public interface DockerLog { * @return {@link DockerLog} instance that logs to the given print stream */ static DockerLog to(PrintStream out) { - return new PrintStreamDockerLog(out); + return out::println; } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLog.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLog.java deleted file mode 100644 index d90da67d249..00000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLog.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2025 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.buildpack.platform.docker; - -import java.io.PrintStream; - -import org.springframework.util.Assert; - -/** - * {@link DockerLog} implementation that prints output to a {@link PrintStream}. - * - * @author Dmytro Nosan - */ -class PrintStreamDockerLog implements DockerLog { - - private final PrintStream stream; - - PrintStreamDockerLog(PrintStream stream) { - Assert.notNull(stream, "'stream' must not be null"); - this.stream = stream; - } - - @Override - public void log(String message) { - this.stream.println(message); - } - -} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java index 0d1541b7b0e..5db918a25b6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.stubbing.Answer; -import org.springframework.boot.buildpack.platform.build.Builder.BuildLogDockerLogDelegate; +import org.springframework.boot.buildpack.platform.build.Builder.BuildLogAdapter; import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi; import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi; @@ -84,7 +84,7 @@ class BuilderTests { assertThat(builder).extracting("docker") .extracting("system") .extracting("log") - .isInstanceOf(BuildLogDockerLogDelegate.class); + .isInstanceOf(BuildLogAdapter.class); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLogTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLogTests.java deleted file mode 100644 index c07c5b62587..00000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLogTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2025 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.buildpack.platform.docker; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link PrintStreamDockerLog}. - * - * @author Dmytro Nosan - */ -class PrintStreamDockerLogTests { - - @Test - void printsExpectedOutput() { - TestPrintStream stream = new TestPrintStream(); - PrintStreamDockerLog logger = new PrintStreamDockerLog(stream); - logger.log("Some message"); - logger.log("Some message1"); - assertThat(stream.toString()).isEqualTo(String.format("Some message%nSome message1%n")); - } - - static class TestPrintStream extends PrintStream { - - TestPrintStream() { - super(new ByteArrayOutputStream()); - } - - @Override - public String toString() { - return this.out.toString(); - } - - } - -}