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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new fd1c8922be Keep a directory exclude in PathSelector (#14125)
fd1c8922be is described below

commit fd1c8922bea3b5267b00c54fefef649aa7e446fd
Author: Sharang Gupta <[email protected]>
AuthorDate: Fri Nov 27 09:03:29 2026 +0000

    Keep a directory exclude in PathSelector (#14125)
    
    PathSelector drops the excludes that cannot match any include, but it
    compared a directory exclude such as docs/, which means docs/**, as
    written, so it was dropped for includes like **/*.md and the files of
    that directory were selected.
---
 .../main/java/org/apache/maven/impl/PathSelector.java    |  3 +++
 .../java/org/apache/maven/impl/PathSelectorTest.java     | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
index aefa56cb5b..853b4b1a20 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
@@ -320,6 +320,9 @@ private static Collection<String> effectiveExcludes(
             if (s <= MAVEN_SYNTAX_THRESHOLD || 
exclude.startsWith(DEFAULT_SYNTAX)) {
                 if (s > MAVEN_SYNTAX_THRESHOLD) {
                     exclude = exclude.substring(DEFAULT_SYNTAX.length());
+                } else if (exclude.endsWith("/") || 
exclude.endsWith(File.separator)) {
+                    // As for the includes, a directory stands for everything 
below it.
+                    exclude += "**";
                 }
                 if (cannotMatch(exclude, prefixes, false) || 
cannotMatch(exclude, suffixes, true)) {
                     it.remove();
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
index e3edd9d7a9..42ba8c33ed 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
@@ -117,6 +117,22 @@ private static void assertFilteredFilesContains(final Path 
directory, final Stri
         assertTrue(filtered.isEmpty(), filtered.toString());
     }
 
+    /**
+     * Tests that an exclude given as a directory with a trailing slash is not 
omitted as unnecessary.
+     *
+     * @param directory temporary directory where to create a tree
+     * @throws IOException if an error occurred while creating a temporary 
file or directory
+     */
+    @Test
+    public void testExcludeDirectoryWithTrailingSlash(final @TempDir Path 
directory) throws IOException {
+        Path docs = Files.createDirectory(directory.resolve("docs"));
+        Files.createFile(directory.resolve("README.md"));
+        Files.createFile(docs.resolve("guide.md"));
+        PathMatcher matcher = PathSelector.of(directory, List.of("**/*.md"), 
List.of("docs/"), false);
+        assertTrue(matcher.matches(directory.resolve("README.md")));
+        assertFalse(matcher.matches(docs.resolve("guide.md")));
+    }
+
     /**
      * Tests the omission of unnecessary excludes.
      *

Reply via email to