From ca21600fae70caf2e1d29a4335b578d9a0c3b5f3 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 12 Jun 2025 10:00:30 +0100 Subject: [PATCH] Use Framework's StreamUtils instead of Commons Compress's IOUtils Closes gh-45911 --- .../buildpack/platform/build/EphemeralBuilderTests.java | 4 ++-- .../boot/buildpack/platform/build/TestTarGzip.java | 6 +++--- .../tasks/bundling/BootBuildImageIntegrationTests.java | 6 +++--- .../springframework/boot/image/assertions/ImageAssert.java | 6 +++--- src/checkstyle/checkstyle.xml | 3 ++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java index 75ab37ee21b..3aa87f8cf9a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java @@ -35,7 +35,6 @@ import java.util.Map; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.compress.utils.IOUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -46,6 +45,7 @@ import org.springframework.boot.buildpack.platform.docker.type.ImageConfig; import org.springframework.boot.buildpack.platform.docker.type.ImageReference; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import org.springframework.util.FileCopyUtils; +import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -202,7 +202,7 @@ class EphemeralBuilderTests extends AbstractJsonTests { else { file.getParentFile().mkdirs(); try (OutputStream out = new FileOutputStream(file)) { - IOUtils.copy(archive, out); + StreamUtils.copy(archive, out); } } entry = archive.getNextEntry(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestTarGzip.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestTarGzip.java index 6a143fa2e09..c49aed4421d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestTarGzip.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestTarGzip.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * 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. @@ -31,9 +31,9 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; -import org.apache.commons.compress.utils.IOUtils; import org.springframework.util.FileCopyUtils; +import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -110,7 +110,7 @@ class TestTarGzip { TarArchiveEntry entry = new TarArchiveEntry(entryName); entry.setSize(content.length()); tar.putArchiveEntry(entry); - IOUtils.copy(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), tar); + StreamUtils.copy(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), tar); tar.closeArchiveEntry(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java index 219b150cc0d..351636ca06a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * 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. @@ -33,7 +33,6 @@ import java.util.Set; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; -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; @@ -52,6 +51,7 @@ import org.springframework.boot.testsupport.container.DisabledIfDockerUnavailabl import org.springframework.boot.testsupport.gradle.testkit.GradleBuild; import org.springframework.boot.testsupport.junit.DisabledOnOs; import org.springframework.util.FileSystemUtils; +import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -547,7 +547,7 @@ class BootBuildImageIntegrationTests { TarArchiveEntry entry = new TarArchiveEntry(file, name); entry.setMode(mode); tar.putArchiveEntry(entry); - IOUtils.copy(Files.newInputStream(file.toPath()), tar); + StreamUtils.copy(Files.newInputStream(file.toPath()), tar); tar.closeArchiveEntry(); } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java index fc5f9509412..ca61c89c2e2 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * 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. @@ -26,7 +26,6 @@ import java.util.function.Consumer; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.compress.utils.IOUtils; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.ListAssert; @@ -35,6 +34,7 @@ import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.type.ImageReference; import org.springframework.boot.buildpack.platform.docker.type.Layer; import org.springframework.boot.test.json.JsonContentAssert; +import org.springframework.util.StreamUtils; /** * AssertJ {@link org.assertj.core.api.Assert} for Docker image contents. @@ -105,7 +105,7 @@ public class ImageAssert extends AbstractAssert { while (entry != null) { if (entry.getName().equals(name)) { ByteArrayOutputStream entryOut = new ByteArrayOutputStream(); - IOUtils.copy(in, entryOut); + StreamUtils.copy(in, entryOut); assertConsumer.accept(new JsonContentAssert(LayerContentAssert.class, entryOut.toString())); return; } diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 60c8a4d6e5d..3838d69d7fd 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -14,7 +14,8 @@ name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck"> + value="^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|logging|pool2).*, ^com\.datastax\.oss\.driver\.shaded.*, ^com\.google\.common.*, ^io\.micrometer\.core\.lang.*, ^io\.micrometer\.shaded.*, ^org\.jetbrains\.annotations.*, ^org\.testcontainers\.shaded.*, + ^org\.apache\.commons\.compress\.utils" />