From 703f814e34a04924ecec923d8f45508600d97b0f Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 19 Mar 2023 21:19:22 +0100 Subject: [PATCH] [MNG-6825] Replace FileUtils with Commons IO (#1067) * [MNG-6825] Replace FileUtils with Commons IO Co-authored-by: Moderne * Minor fixes and reverts where cases are not handled yet * Drop explicit dependencies on plexus-utils --------- Co-authored-by: Moderne --- maven-compat/pom.xml | 4 ---- .../artifact/repository/metadata/MetadataBridge.java | 2 +- .../maven/artifact/deployer/ArtifactDeployerTest.java | 7 ++++--- maven-core/pom.xml | 9 ++++----- .../maven/project/artifact/ProjectArtifactMetadata.java | 2 +- .../maven/artifact/handler/ArtifactHandlerTest.java | 4 ++-- .../apache/maven/internal/impl/TestRepositorySystem.java | 2 +- .../apache/maven/repository/TestRepositoryConnector.java | 2 +- .../apache/maven/repository/TestRepositorySystem.java | 2 +- maven-embedder/pom.xml | 4 ---- .../apache/maven/cli/CLIManagerDocumentationTest.java | 4 ++-- 11 files changed, 17 insertions(+), 25 deletions(-) diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 07928f9317..fa052f0c89 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-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 fbe682a052..48eea0ac53 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.io.File; 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/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java index 1d8278f44d..29bf7494f2 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 javax.inject.Inject; 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,15 @@ public class ArtifactDeployerTest extends AbstractArtifactComponentTestCase { 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-core/pom.xml b/maven-core/pom.xml index a2148c8ed8..abc40b5491 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/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java b/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java index 4071681424..f00cb4b2b7 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 @@ package org.apache.maven.project.artifact; 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/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 5d64c32ef4..bc062ee882 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 javax.inject.Inject; 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 f34eb51e60..3f3d1e08a7 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.LinkedHashMap; 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.repository.RepositorySystem; 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 4fd761003e..6f9d963904 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.MalformedURLException; 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 e882e517c8..bb198ec663 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.List; 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.project.artifact.ArtifactWithDependencies; 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/pom.xml b/maven-embedder/pom.xml index ec35a862d6..5d8bcf9887 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 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 ed6c159bf3..19a1efa2b2 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.Comparator; 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 class CLIManagerDocumentationTest { @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"); } }