You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/05/28 15:34:25 UTC

[commons-io] branch master updated (94be75e -> a41080e)

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

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git.


    from 94be75e  Small refactoring.
     new 480ab12  Simplify construction implementation.
     new a41080e  Updates for next release.

The 2 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.


Summary of changes:
 pom.xml                                            |  6 +-
 src/changes/changes.xml                            |  6 +-
 .../commons/io/filefilter/RegexFileFilter.java     | 70 +++++++++++++++-------
 3 files changed, 55 insertions(+), 27 deletions(-)

[commons-io] 01/02: Simplify construction implementation.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit 480ab122a8ff2634f366e25e387b7cd3b29afbcf
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 28 11:33:38 2021 -0400

    Simplify construction implementation.
---
 .../commons/io/filefilter/RegexFileFilter.java     | 70 +++++++++++++++-------
 1 file changed, 47 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java
index bfa75cf..401ff76 100644
--- a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java
+++ b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java
@@ -68,11 +68,40 @@ import org.apache.commons.io.IOCase;
 public class RegexFileFilter extends AbstractFileFilter implements Serializable {
 
     private static final long serialVersionUID = 4269646126155225062L;
+
+    /**
+     * Compiles the given pattern source.
+     *
+     * @param pattern the source pattern
+     * @param flags the compilation flags.
+     * @return a new Pattern.
+     */
+    private static Pattern compile(final String pattern, final int flags) {
+        if (pattern == null) {
+            throw new IllegalArgumentException("Pattern is missing");
+        }
+        return Pattern.compile(pattern, flags);
+    }
+
+    /**
+     * Converts IOCase to Pattern compilation flags.
+     *
+     * @param caseSensitivity case-sensitivity.
+     * @return Pattern compilation flags.
+     */
+    private static int toFlags(final IOCase caseSensitivity) {
+        int flags = 0;
+        if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) {
+            flags = Pattern.CASE_INSENSITIVE;
+        }
+        return flags;
+    }
+
     /** The regular expression pattern that will be used to match file names */
     private final Pattern pattern;
 
     /**
-     * Construct a new regular expression filter for a compiled regular expression
+     * Constructs a new regular expression filter for a compiled regular expression
      *
      * @param pattern regular expression to match
      * @throws IllegalArgumentException if the pattern is null
@@ -81,54 +110,39 @@ public class RegexFileFilter extends AbstractFileFilter implements Serializable
         if (pattern == null) {
             throw new IllegalArgumentException("Pattern is missing");
         }
-
         this.pattern = pattern;
     }
 
     /**
-     * Construct a new regular expression filter.
+     * Constructs a new regular expression filter.
      *
      * @param pattern regular string expression to match
      * @throws IllegalArgumentException if the pattern is null
      */
     public RegexFileFilter(final String pattern) {
-        if (pattern == null) {
-            throw new IllegalArgumentException("Pattern is missing");
-        }
-
-        this.pattern = Pattern.compile(pattern);
+        this(pattern, 0);
     }
 
     /**
-     * Construct a new regular expression filter with the specified flags.
+     * Constructs a new regular expression filter with the specified flags.
      *
      * @param pattern regular string expression to match
      * @param flags pattern flags - e.g. {@link Pattern#CASE_INSENSITIVE}
      * @throws IllegalArgumentException if the pattern is null
      */
     public RegexFileFilter(final String pattern, final int flags) {
-        if (pattern == null) {
-            throw new IllegalArgumentException("Pattern is missing");
-        }
-        this.pattern = Pattern.compile(pattern, flags);
+        this(compile(pattern, flags));
     }
 
     /**
-     * Construct a new regular expression filter with the specified flags case sensitivity.
+     * Constructs a new regular expression filter with the specified flags case sensitivity.
      *
      * @param pattern regular string expression to match
      * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
      * @throws IllegalArgumentException if the pattern is null
      */
     public RegexFileFilter(final String pattern, final IOCase caseSensitivity) {
-        if (pattern == null) {
-            throw new IllegalArgumentException("Pattern is missing");
-        }
-        int flags = 0;
-        if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) {
-            flags = Pattern.CASE_INSENSITIVE;
-        }
-        this.pattern = Pattern.compile(pattern, flags);
+        this(compile(pattern, toFlags(caseSensitivity)));
     }
 
     /**
@@ -152,7 +166,17 @@ public class RegexFileFilter extends AbstractFileFilter implements Serializable
      */
     @Override
     public FileVisitResult accept(final Path path, final BasicFileAttributes attributes) {
-        return toFileVisitResult(pattern.matcher(path.toString()).matches(), path);
+        return toFileVisitResult(pattern.matcher(path.getFileName().toString()).matches(), path);
+    }
+
+    /**
+     * Returns a debug string.
+     *
+     * @since 2.10.0
+     */
+    @Override
+    public String toString() {
+        return "RegexFileFilter [pattern=" + pattern + "]";
     }
 
 }

[commons-io] 02/02: Updates for next release.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit a41080e1284ecc2ebb967852c5cd13be5660be7b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 28 11:34:20 2021 -0400

    Updates for next release.
---
 pom.xml                 | 6 +++---
 src/changes/changes.xml | 6 +++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index c744b50..4d90171 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
-  <version>2.9.1-SNAPSHOT</version>
+  <version>2.10.0-SNAPSHOT</version>
   <name>Apache Commons IO</name>
 
   <inceptionYear>2002</inceptionYear>
@@ -52,7 +52,7 @@ file comparators, endian transformation classes, and much more.
     <connection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</connection>
     <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</developerConnection>
     <url>https://gitbox.apache.org/repos/asf?p=commons-io.git</url>
-    <tag>rel/commons-io-2.9.0</tag>
+    <tag>rel/commons-io-2.10.0</tag>
   </scm>
 
   <developers>
@@ -292,7 +292,7 @@ file comparators, endian transformation classes, and much more.
     <commons.module.name>org.apache.commons.io</commons.module.name>
     <commons.rc.version>RC1</commons.rc.version>
     <commons.bc.version>2.9.0</commons.bc.version>
-    <commons.release.version>2.9.1</commons.release.version>
+    <commons.release.version>2.10.0</commons.release.version>
     <commons.release.desc>(requires Java 8)</commons.release.desc>
     <commons.jira.id>IO</commons.jira.id>
     <commons.jira.pid>12310477</commons.jira.pid>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7b805e7..0f22caa 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,7 +46,11 @@ The <action> type attribute can be add,update,fix,remove.
 
   <body>
     <!-- The release date is the date RC is cut -->
-    <release version="2.9.1" date="2021-MM-DD" description="Java 8 required.">
+    <release version="2.10.0" date="2021-MM-DD" description="Java 8 required.">
+      <!-- ADD -->
+      <action dev="ggregory" type="add" due-to="Gary Gregory">
+        Add RegexFileFilter.toString().
+      </action>
     </release>
     <release version="2.9.0" date="2021-05-22" description="Java 8 required.">
       <!-- FIX -->