You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2022/01/09 23:41:36 UTC

[maven-clean-plugin] 01/01: [MCLEAN-97] Require Java 8

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

slachiewicz pushed a commit to branch MCLEAN-97
in repository https://gitbox.apache.org/repos/asf/maven-clean-plugin.git

commit de77b5820bf7fda77844a4ffd12eecb58f7a0a48
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Mon Jan 10 00:40:37 2022 +0100

    [MCLEAN-97] Require Java 8
---
 pom.xml                                            |  2 +-
 .../org/apache/maven/plugins/clean/Cleaner.java    | 28 ++++------------------
 .../apache/maven/plugins/clean/CleanMojoTest.java  | 21 ++++++++--------
 .../java/org/apache/maven/plugins/clean/Utils.java | 15 +-----------
 4 files changed, 18 insertions(+), 48 deletions(-)

diff --git a/pom.xml b/pom.xml
index f5714de..cebba16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@ under the License.
 
   <properties>
     <mavenVersion>3.2.5</mavenVersion>
-    <javaVersion>7</javaVersion>
+    <javaVersion>8</javaVersion>
     <surefire.version>2.22.2</surefire.version>
     <mavenPluginToolsVersion>3.6.2</mavenPluginToolsVersion>
     <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
diff --git a/src/main/java/org/apache/maven/plugins/clean/Cleaner.java b/src/main/java/org/apache/maven/plugins/clean/Cleaner.java
index a15a221..33dbd49 100644
--- a/src/main/java/org/apache/maven/plugins/clean/Cleaner.java
+++ b/src/main/java/org/apache/maven/plugins/clean/Cleaner.java
@@ -21,10 +21,10 @@ package org.apache.maven.plugins.clean;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.shared.utils.Os;
-import org.apache.maven.shared.utils.io.FileUtils;
 
 /**
  * Cleans directories.
@@ -52,29 +52,11 @@ class Cleaner
      */
     Cleaner( final Log log, boolean verbose )
     {
-        logDebug = ( log == null || !log.isDebugEnabled() ) ? null : new Logger()
-        {
-            public void log( CharSequence message )
-            {
-                log.debug( message );
-            }
-        };
+        logDebug = ( log == null || !log.isDebugEnabled() ) ? null : log::debug;
 
-        logInfo = ( log == null || !log.isInfoEnabled() ) ? null : new Logger()
-        {
-            public void log( CharSequence message )
-            {
-                log.info( message );
-            }
-        };
+        logInfo = ( log == null || !log.isInfoEnabled() ) ? null : log::info;
 
-        logWarn = ( log == null || !log.isWarnEnabled() ) ? null : new Logger()
-        {
-            public void log( CharSequence message )
-            {
-                log.warn( message );
-            }
-        };
+        logWarn = ( log == null || !log.isWarnEnabled() ) ? null : log::warn;
 
         logVerbose = verbose ? logInfo : logDebug;
     }
@@ -145,7 +127,7 @@ class Cleaner
         {
             if ( selector == null || selector.couldHoldSelected( pathname ) )
             {
-                final boolean isSymlink = FileUtils.isSymbolicLink( file );
+                final boolean isSymlink = Files.isSymbolicLink( file.toPath() );
                 File canonical = followSymlinks ? file : file.getCanonicalFile();
                 if ( followSymlinks || !isSymlink )
                 {
diff --git a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java
index 9bf3b63..84b638f 100644
--- a/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/clean/CleanMojoTest.java
@@ -21,13 +21,14 @@ package org.apache.maven.plugins.clean;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.shared.utils.io.FileUtils;
 
 import java.io.File;
 import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 
+import static org.apache.commons.io.FileUtils.copyDirectory;
+
 /**
  * Test the clean mojo.
  *
@@ -47,7 +48,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/basic-clean-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/basic-clean-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/basic-clean-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/basic-clean-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -74,7 +75,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/nested-clean-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/nested-clean-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/nested-clean-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/nested-clean-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -99,7 +100,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/empty-clean-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/empty-clean-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/empty-clean-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/empty-clean-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupEmptyMojo( "clean", pluginPom );
@@ -127,7 +128,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/fileset-clean-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/fileset-clean-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/fileset-clean-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/fileset-clean-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -163,7 +164,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/invalid-directory-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/invalid-directory-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/invalid-directory-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/invalid-directory-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -192,7 +193,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/missing-directory-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/missing-directory-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/missing-directory-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/missing-directory-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -223,7 +224,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/locked-file-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/locked-file-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -262,7 +263,7 @@ public class CleanMojoTest
         String pluginPom = getBasedir() + "/src/test/resources/unit/locked-file-test/plugin-pom.xml";
 
         // safety
-        FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
+        copyDirectory( new File( getBasedir(), "src/test/resources/unit/locked-file-test" ),
                                  new File( getBasedir(), "target/test-classes/unit/locked-file-test" ) );
 
         CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
@@ -288,7 +289,7 @@ public class CleanMojoTest
      */
     private boolean checkExists( String dir )
     {
-        return FileUtils.fileExists( new File( dir ).getAbsolutePath() );
+        return new File( new File( dir ).getAbsolutePath() ).exists();
     }
 
     /**
diff --git a/src/test/java/org/apache/maven/plugins/clean/Utils.java b/src/test/java/org/apache/maven/plugins/clean/Utils.java
index c36fecf..c6f1342 100644
--- a/src/test/java/org/apache/maven/plugins/clean/Utils.java
+++ b/src/test/java/org/apache/maven/plugins/clean/Utils.java
@@ -23,7 +23,6 @@ import java.io.File;
 
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.StreamConsumer;
 
 /**
  * Testing helpers for the IT scripts.
@@ -49,19 +48,7 @@ public class Utils
             cli.createArg().setValue( "-s" );
             cli.createArg().setFile( target );
             cli.createArg().setFile( link );
-            int code = CommandLineUtils.executeCommandLine( cli, new StreamConsumer()
-            {
-                public void consumeLine( String line )
-                {
-                    System.out.println( line );
-                }
-            }, new StreamConsumer()
-            {
-                public void consumeLine( String line )
-                {
-                    System.err.println( line );
-                }
-            } );
+            int code = CommandLineUtils.executeCommandLine( cli, System.out::println, System.err::println );
             return 0 == code;
         }
         catch ( Exception e )