From 4a6b1f7fbe2fd3442534d44f380890333f48cc48 Mon Sep 17 00:00:00 2001
From: Elliotte Rusty Harold
Date: Fri, 29 May 2020 16:00:43 -0400
Subject: [PATCH 1/2] -a
deprecate much DirectoryScanner code in favor of java.nio.file.DirectoryStream and related classes available in Java 7 and later
---
.../maven/shared/utils/io/DirectoryScanResult.java | 3 +++
.../maven/shared/utils/io/DirectoryScanner.java | 8 +++++---
.../shared/utils/io/DirectoryWalkListener.java | 13 +++++++------
.../apache/maven/shared/utils/io/MatchPattern.java | 4 +++-
.../apache/maven/shared/utils/io/MatchPatterns.java | 2 ++
.../apache/maven/shared/utils/io/ScanConductor.java | 3 +++
.../apache/maven/shared/utils/io/SelectorUtils.java | 2 ++
.../apache/maven/shared/utils/io/WalkCollector.java | 5 +++--
8 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanResult.java b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanResult.java
index 42232f3d..ae5de32b 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanResult.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanResult.java
@@ -23,7 +23,10 @@
/**
* Scan for files in a directory at a given time and reports removed and added files
* between captures.
+ *
+ * @deprecated use {@code java.nio.file.DirectoryStream} and related classes
*/
+@Deprecated
public class DirectoryScanResult
{
private final String[] filesAdded;
diff --git a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java
index c22cfe33..5d03525e 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java
@@ -108,7 +108,9 @@
* @author Magesh Umasankar
* @author Bruce Atherton
* @author Antoine Levy-Lambert
+ * @deprecated use {@code java.nio.file.DirectoryStream} and related classes
*/
+@Deprecated
public class DirectoryScanner
{
/**
@@ -452,9 +454,9 @@ public DirectoryScanResult diffIncludedFiles( String... oldFiles )
}
/**
- * @param oldFiles array of old files.
- * @param newFiles array of new files.
- * @return calculated differerence.
+ * @param oldFiles array of old files
+ * @param newFiles array of new files
+ * @return calculated difference
*/
public static DirectoryScanResult diffFiles( @Nullable String[] oldFiles, @Nullable String[] newFiles )
{
diff --git a/src/main/java/org/apache/maven/shared/utils/io/DirectoryWalkListener.java b/src/main/java/org/apache/maven/shared/utils/io/DirectoryWalkListener.java
index 292298cd..bb142b5d 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/DirectoryWalkListener.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/DirectoryWalkListener.java
@@ -22,16 +22,17 @@
import java.io.File;
/**
- * DirectoryWalkListener
- *
- *
+ * DirectoryWalkListener.
+ *
+ * @deprecated use {@code java.nio.file.FileVisitor} and related classes
*/
+@Deprecated
public interface DirectoryWalkListener
{
/**
* The directory walking has begun.
*
- * @param basedir the basedir that walk started in.
+ * @param basedir the basedir that walk started in
*/
void directoryWalkStarting( File basedir );
@@ -39,7 +40,7 @@ public interface DirectoryWalkListener
* The included entry that was encountered.
*
* @param percentage rough percentage of the walk completed. (inaccurate)
- * @param file the file that was included.
+ * @param file the file that was included
*/
void directoryWalkStep( int percentage, File file );
@@ -49,7 +50,7 @@ public interface DirectoryWalkListener
void directoryWalkFinished();
/**
- * @param message The message for the debugging output.
+ * @param message the message for the debugging output
*/
void debug( String message );
}
diff --git a/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java b/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java
index 15ad1488..8abff427 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java
@@ -33,7 +33,9 @@
* Significantly more efficient than using strings, since re-evaluation and re-tokenizing is avoided.
*
* @author Kristian Rosenvold
+ * @deprecated use {@code java.nio.filejava.nio.file.DirectoryStream.Filter} and related classes
*/
+@Deprecated
public class MatchPattern
{
private final String source;
@@ -98,7 +100,7 @@ public boolean matchPatternStart( @Nonnull String str, boolean isCaseSensitive )
{
if ( regexPattern != null )
{
- // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgement until we have
+ // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgment until we have
// a file to deal with, or we can definitely say this is an exclusion...
return true;
}
diff --git a/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java b/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java
index 8e59f48f..693acb1c 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java
@@ -27,7 +27,9 @@
* A list of patterns to be matched
*
* @author Kristian Rosenvold
+ * @deprecated use {@code java.nio.filejava.nio.file.DirectoryStream.Filter} and related classes
*/
+@Deprecated
public class MatchPatterns
{
private final MatchPattern[] patterns;
diff --git a/src/main/java/org/apache/maven/shared/utils/io/ScanConductor.java b/src/main/java/org/apache/maven/shared/utils/io/ScanConductor.java
index bd19067b..08d7a1cd 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/ScanConductor.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/ScanConductor.java
@@ -33,7 +33,10 @@
* cleaned between two scan() invocations.
*
* @author Mark Struberg
+ *
+ * @deprecated use {@code java.nio.file.Files.walkFileTree()} and related classes
*/
+@Deprecated
public interface ScanConductor
{
/**
diff --git a/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java b/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java
index 396ef6a3..b716e7c8 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java
@@ -39,7 +39,9 @@
* @author Magesh Umasankar
* @author Bruce Atherton
*
+ * @deprecated use {@code java.nio.file.Files.walkFileTree()} and related classes
*/
+@Deprecated
public final class SelectorUtils
{
diff --git a/src/main/java/org/apache/maven/shared/utils/io/WalkCollector.java b/src/main/java/org/apache/maven/shared/utils/io/WalkCollector.java
index 5d48d4ac..3db835ae 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/WalkCollector.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/WalkCollector.java
@@ -23,9 +23,10 @@
import java.util.ArrayList;
import java.util.List;
-/**
- *
+/**
+ * @deprecated use {@code java.nio.file.FileVisitor} and related classes
*/
+@Deprecated
public class WalkCollector
implements DirectoryWalkListener
{
From 8a83d0d1ca8eb7e7123b10fc4f961a76c95b5a4c Mon Sep 17 00:00:00 2001
From: Elliotte Rusty Harold
Date: Fri, 29 May 2020 16:04:18 -0400
Subject: [PATCH 2/2] suppress deprecation warnings in test file
---
.../maven/shared/utils/io/DirectoryScannerTest.java | 4 ++--
.../shared/utils/testhelpers/FileTestHelper.java | 11 +----------
2 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
index 421f635a..01110069 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
@@ -37,6 +37,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
+@SuppressWarnings( "deprecation" )
public class DirectoryScannerTest
{
private static final String[] NONE = new String[0];
@@ -214,7 +215,6 @@ public void followSymlinks()
/*
Creates a standard directory layout with symlinks and files.
*/
-
@Test
public void testSimpleExcludes()
throws Exception
@@ -243,7 +243,7 @@ public void testSimpleExcludes()
/* expExclDirs */ NONE );
}
- public void testIsSymLin()
+ public void testIsSymbolicLink()
throws IOException
{
File file = new File( "." );
diff --git a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
index f4c6b02e..81d4fad6 100644
--- a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
+++ b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
@@ -20,7 +20,6 @@
*/
import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
import org.junit.rules.TemporaryFolder;
import java.io.*;
@@ -71,20 +70,12 @@ public static void createLineBasedFile( File file, String[] data )
throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
}
- PrintWriter out = null;
- try
+ try ( PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) ) )
{
- out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) );
for ( String aData : data )
{
out.println( aData );
}
- out.close();
- out = null;
- }
- finally
- {
- IOUtil.close( out );
}
}