From 98d98df6b2348a3659a00f1fed7b2b1ca98cc62a Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 19 Mar 2023 13:19:30 +0000 Subject: [PATCH 1/3] [MNG-6825] Replace FileUtils with Commons IO Co-authored-by: Moderne --- .../maven/artifact/repository/metadata/MetadataBridge.java | 2 +- .../apache/maven/repository/legacy/DefaultWagonManager.java | 3 ++- .../maven/artifact/deployer/ArtifactDeployerTest.java | 6 +++--- .../apache/maven/artifact/testutils/TestFileManager.java | 5 +++-- .../maven/repository/legacy/DefaultWagonManagerTest.java | 4 ++-- .../maven/project/artifact/ProjectArtifactMetadata.java | 2 +- .../apache/maven/AbstractCoreMavenComponentTestCase.java | 2 +- .../apache/maven/artifact/handler/ArtifactHandlerTest.java | 4 ++-- .../apache/maven/internal/impl/TestRepositorySystem.java | 2 +- .../apache/maven/repository/TestRepositoryConnector.java | 2 +- .../org/apache/maven/repository/TestRepositorySystem.java | 2 +- .../org/apache/maven/cli/CLIManagerDocumentationTest.java | 4 ++-- 12 files changed, 20 insertions(+), 18 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java index fbe682a05282..48eea0ac5343 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java @@ -22,10 +22,10 @@ import java.util.Collections; import java.util.Map; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.RepositoryException; import org.eclipse.aether.metadata.AbstractMetadata; import org.eclipse.aether.metadata.MergeableMetadata; diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java index 3ffc399ed2db..2c730b1f7bcf 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Properties; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -609,7 +610,7 @@ private void verifyChecksum( tempChecksumFile.deleteOnExit(); wagon.get(remotePath + checksumFileExtension, tempChecksumFile); - String expectedChecksum = FileUtils.fileRead(tempChecksumFile, "UTF-8"); + String expectedChecksum = FileUtils.readFileToString(tempChecksumFile, "UTF-8"); // remove whitespaces at the end expectedChecksum = expectedChecksum.trim(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 1d8278f44dea..01b917bb618a 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -22,12 +22,12 @@ import java.io.File; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; import org.apache.maven.session.scope.internal.SessionScope; -import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; @@ -60,14 +60,14 @@ public void testArtifactInstallation() throws Exception { Artifact artifact = createArtifact("artifact", "1.0"); File file = new File(artifactBasedir, "artifact-1.0.jar"); - assertEquals("dummy", FileUtils.fileRead(file, "UTF-8").trim()); + assertEquals("dummy", FileUtils.readFileToString(file, "UTF-8").trim()); artifactDeployer.deploy(file, artifact, remoteRepository(), localRepository()); ArtifactRepository remoteRepository = remoteRepository(); File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact)); assertTrue(deployedFile.exists()); - assertEquals("dummy", FileUtils.fileRead(deployedFile, "UTF-8").trim()); + assertEquals("dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim()); } finally { sessionScope.exit(); } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java index c44eb74106df..692372a076cf 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.List; +import org.apache.commons.io.FileUtils; import org.codehaus.plexus.util.FileUtils; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -130,7 +131,7 @@ public void assertFileContents(File dir, String filename, String contentsTest, S File file = new File(dir, filename); - String contents = FileUtils.fileRead(file, encoding); + String contents = FileUtils.readFileToString(file, encoding); assertEquals(contentsTest, contents); } @@ -148,7 +149,7 @@ public File createFile(File dir, String filename, String contents, String encodi } public String getFileContents(File file, String encoding) throws IOException { - return FileUtils.fileRead(file, encoding); + return FileUtils.readFileToString(file, encoding); } protected void finalize() throws Throwable { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index 164b1739bfc0..9641ef57ab08 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -44,7 +45,6 @@ import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.Debug; import org.codehaus.plexus.testing.PlexusTest; -import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -140,7 +140,7 @@ public void testGetRemoteJar() wagonManager.getArtifact(artifact, repo, null, false); assertTrue(artifact.getFile().exists()); - assertEquals("expected", FileUtils.fileRead(artifact.getFile(), "UTF-8")); + assertEquals("expected", FileUtils.readFileToString(artifact.getFile(), "UTF-8")); } private Artifact createTestPomArtifact(String directory) throws IOException { diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java b/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java index 407168142432..f00cb4b2b7de 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java @@ -21,12 +21,12 @@ import java.io.File; import java.io.IOException; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.AbstractArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; -import org.codehaus.plexus.util.FileUtils; /** * Attach a POM to an artifact. diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 720729582f83..f711255aef37 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Properties; +import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -48,7 +49,6 @@ import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.testing.PlexusTest; -import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 5d64c32ef461..bc062ee8822a 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java @@ -23,9 +23,9 @@ import java.io.File; import java.util.List; +import org.apache.commons.io.FileUtils; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.testing.PlexusTest; -import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; @@ -40,7 +40,7 @@ public class ArtifactHandlerTest { public void testAptConsistency() throws Exception { File apt = getTestFile("src/site/apt/artifact-handlers.apt"); - List lines = FileUtils.loadFile(apt); + List lines = FileUtils.readLines(apt); for (String line : lines) { if (line.startsWith("||")) { diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java index f34eb51e6070..3f3d1e08a790 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.io.FileUtils; import org.apache.maven.api.model.Model; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; @@ -55,7 +56,6 @@ import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; -import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystemSession; diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java index 4fd761003e80..6f9d9639046e 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java @@ -24,7 +24,7 @@ import java.net.URL; import java.util.Collection; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.metadata.Metadata; import org.eclipse.aether.repository.RemoteRepository; diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java index e882e517c89a..bb198ec6637d 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.io.FileUtils; import org.apache.maven.api.model.Model; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; @@ -52,7 +53,6 @@ import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; -import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystemSession; diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java index ed6c159bf3b8..19a1efa2b219 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.commons.cli.Option; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; /** @@ -88,6 +88,6 @@ public String getOptionsAsHtml() { @Test public void testOptionsAsHtml() throws IOException { File options = new File("target/test-classes/options.html"); - FileUtils.fileWrite(options, "UTF-8", getOptionsAsHtml()); + FileUtils.write(options, getOptionsAsHtml(), "UTF-8"); } } From 41046c114c907acc445a2e89e3c97d83163c17ff Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 19 Mar 2023 14:28:26 +0100 Subject: [PATCH 2/3] Minor fixes and reverts where cases are not handled yet --- .../maven/repository/legacy/DefaultWagonManager.java | 3 +-- .../maven/artifact/deployer/ArtifactDeployerTest.java | 3 ++- .../apache/maven/artifact/testutils/TestFileManager.java | 5 ++--- .../maven/repository/legacy/DefaultWagonManagerTest.java | 4 ++-- maven-core/pom.xml | 9 ++++----- .../apache/maven/AbstractCoreMavenComponentTestCase.java | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java index 2c730b1f7bcf..3ffc399ed2db 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Properties; -import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -610,7 +609,7 @@ private void verifyChecksum( tempChecksumFile.deleteOnExit(); wagon.get(remotePath + checksumFileExtension, tempChecksumFile); - String expectedChecksum = FileUtils.readFileToString(tempChecksumFile, "UTF-8"); + String expectedChecksum = FileUtils.fileRead(tempChecksumFile, "UTF-8"); // remove whitespaces at the end expectedChecksum = expectedChecksum.trim(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 01b917bb618a..29bf7494f29f 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java @@ -67,7 +67,8 @@ public void testArtifactInstallation() throws Exception { ArtifactRepository remoteRepository = remoteRepository(); File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact)); assertTrue(deployedFile.exists()); - assertEquals("dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim()); + assertEquals( + "dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim()); } finally { sessionScope.exit(); } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java index 692372a076cf..c44eb74106df 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.List; -import org.apache.commons.io.FileUtils; import org.codehaus.plexus.util.FileUtils; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -131,7 +130,7 @@ public void assertFileContents(File dir, String filename, String contentsTest, S File file = new File(dir, filename); - String contents = FileUtils.readFileToString(file, encoding); + String contents = FileUtils.fileRead(file, encoding); assertEquals(contentsTest, contents); } @@ -149,7 +148,7 @@ public File createFile(File dir, String filename, String contents, String encodi } public String getFileContents(File file, String encoding) throws IOException { - return FileUtils.readFileToString(file, encoding); + return FileUtils.fileRead(file, encoding); } protected void finalize() throws Throwable { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index 9641ef57ab08..164b1739bfc0 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -45,6 +44,7 @@ import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.Debug; import org.codehaus.plexus.testing.PlexusTest; +import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -140,7 +140,7 @@ public void testGetRemoteJar() wagonManager.getArtifact(artifact, repo, null, false); assertTrue(artifact.getFile().exists()); - assertEquals("expected", FileUtils.readFileToString(artifact.getFile(), "UTF-8")); + assertEquals("expected", FileUtils.fileRead(artifact.getFile(), "UTF-8")); } private Artifact createTestPomArtifact(String directory) throws IOException { diff --git a/maven-core/pom.xml b/maven-core/pom.xml index a2148c8ed8df..abc40b549130 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -123,6 +123,10 @@ under the License. com.google.guava failureaccess + + commons-io + commons-io + javax.inject javax.inject @@ -154,11 +158,6 @@ under the License. commons-jxpath test - - commons-io - commons-io - test - org.mockito mockito-core diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index f711255aef37..720729582f83 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Properties; -import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -49,6 +48,7 @@ import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.testing.PlexusTest; +import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; From 6103b677c19f2143eb1711176a2ef92c97000703 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 19 Mar 2023 14:35:07 +0100 Subject: [PATCH 3/3] Drop explicit dependencies on plexus-utils --- maven-compat/pom.xml | 4 ---- maven-embedder/pom.xml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 07928f93172e..fa052f0c89cd 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -80,10 +80,6 @@ under the License. javax.inject javax.inject - - org.apache.maven - plexus-utils - org.codehaus.plexus plexus-interpolation diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index ec35a862d619..5d8bcf98878b 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -107,10 +107,6 @@ under the License. javax.annotation javax.annotation-api - - org.apache.maven - plexus-utils - org.codehaus.plexus plexus-classworlds