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 2020/08/03 11:31:36 UTC

[maven-shared-io] branch 31 created (now ab061eb)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch 31
in repository https://gitbox.apache.org/repos/asf/maven-shared-io.git.


      at ab061eb  deprecate Utils class

This branch includes the following new commits:

     new ab061eb  deprecate Utils class

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-shared-io] 01/01: deprecate Utils class

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch 31
in repository https://gitbox.apache.org/repos/asf/maven-shared-io.git

commit ab061eb41c24ddb576061098405b07a4ca8446d5
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Mon Aug 3 07:31:23 2020 -0400

    deprecate Utils class
---
 pom.xml                                            |  6 ++++
 .../java/org/apache/maven/shared/io/Utils.java     | 10 ++++++
 .../io/download/DefaultDownloadManagerTest.java    | 36 +++++++++++-----------
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5e5ab5d..9b9f226 100644
--- a/pom.xml
+++ b/pom.xml
@@ -112,6 +112,12 @@
       <version>3.2</version>
       <scope>test</scope>
     </dependency>
+   <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
diff --git a/src/test/java/org/apache/maven/shared/io/Utils.java b/src/test/java/org/apache/maven/shared/io/Utils.java
index 59e6c7f..803e8fa 100644
--- a/src/test/java/org/apache/maven/shared/io/Utils.java
+++ b/src/test/java/org/apache/maven/shared/io/Utils.java
@@ -27,6 +27,7 @@ import java.io.Writer;
 
 import org.apache.maven.shared.utils.WriterFactory;
 
+@Deprecated
 public final class Utils
 {
 
@@ -34,6 +35,10 @@ public final class Utils
     {
     }
 
+    /**
+     * deprecated use Apache Commons IO {@code FileUtils.writeStringToFile} instead
+     */
+    @Deprecated
     public static void writeFileWithEncoding( File file, String content, String encoding )
         throws IOException
     {
@@ -43,6 +48,11 @@ public final class Utils
         }
     }
 
+    /**
+     * deprecated use Apache Commons Lang
+     *     {@code org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(Throwable)} instead
+     */
+    @Deprecated
     public static String toString( Throwable error )
     {
         StringWriter sw = new StringWriter();
diff --git a/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java b/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java
index f846089..fc7363d 100644
--- a/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java
+++ b/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java
@@ -31,8 +31,8 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.maven.artifact.manager.WagonManager;
-import org.apache.maven.shared.io.Utils;
 import org.apache.maven.shared.io.logging.DefaultMessageHolder;
 import org.apache.maven.shared.io.logging.MessageHolder;
 import org.apache.maven.wagon.ConnectionException;
@@ -117,7 +117,7 @@ public class DefaultDownloadManagerTest
 
         DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
 
-        downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+        downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
         verify( wagon, wagonManager );
     }
@@ -134,11 +134,11 @@ public class DefaultDownloadManagerTest
 
         DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
 
-        File first = downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+        File first = downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
         MessageHolder mh = new DefaultMessageHolder();
 
-        File second = downloadManager.download( tempFile.toURL().toExternalForm(), mh );
+        File second = downloadManager.download( tempFile.toURI().toASCIIString(), mh );
 
         assertSame( first, second );
         assertEquals( 1, mh.size() );
@@ -165,7 +165,7 @@ public class DefaultDownloadManagerTest
 
         DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
 
-        downloadManager.download( tempFile.toURL().toExternalForm(), Collections.singletonList( transferListener ),
+        downloadManager.download( tempFile.toURI().toASCIIString(), Collections.singletonList( transferListener ),
                                   new DefaultMessageHolder() );
 
         verify( wagon, wagonManager, transferListener );
@@ -185,13 +185,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to retrieve wagon." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "UnsupportedProtocolException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "UnsupportedProtocolException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -211,13 +211,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to connect wagon." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "ConnectionException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "ConnectionException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -237,13 +237,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to connect wagon." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "AuthenticationException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "AuthenticationException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -263,13 +263,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to get resource." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "TransferFailedException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "TransferFailedException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -289,13 +289,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to get resource." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "ResourceDoesNotExistException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "ResourceDoesNotExistException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -315,13 +315,13 @@ public class DefaultDownloadManagerTest
 
         try
         {
-            downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
+            downloadManager.download( tempFile.toURI().toASCIIString(), new DefaultMessageHolder() );
 
             fail( "should have failed to get resource." );
         }
         catch ( DownloadFailedException e )
         {
-            assertTrue( Utils.toString( e ).indexOf( "AuthorizationException" ) > -1 );
+            assertTrue( ExceptionUtils.getStackTrace( e ).indexOf( "AuthorizationException" ) > -1 );
         }
 
         verify( wagon, wagonManager );
@@ -341,7 +341,7 @@ public class DefaultDownloadManagerTest
 
         MessageHolder mh = new DefaultMessageHolder();
 
-        downloadManager.download( tempFile.toURL().toExternalForm(), mh );
+        downloadManager.download( tempFile.toURI().toASCIIString(), mh );
 
         assertTrue( mh.render().indexOf( "ConnectionException" ) > -1 );