[MNG-6825] Replace FileUtils with Commons IO (#1067)

* [MNG-6825] Replace FileUtils with Commons IO

Co-authored-by: Moderne <team@moderne.io>

* Minor fixes and reverts where cases are not handled yet

* Drop explicit dependencies on plexus-utils

---------

Co-authored-by: Moderne <team@moderne.io>
This commit is contained in:
Tim te Beek 2023-03-19 21:19:22 +01:00 committed by GitHub
parent f071094f34
commit 703f814e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 25 deletions

View File

@ -80,10 +80,6 @@ under the License.
<groupId>javax.inject</groupId> <groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId> <artifactId>javax.inject</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interpolation</artifactId> <artifactId>plexus-interpolation</artifactId>

View File

@ -22,10 +22,10 @@ import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.RepositoryException; import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.metadata.AbstractMetadata; import org.eclipse.aether.metadata.AbstractMetadata;
import org.eclipse.aether.metadata.MergeableMetadata; import org.eclipse.aether.metadata.MergeableMetadata;

View File

@ -22,12 +22,12 @@ import javax.inject.Inject;
import java.io.File; import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.session.scope.internal.SessionScope; import org.apache.maven.session.scope.internal.SessionScope;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
@ -60,14 +60,15 @@ public class ArtifactDeployerTest extends AbstractArtifactComponentTestCase {
Artifact artifact = createArtifact("artifact", "1.0"); Artifact artifact = createArtifact("artifact", "1.0");
File file = new File(artifactBasedir, "artifact-1.0.jar"); 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()); artifactDeployer.deploy(file, artifact, remoteRepository(), localRepository());
ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository remoteRepository = remoteRepository();
File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact)); File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact));
assertTrue(deployedFile.exists()); assertTrue(deployedFile.exists());
assertEquals("dummy", FileUtils.fileRead(deployedFile, "UTF-8").trim()); assertEquals(
"dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim());
} finally { } finally {
sessionScope.exit(); sessionScope.exit();
} }

View File

@ -123,6 +123,10 @@ under the License.
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId> <artifactId>failureaccess</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency> <dependency>
<groupId>javax.inject</groupId> <groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId> <artifactId>javax.inject</artifactId>
@ -154,11 +158,6 @@ under the License.
<artifactId>commons-jxpath</artifactId> <artifactId>commons-jxpath</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -21,12 +21,12 @@ package org.apache.maven.project.artifact;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractArtifactMetadata; import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
import org.codehaus.plexus.util.FileUtils;
/** /**
* Attach a POM to an artifact. * Attach a POM to an artifact.

View File

@ -23,9 +23,9 @@ import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
@ -40,7 +40,7 @@ public class ArtifactHandlerTest {
public void testAptConsistency() throws Exception { public void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt"); File apt = getTestFile("src/site/apt/artifact-handlers.apt");
List<String> lines = FileUtils.loadFile(apt); List<String> lines = FileUtils.readLines(apt);
for (String line : lines) { for (String line : lines) {
if (line.startsWith("||")) { if (line.startsWith("||")) {

View File

@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Model;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; 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.Mirror;
import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server; import org.apache.maven.settings.Server;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;

View File

@ -24,7 +24,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Collection; 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.artifact.Artifact;
import org.eclipse.aether.metadata.Metadata; import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RemoteRepository;

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Model;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; 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.Mirror;
import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server; import org.apache.maven.settings.Server;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;

View File

@ -107,10 +107,6 @@ under the License.
<groupId>javax.annotation</groupId> <groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId> <artifactId>javax.annotation-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId> <artifactId>plexus-classworlds</artifactId>

View File

@ -27,7 +27,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.codehaus.plexus.util.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** /**
@ -88,6 +88,6 @@ public class CLIManagerDocumentationTest {
@Test @Test
public void testOptionsAsHtml() throws IOException { public void testOptionsAsHtml() throws IOException {
File options = new File("target/test-classes/options.html"); File options = new File("target/test-classes/options.html");
FileUtils.fileWrite(options, "UTF-8", getOptionsAsHtml()); FileUtils.write(options, getOptionsAsHtml(), "UTF-8");
} }
} }