You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2025/06/25 18:15:39 UTC
(maven-wagon) branch master updated: Replace plexus IO methods with JDK methods (#187)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git
The following commit(s) were added to refs/heads/master by this push:
new f41193b3 Replace plexus IO methods with JDK methods (#187)
f41193b3 is described below
commit f41193b331a584bd308cfbb3a4c29ae6ea820f1d
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Wed Jun 25 18:15:34 2025 +0000
Replace plexus IO methods with JDK methods (#187)
* Replace plexus IO methods with JDK methods
---
.../java/org/apache/maven/wagon/WagonUtils.java | 6 +-
.../org/apache/maven/wagon/AbstractWagonTest.java | 5 +-
.../maven/wagon/LazyFileOutputStreamTest.java | 7 +-
.../org/apache/maven/wagon/StreamWagonTest.java | 7 +-
.../apache/maven/wagon/StreamingWagonTestCase.java | 50 +++------
.../java/org/apache/maven/wagon/WagonTestCase.java | 22 ++--
.../apache/maven/wagon/http/HttpWagonTestCase.java | 125 +++++++--------------
.../maven/wagon/providers/ssh/ShellCommand.java | 6 +-
.../apache/maven/wagon/providers/ssh/TestData.java | 7 +-
.../ssh/knownhost/FileKnownHostsProviderTest.java | 10 +-
.../apache/maven/wagon/tck/http/Assertions.java | 7 +-
11 files changed, 99 insertions(+), 153 deletions(-)
diff --git a/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonUtils.java b/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonUtils.java
index 85ae8855..108aa4fd 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonUtils.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonUtils.java
@@ -20,10 +20,10 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
import java.util.LinkedList;
import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.codehaus.plexus.util.FileUtils;
/**
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
@@ -43,7 +43,9 @@ public static String toString(String resource, Wagon wagon)
wagon.get(resource, file);
- return FileUtils.fileRead(file);
+ byte[] content = Files.readAllBytes(file.toPath());
+ // TODO this method should take a character set
+ return new String(content);
} finally {
if (file != null) {
boolean deleted = file.delete();
diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
index aff719ff..e6ce9a89 100644
--- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
+++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
@@ -21,6 +21,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import junit.framework.TestCase;
import org.apache.maven.wagon.authentication.AuthenticationException;
@@ -35,7 +37,6 @@
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.apache.maven.wagon.resource.Resource;
-import org.codehaus.plexus.util.FileUtils;
import org.easymock.IAnswer;
import static org.easymock.EasyMock.*;
@@ -434,7 +435,7 @@ public void testPostProcessListeners() throws TransferFailedException, IOExcepti
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
String content = "content";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ Files.write(tempFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));
Resource resource = new Resource("resource");
diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java
index d630f035..bc141ad2 100644
--- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java
+++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java
@@ -19,9 +19,10 @@
package org.apache.maven.wagon;
import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import junit.framework.TestCase;
-import org.codehaus.plexus.util.FileUtils;
/**
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
@@ -42,13 +43,13 @@ public void testFileCreation() throws Exception {
String expected = "michal";
- stream.write(expected.getBytes());
+ stream.write(expected.getBytes(StandardCharsets.UTF_8));
stream.close();
assertTrue(file.exists());
- String actual = FileUtils.fileRead(file);
+ String actual = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
assertEquals(expected, actual);
}
diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java
index 8fbd1cbc..59db8e63 100644
--- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java
+++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.text.SimpleDateFormat;
import junit.framework.TestCase;
@@ -33,7 +34,6 @@
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
-import org.codehaus.plexus.util.FileUtils;
import static org.easymock.EasyMock.*;
@@ -277,7 +277,8 @@ public void fillInputData(InputData inputData) {
wagon.connect(repository);
try {
wagon.get("resource", tempFile);
- assertEquals(content, FileUtils.fileRead(tempFile));
+ String actual = new String(Files.readAllBytes(tempFile.toPath()));
+ assertEquals(content, actual);
} finally {
wagon.disconnect();
tempFile.delete();
@@ -375,7 +376,7 @@ public void testPut() throws Exception {
final String content = "the content to return";
final File tempFile = File.createTempFile("wagon", "tmp");
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ Files.write(tempFile.toPath().toAbsolutePath(), content.getBytes());
tempFile.deleteOnExit();
OutputStream out = new ByteArrayOutputStream();
diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java
index 8a405b4e..539363b4 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java
@@ -23,12 +23,14 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.text.SimpleDateFormat;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.resource.Resource;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
+
+import static org.junit.Assert.assertArrayEquals;
/**
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
@@ -63,10 +65,7 @@ public void testFailedGetToStream() throws Exception {
destFile.deleteOnExit();
- OutputStream stream = null;
-
- try {
- stream = new FileOutputStream(destFile);
+ try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getToStream("fubar.txt", stream);
fail("File was found when it shouldn't have been");
} catch (ResourceDoesNotExistException e) {
@@ -77,8 +76,6 @@ public void testFailedGetToStream() throws Exception {
wagon.disconnect();
- IOUtil.close(stream);
-
tearDownWagonTestingFixtures();
}
}
@@ -149,13 +146,10 @@ public void testFailedGetIfNewerToStream() throws Exception {
wagon.connect(testRepository, getAuthInfo());
destFile = FileTestUtils.createUniqueFile(getName(), getName());
destFile.deleteOnExit();
- OutputStream stream = null;
- try {
- stream = new FileOutputStream(destFile);
+
+ try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getIfNewerToStream("fubar.txt", stream, 0);
fail("File was found when it shouldn't have been");
- stream.close();
- stream = null;
} catch (ResourceDoesNotExistException e) {
// expected
assertTrue(true);
@@ -164,8 +158,6 @@ public void testFailedGetIfNewerToStream() throws Exception {
wagon.disconnect();
- IOUtil.close(stream);
-
tearDownWagonTestingFixtures();
}
}
@@ -188,22 +180,22 @@ protected void streamRoundTripTesting() throws Exception {
assertEquals("compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum());
- // Now compare the conents of the artifact that was placed in
+ // Now compare the contents of the artifact that was placed in
// the repository with the contents of the artifact that was
// retrieved from the repository.
- String sourceContent = FileUtils.fileRead(sourceFile);
+ byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());
- String destContent = FileUtils.fileRead(destFile);
+ byte[] destContent = Files.readAllBytes(destFile.toPath());
- assertEquals(sourceContent, destContent);
+ assertArrayEquals(sourceContent, destContent);
}
private int putStream() throws Exception {
String content = "test-resource.txt\n";
sourceFile = new File(FileTestUtils.getTestOutputDir(), "test-resource");
sourceFile.getParentFile().mkdirs();
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), content);
+ Files.write(sourceFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));
StreamingWagon wagon = (StreamingWagon) getWagon();
@@ -213,17 +205,10 @@ private int putStream() throws Exception {
connectWagon(wagon);
- InputStream stream = null;
-
- try {
- stream = new FileInputStream(sourceFile);
+ try (InputStream stream = new FileInputStream(sourceFile)) {
wagon.putFromStream(stream, resource, sourceFile.length(), sourceFile.lastModified());
- stream.close();
- stream = null;
} catch (Exception e) {
logger.error("error while putting resources to the FTP Server", e);
- } finally {
- IOUtil.close(stream);
}
disconnectWagon(wagon);
@@ -244,17 +229,10 @@ private void getStream(int expectedSize) throws Exception {
connectWagon(wagon);
- OutputStream stream = null;
-
- try {
- stream = new FileOutputStream(destFile);
+ try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getToStream(this.resource, stream);
- stream.close();
- stream = null;
} catch (Exception e) {
logger.error("error while reading resources from the FTP Server", e);
- } finally {
- IOUtil.close(stream);
}
disconnectWagon(wagon);
diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
index fc99281d..2f34434b 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -54,6 +55,7 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertArrayEquals;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -325,9 +327,9 @@ protected void assertGetIfNewerTest(ProgressAnswer progressAnswer, boolean expec
// the repository with the contents of the artifact that was
// retrieved from the repository.
- String sourceContent = FileUtils.fileRead(sourceFile);
- String destContent = FileUtils.fileRead(destFile);
- assertEquals(sourceContent, destContent);
+ byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());
+ byte[] destContent = Files.readAllBytes(destFile.toPath());
+ assertArrayEquals(sourceContent, destContent);
} else {
verify(mockTransferListener);
@@ -583,7 +585,7 @@ protected void assertNotExists(Wagon wagon, String resourceName)
private void writeTestFile(String child) throws IOException {
File dir = new File(sourceFile, child);
dir.getParentFile().mkdirs();
- FileUtils.fileWrite(dir.getAbsolutePath(), child);
+ Files.write(dir.toPath().toAbsolutePath(), child.getBytes());
}
public void testFailedGet() throws Exception {
@@ -788,7 +790,7 @@ public void testWagonResourceNotExists() throws Exception {
protected void putFile(String resourceName, String testFileName, String content) throws Exception {
sourceFile = new File(FileTestUtils.getTestOutputDir(), testFileName);
sourceFile.getParentFile().mkdirs();
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), content);
+ Files.write(sourceFile.toPath().toAbsolutePath(), content.getBytes());
Wagon wagon = getWagon();
@@ -958,15 +960,13 @@ protected void fileRoundTripTesting() throws Exception {
assertEquals("compare checksums", TEST_CKSUM, checksumObserver.getActualChecksum());
- // Now compare the conents of the artifact that was placed in
+ // Now compare the contents of the artifact that was placed in
// the repository with the contents of the artifact that was
// retrieved from the repository.
- String sourceContent = FileUtils.fileRead(sourceFile);
-
- String destContent = FileUtils.fileRead(destFile);
-
- assertEquals(sourceContent, destContent);
+ byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());
+ byte[] destContent = Files.readAllBytes(destFile.toPath());
+ assertArrayEquals(sourceContent, destContent);
}
// ----------------------------------------------------------------------
diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
index 937d210e..a320f46a 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
@@ -31,6 +31,8 @@
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@@ -79,6 +81,8 @@
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Password;
+import static org.junit.Assert.assertArrayEquals;
+
/**
*
*/
@@ -433,7 +437,7 @@ public void testGzipGet() throws Exception {
wagon.disconnect();
- String destContent = FileUtils.fileRead(destFile);
+ String destContent = new String(Files.readAllBytes(destFile.toPath()));
assertEquals(sourceContent, destContent);
} finally {
@@ -441,56 +445,6 @@ public void testGzipGet() throws Exception {
}
}
- /* This test cannot be enabled because we cannot tell GzipFilter to compress with deflate only
- public void testDeflateGet()
- throws Exception
- {
- Server server = new Server( );
-
- String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
- ServletContextHandler root = new ServletContextHandler( ServletContextHandler.SESSIONS );
- root.setResourceBase( localRepositoryPath );
- ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
- root.addServlet( servletHolder, "/*" );
- FilterHolder filterHolder = new FilterHolder( new GzipFilter() );
- root.addFilter( filterHolder, "/deflate/*", EnumSet.of( DispatcherType.REQUEST ) );
- addConnector( server );
- server.setHandler( root );
- server.start();
-
- try
- {
- Wagon wagon = getWagon();
-
- Repository testRepository = new Repository( "id", getRepositoryUrl( server ) );
-
- File sourceFile = new File( localRepositoryPath + "/deflate" );
-
- sourceFile.deleteOnExit();
-
- String resName = "deflate-res.txt";
- String sourceContent = writeTestFile( sourceFile, resName, null );
-
- wagon.connect( testRepository );
-
- File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
-
- destFile.deleteOnExit();
-
- wagon.get( "deflate/" + resName, destFile );
-
- wagon.disconnect();
-
- String destContent = FileUtils.fileRead( destFile );
-
- assertEquals( sourceContent, destContent );
- }
- finally
- {
- server.stop();
- }
- }*/
-
public void testProxiedRequest() throws Exception {
ProxyInfo proxyInfo = createProxyInfo();
TestHeaderHandler handler = new TestHeaderHandler();
@@ -585,7 +539,7 @@ public void testRedirectGetToStream() throws Exception {
wagon.getToStream("resource", fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
- String found = FileUtils.fileRead(tmpResult);
+ String found = new String(Files.readAllBytes(tmpResult.toPath()));
assertEquals("found:'" + found + "'", "Hello, World!", found);
checkHandlerResult(redirectHandler.handlerRequestResponses, HttpServletResponse.SC_SEE_OTHER);
@@ -640,7 +594,7 @@ public void testRedirectGet() throws Exception {
try {
wagon.get("resource", tmpResult);
- String found = FileUtils.fileRead(tmpResult);
+ String found = new String(Files.readAllBytes(tmpResult.toPath()));
assertEquals("found:'" + found + "'", "Hello, World!", found);
checkHandlerResult(redirectHandler.handlerRequestResponses, HttpServletResponse.SC_SEE_OTHER);
@@ -706,11 +660,13 @@ public void testRedirectPutFromStreamWithFullUrl() throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ Files.write(tempFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));
try (FileInputStream fileInputStream = new FileInputStream(tempFile)) {
wagon.putFromStream(fileInputStream, "test-secured-put-resource", content.length(), -1);
- assertEquals(content, FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ String actual =
+ new String(Files.readAllBytes(sourceFile.toPath().toAbsolutePath()), StandardCharsets.UTF_8);
+ assertEquals(content, actual);
checkRequestResponseForRedirectPutWithFullUrl(redirectHandler, putHandler);
} finally {
@@ -766,11 +722,13 @@ public void testRedirectPutFromStreamRelativeUrl() throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ Files.write(tempFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));
try (FileInputStream fileInputStream = new FileInputStream(tempFile)) {
wagon.putFromStream(fileInputStream, "test-secured-put-resource", content.length(), -1);
- assertEquals(content, FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ assertEquals(
+ content,
+ new String(Files.readAllBytes(sourceFile.toPath().toAbsolutePath()), StandardCharsets.UTF_8));
checkRequestResponseForRedirectPutWithRelativeUrl(redirectHandler, putHandler);
} finally {
@@ -857,12 +815,13 @@ public void testRedirectPutFileWithFullUrl() throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ byte[] content = "put top secret".getBytes(StandardCharsets.UTF_8);
+ Files.write(tempFile.toPath().toAbsolutePath(), content);
try {
wagon.put(tempFile, "test-secured-put-resource");
- assertEquals(content, FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ assertArrayEquals(
+ content, Files.readAllBytes(sourceFile.toPath().toAbsolutePath()));
checkRequestResponseForRedirectPutWithFullUrl(redirectHandler, putHandler);
} finally {
@@ -911,12 +870,13 @@ public void testRedirectPutFileRelativeUrl() throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ byte[] content = "put top secret".getBytes(StandardCharsets.UTF_8);
+ Files.write(tempFile.toPath().toAbsolutePath(), content);
try {
wagon.put(tempFile, "test-secured-put-resource");
- assertEquals(content, FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ assertArrayEquals(
+ content, Files.readAllBytes(sourceFile.toPath().toAbsolutePath()));
checkRequestResponseForRedirectPutWithRelativeUrl(redirectHandler, putHandler);
} finally {
@@ -962,7 +922,7 @@ public void testRedirectPutFailureNonRepeatableStream() throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ Files.write(tempFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));
try (FileInputStream fileInputStream = new FileInputStream(tempFile)) {
wagon.putFromStream(fileInputStream, "test-secured-put-resource", content.length(), -1);
@@ -1056,7 +1016,7 @@ private void runTestProxiedRequest(ProxyInfo proxyInfo, TestHeaderHandler handle
String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
File sourceFile = new File(localRepositoryPath, "test-proxied-resource");
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), "content");
+ Files.write(sourceFile.toPath().toAbsolutePath(), "content".getBytes(StandardCharsets.UTF_8));
wagon.connect(testRepository, proxyInfo);
@@ -1110,7 +1070,7 @@ private void runTestProxiedRequestWithProvider(ProxyInfoProvider proxyInfoProvid
String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
File sourceFile = new File(localRepositoryPath, "test-proxied-resource");
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), "content");
+ Files.write(sourceFile.toPath().toAbsolutePath(), "content".getBytes(StandardCharsets.UTF_8));
wagon.connect(testRepository, proxyInfoProvider);
@@ -1176,7 +1136,7 @@ public void runTestSecuredGet(AuthenticationInfo authInfo) throws Exception {
Repository testRepository = new Repository("id", getRepositoryUrl(server));
File sourceFile = new File(localRepositoryPath, "test-secured-resource");
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), "top secret");
+ Files.write(sourceFile.toPath().toAbsolutePath(), "top secret".getBytes(StandardCharsets.UTF_8));
wagon.connect(testRepository, authInfo);
@@ -1188,12 +1148,10 @@ public void runTestSecuredGet(AuthenticationInfo authInfo) throws Exception {
wagon.disconnect();
}
- FileInputStream in = new FileInputStream(file);
-
- assertEquals("top secret", IOUtil.toString(in));
+ assertEquals("top secret", new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8));
/*
- * We need to wait a bit for all Jetty workers/threads to complete their work. Otherwise
+ * We need to wait a bit for all Jetty workers/threads to complete their work. Otherwise,
* we may suffer from race conditions where handlerRequestResponses list is not completely
* populated and its premature iteration in testPreemptiveAuthenticationGet will lead to
* a test failure.
@@ -1229,7 +1187,7 @@ public void runTestSecuredGetToStream(AuthenticationInfo authInfo) throws Except
Repository testRepository = new Repository("id", getRepositoryUrl(server));
File sourceFile = new File(localRepositoryPath, "test-secured-resource");
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), "top secret");
+ Files.write(sourceFile.toPath().toAbsolutePath(), "top secret".getBytes(StandardCharsets.US_ASCII));
wagon.connect(testRepository, authInfo);
@@ -1243,7 +1201,7 @@ public void runTestSecuredGetToStream(AuthenticationInfo authInfo) throws Except
assertEquals("top secret", out.toString("US-ASCII"));
/*
- * We need to wait a bit for all Jetty workers/threads to complete their work. Otherwise
+ * We need to wait a bit for all Jetty workers/threads to complete their work. Otherwise,
* we may suffer from race conditions where handlerRequestResponses list is not completely
* populated and its premature iteration in testPreemptiveAuthenticationGet will lead to
* a test failure.
@@ -1298,7 +1256,7 @@ public void runTestSecuredResourceExists(AuthenticationInfo authInfo) throws Exc
Repository testRepository = new Repository("id", getRepositoryUrl(server));
File sourceFile = new File(localRepositoryPath, "test-secured-resource-exists");
- FileUtils.fileWrite(sourceFile.getAbsolutePath(), "top secret");
+ Files.write(sourceFile.toPath().toAbsolutePath(), "top secret".getBytes(StandardCharsets.US_ASCII));
wagon.connect(testRepository, authInfo);
@@ -1439,7 +1397,7 @@ public void handle(
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- FileUtils.fileWrite(tempFile.getAbsolutePath(), "content");
+ Files.write(tempFile.toPath().toAbsolutePath(), "content".getBytes(StandardCharsets.US_ASCII));
try {
wagon.put(tempFile, "resource");
@@ -1467,7 +1425,7 @@ private void runTestPut(int status) throws Exception {
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- FileUtils.fileWrite(tempFile.getAbsolutePath(), "content");
+ Files.write(tempFile.toPath().toAbsolutePath(), "content".getBytes(StandardCharsets.US_ASCII));
String baseUrl = getRepositoryUrl(server);
String resourceName = "resource";
@@ -1544,7 +1502,8 @@ public void runTestSecuredPut(AuthenticationInfo authInfo, int putNumber) throws
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- FileUtils.fileWrite(tempFile.getAbsolutePath(), "put top secret");
+ byte[] content = "put top secret".getBytes(StandardCharsets.US_ASCII);
+ Files.write(tempFile.toPath().toAbsolutePath(), content);
try {
wagon.put(tempFile, "test-secured-put-resource");
@@ -1552,7 +1511,8 @@ public void runTestSecuredPut(AuthenticationInfo authInfo, int putNumber) throws
tempFile.delete();
}
- assertEquals("put top secret", FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ assertArrayEquals(
+ content, Files.readAllBytes(sourceFile.toPath().toAbsolutePath()));
}
} finally {
wagon.disconnect();
@@ -1609,16 +1569,17 @@ public void runTestSecuredPutFromStream(AuthenticationInfo authInfo, int putNumb
File tempFile = File.createTempFile("wagon", "tmp");
tempFile.deleteOnExit();
- String content = "put top secret";
- FileUtils.fileWrite(tempFile.getAbsolutePath(), content);
+ byte[] content = "put top secret".getBytes(StandardCharsets.UTF_8);
+ Files.write(tempFile.toPath().toAbsolutePath(), content);
try (FileInputStream fileInputStream = new FileInputStream(tempFile)) {
- wagon.putFromStream(fileInputStream, "test-secured-put-resource", content.length(), -1);
+ wagon.putFromStream(fileInputStream, "test-secured-put-resource", content.length, -1);
} finally {
tempFile.delete();
}
- assertEquals(content, FileUtils.fileRead(sourceFile.getAbsolutePath()));
+ assertArrayEquals(
+ content, Files.readAllBytes(sourceFile.toPath().toAbsolutePath()));
}
} finally {
wagon.disconnect();
diff --git a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ShellCommand.java b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ShellCommand.java
index c91e5767..85b0ac07 100644
--- a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ShellCommand.java
+++ b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ShellCommand.java
@@ -22,11 +22,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
-import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
@@ -80,9 +80,9 @@ public void start(Environment env) throws IOException {
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
try {
- // hackhish defaut commandline tools not support ; or && so write a file with the script
+ // hackish default commandline tools not support ; or && so write a file with the script
// and "/bin/sh -e " + tmpFile.getPath();
- FileUtils.fileWrite(tmpFile, commandLine);
+ Files.write(tmpFile.toPath(), commandLine.getBytes());
Commandline cl = new Commandline();
cl.setExecutable("/bin/sh");
diff --git a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestData.java b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestData.java
index 72bd9302..126d7de8 100644
--- a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestData.java
+++ b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestData.java
@@ -20,8 +20,8 @@
import java.io.File;
import java.io.IOException;
-
-import org.codehaus.plexus.util.FileUtils;
+import java.nio.file.Files;
+import java.nio.file.Path;
/**
* @author <a href="michal@codehaus.org">Michal Maczka</a>
@@ -62,7 +62,8 @@ public static String getHostname() {
public static String getHostKey() {
try {
- return FileUtils.fileRead(new File(System.getProperty("sshKeysPath"), "id_rsa.pub").getPath())
+ Path sshKeysPath = new File(System.getProperty("sshKeysPath"), "id_rsa.pub").toPath();
+ return new String(Files.readAllBytes(sshKeysPath))
.substring("ssh-rsa".length())
.trim();
} catch (IOException e) {
diff --git a/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProviderTest.java b/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProviderTest.java
index f1b919b0..037c32fa 100644
--- a/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProviderTest.java
+++ b/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProviderTest.java
@@ -19,10 +19,14 @@
package org.apache.maven.wagon.providers.ssh.knownhost;
import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import junit.framework.TestCase;
import org.codehaus.plexus.util.FileUtils;
+import static org.junit.Assert.assertNotEquals;
+
public class FileKnownHostsProviderTest extends TestCase {
private File basedir = new File(System.getProperty("basedir", "."));
@@ -44,7 +48,7 @@ public void testStoreKnownHostsNoChange() throws Exception {
long timestamp = this.testKnownHostsFile.lastModified();
// file with the same contents, but with entries swapped
File sameKnownHostFile = new File(basedir, "src/test/resources/known_hosts_same");
- String contents = FileUtils.fileRead(sameKnownHostFile);
+ String contents = new String(Files.readAllBytes(sameKnownHostFile.toPath()), StandardCharsets.US_ASCII);
provider.storeKnownHosts(contents);
assertEquals("known_hosts file is rewritten", timestamp, testKnownHostsFile.lastModified());
@@ -53,10 +57,10 @@ public void testStoreKnownHostsNoChange() throws Exception {
public void testStoreKnownHostsWithChange() throws Exception {
long timestamp = this.testKnownHostsFile.lastModified();
File sameKnownHostFile = new File(basedir, "src/test/resources/known_hosts_same");
- String contents = FileUtils.fileRead(sameKnownHostFile);
+ String contents = new String(Files.readAllBytes(sameKnownHostFile.toPath()), StandardCharsets.US_ASCII);
contents += "1 2 3";
provider.storeKnownHosts(contents);
- assertTrue("known_hosts file is not rewritten", timestamp != testKnownHostsFile.lastModified());
+ assertNotEquals("known_hosts file is not rewritten", timestamp, testKnownHostsFile.lastModified());
}
}
diff --git a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/Assertions.java b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/Assertions.java
index 35bda8d5..f889c6f3 100644
--- a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/Assertions.java
+++ b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/Assertions.java
@@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
@@ -33,14 +34,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.codehaus.plexus.util.FileUtils.fileRead;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/**
- *
- */
public final class Assertions {
public static final int NO_RESPONSE_STATUS_CODE = -1;
@@ -51,7 +48,7 @@ public static void assertFileContentsFromResource(
final String resourceBase, final String resourceName, final File output, final String whyWouldItFail)
throws IOException {
String content = readResource(resourceBase, resourceName);
- String test = fileRead(output);
+ String test = new String(Files.readAllBytes(output.toPath()));
assertEquals(whyWouldItFail, content, test);
}