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/05/28 10:47:19 UTC

[maven-shared-utils] branch master updated: [MSHARED-893] deprecate more file methods we don't need in Java 7+ (#36)

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-shared-utils.git


The following commit(s) were added to refs/heads/master by this push:
     new c2ec379  [MSHARED-893] deprecate more file methods we don't need in Java 7+ (#36)
c2ec379 is described below

commit c2ec37910f2231722ccfc3becc8745669bfbb6c9
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Thu May 28 06:47:11 2020 -0400

    [MSHARED-893] deprecate more file methods we don't need in Java 7+ (#36)
    
    * deprecate more obsolete methods
---
 .../apache/maven/shared/utils/io/FileUtils.java    | 58 ++++++++++++++++------
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
index a3014ec..d8023c5 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
@@ -470,7 +470,9 @@ public class FileUtils
      * Deletes a file.
      *
      * @param fileName the path of the file to delete
+     * @deprecated use {@code Files.delete(Paths.get(fileName))}
      */
+    @Deprecated
     public static void fileDelete( @Nonnull String fileName )
     {
         File file = new File( fileName );
@@ -481,11 +483,11 @@ public class FileUtils
     /**
      * Given a directory and an array of extensions return an array of compliant files.
      * <p/>
-     * The given extensions should be like "java" and not like ".java"
+     * The given extensions should be like "java" and not like ".java".
      *
      * @param directory  the path of the directory
      * @param extensions an array of expected extensions
-     * @return tn array of files for the wanted extensions
+     * @return an array of files for the wanted extensions
      */
     public static String[] getFilesFromExtension( @Nonnull String directory, @Nonnull String... extensions )
     {
@@ -573,12 +575,14 @@ public class FileUtils
     }
 
     /**
-     * Simple way to make a directory
+     * Simple way to make a directory.
      *
      * @param dir the directory to create
-     * @throws IllegalArgumentException if the dir contains illegal Windows characters under Windows OS.
+     * @throws IllegalArgumentException if the dir contains illegal Windows characters under Windows OS
      * @see #INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
+     * @deprecated use {@code java.nio.file.Files.createDirectories(Paths.get(dir))}
      */
+    @Deprecated
     public static void mkdir( @Nonnull String dir )
     {
         File file = new File( dir );
@@ -682,7 +686,7 @@ public class FileUtils
     }
 
     /**
-     * Remove extension from filename. E.g.
+     * Remove extension from a path. E.g.
      * <pre>
      * foo.txt    --> foo
      * a\b\c.jpg --> a\b\c
@@ -691,7 +695,9 @@ public class FileUtils
      *
      * @param filename the path of the file
      * @return the filename minus extension
+     * @deprecated use {@code org.apache.commons.io.FilenameUtils.removeExtension()}
      */
+    @Deprecated
     @Nonnull public static String removeExtension( @Nonnull final String filename )
     {
         String ext = extension( filename );
@@ -706,7 +712,7 @@ public class FileUtils
     }
 
     /**
-     * Get extension from filename. E.g.
+     * Get extension from a path. E.g.
      *
      * <pre>
      * foo.txt    --> "txt"
@@ -716,7 +722,9 @@ public class FileUtils
      *
      * @param filename the path of the file
      * @return the extension of filename or "" if none
+     * @deprecated use {@code org.apache.commons.io.FilenameUtils.getExtension()}
      */
+    @Deprecated
     @Nonnull public static String getExtension( @Nonnull final String filename )
     {
         return extension( filename );
@@ -734,7 +742,9 @@ public class FileUtils
      * @throws IOException                   if <code>source</code> does not exist, the file in
      *                                       <code>destinationDirectory</code> cannot be written to, or an IO error
      *                                       occurs during copying.
+     * @deprecated use {@code org.apache.commons.io.FileUtils.copyFileToDirectory()}
      */
+    @Deprecated
     public static void copyFileToDirectory( @Nonnull final File source, @Nonnull final File destinationDirectory )
         throws IOException
     {
@@ -784,7 +794,10 @@ public class FileUtils
      * @throws IOException  if <code>source</code> does not exist, <code>destination</code> cannot be
      *                      written to, or an IO error occurs during copying
      * @throws java.io.FileNotFoundException if <code>destination</code> is a directory
+     * @deprecated use {@code java.nio.Files.copy(source.toPath(), destination.toPath(), CopyOptions.NOFOLLOW_LINKS,
+     *     CopyOptions.REPLACE_EXISTING)}
      */
+    @Deprecated
     public static void copyFile( @Nonnull final File source, @Nonnull final File destination )
         throws IOException
     {
@@ -891,6 +904,8 @@ public class FileUtils
      *                     <li><code>destination</code> cannot be written to</li>
      *                     <li>an IO error occurs during copying</li>
      *                     </ul>
+     * @deprecated use {@code java.nio.Files.copy(source.openStream(), destination.toPath(),
+     *     CopyOptions.REPLACE_EXISTING)}
      */
     public static void copyURLToFile( @Nonnull final URL source, @Nonnull final File destination )
         throws IOException
@@ -909,11 +924,14 @@ public class FileUtils
      *                    overwriting).
      * @throws IOException if
      *                     <ul>
-     *                     <li><code>source</code> URL cannot be opened</li>
+     *                     <li><code>source</code> cannot be opened</li>
      *                     <li><code>destination</code> cannot be written to</li>
-     *                     <li>an IO error occurs during copying</li>
+     *                     <li>an I/O error occurs during copying</li>
      *                     </ul>
+     * @deprecated use {@code java.nio.Files.copy(source, destination.toPath(),
+     *     CopyOptions.REPLACE_EXISTING)}
      */
+    @Deprecated
     private static void copyStreamToFile( @Nonnull @WillClose final InputStream source,
                                           @Nonnull final File destination )
         throws IOException
@@ -955,7 +973,9 @@ public class FileUtils
      *
      * @param path the path to normalize
      * @return the normalized String, or <code>null</code> if too many ..'s.
+     * @deprecated use {@code org.apache.commons.io.FileNameUtils.normalize()}
      */
+    @Deprecated
     @Nonnull public static String normalize( @Nonnull final String path )
     {
         String normalized = path;
@@ -1083,11 +1103,13 @@ public class FileUtils
     }
 
     /**
-     * Delete a file. If file is directory delete it and all sub-directories.
+     * Delete a file. If file is directory, delete it and all sub-directories.
      *
      * @param file the file path
      * @throws IOException if any
+     * @deprecated use {@code org.apache.commons.io.FileUtils.deleteQuietly()}
      */
+    @Deprecated
     public static void forceDelete( @Nonnull final String file )
         throws IOException
     {
@@ -1095,11 +1117,13 @@ public class FileUtils
     }
 
     /**
-     * Delete a file. If file is directory delete it and all sub-directories.
+     * Delete a file. If file is directory, delete it and all sub-directories.
      *
      * @param file a file
      * @throws IOException if any
+     * @deprecated use {@code org.apache.commons.io.FileUtils.deleteQuietly()}
      */
+    @Deprecated
     public static void forceDelete( @Nonnull final File file )
         throws IOException
     {
@@ -1123,13 +1147,13 @@ public class FileUtils
     }
 
     /**
-     * deletes a file.
+     * Deletes a file.
      *
-     * @param file The file to delete
+     * @param file the file to delete
      * @throws IOException if the file cannot be deleted
+     * @deprecated use {@code java.nio.files.Files.delete(file.toPath())}
      */
-
-
+    @Deprecated
     public static void delete( @Nonnull File file )
         throws IOException
     {
@@ -1137,9 +1161,11 @@ public class FileUtils
     }
 
     /**
-     * @param file The file.
+     * @param file the file
      * @return true / false
+     * @deprecated use {@code java.nio.files.Files.delete(file.toPath())}
      */
+    @Deprecated
     public static boolean deleteLegacyStyle( @Nonnull File file )
     {
         try
@@ -1974,7 +2000,9 @@ public class FileUtils
      * @param file the file
      * @return a List containing every every line not starting with # and not empty
      * @throws IOException if any
+     * @deprecated assumes the platform default character set
      */
+    @Deprecated
     @Nonnull public static List<String> loadFile( @Nonnull File file )
         throws IOException
     {