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

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


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new 0f7150bc8c [Backport maven-4.0.x] #13993: Honor explicit glob 
exclusions in PathSelector (#14037)
0f7150bc8c is described below

commit 0f7150bc8c4f60e3670bb0f47981e0ad5357c16c
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Nov 17 21:08:24 2026 +0100

    [Backport maven-4.0.x] #13993: Honor explicit glob exclusions in 
PathSelector (#14037)
    
    `PathSelector` can discard an explicit `glob:` exclusion while reducing the 
exclusion list.
    Strip the syntax prefix from the temporary comparison string while 
retaining the original
    pattern for the filesystem matcher.
    
    Add regression coverage for explicit and implicit include syntax, literal 
and wildcard
    exclusions, and default exclusions enabled/disabled (12 parameterized cases 
+ 2 unit tests).
    
    Cherry-picked from b30592d72ca0a91d678d5b932209d583afd5a5e7
    
    Co-authored-by: Amar Ghugare <[email protected]>
---
 .../java/org/apache/maven/impl/PathSelector.java   |  5 ++-
 .../org/apache/maven/impl/PathSelectorTest.java    | 45 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

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 736e908b3b..aefa56cb5b 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
@@ -315,9 +315,12 @@ private static Collection<String> effectiveExcludes(
         final Iterator<String> it = excludes.iterator();
         nextExclude:
         while (it.hasNext()) {
-            final String exclude = it.next();
+            String exclude = it.next();
             final int s = exclude.indexOf(':');
             if (s <= MAVEN_SYNTAX_THRESHOLD || 
exclude.startsWith(DEFAULT_SYNTAX)) {
+                if (s > MAVEN_SYNTAX_THRESHOLD) {
+                    exclude = exclude.substring(DEFAULT_SYNTAX.length());
+                }
                 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 9e0f2e5078..e1ad7e8660 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
@@ -25,14 +25,59 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class PathSelectorTest {
+    @ParameterizedTest
+    @CsvSource({
+        "foo/*.java, glob:foo/Excluded.java, false",
+        "glob:foo/*.java, glob:foo/Excluded.java, false",
+        "foo/*.java, glob:foo/Excluded*.java, false",
+        "glob:foo/*.java, glob:foo/Excluded*.java, false",
+        "foo/*.java, glob:foo/Excluded.java, true",
+        "glob:foo/*.java, glob:foo/Excluded.java, true",
+        "foo/*.java, glob:foo/Excluded*.java, true",
+        "glob:foo/*.java, glob:foo/Excluded*.java, true",
+        "foo/*.java, foo/Excluded.java, false",
+        "glob:foo/*.java, foo/Excluded.java, false",
+        "foo/*.java, foo/Excluded.java, true",
+        "glob:foo/*.java, foo/Excluded.java, true"
+    })
+    public void testGlobExcludes(String include, String exclude, boolean 
useDefaultExcludes) {
+        Path directory = Path.of("dummy");
+        PathMatcher matcher = PathSelector.of(directory, List.of(include), 
List.of(exclude), useDefaultExcludes);
+        assertFalse(matcher.matches(directory.resolve("foo/Excluded.java")));
+        assertTrue(matcher.matches(directory.resolve("foo/Included.java")));
+        assertFalse(matcher.matches(directory.resolve("foo/Included.txt")));
+        assertFalse(matcher.matches(directory.resolve("bar/Included.java")));
+    }
+
+    @Test
+    public void testExplicitGlobExcludeOmission() {
+        PathMatcher matcher = PathSelector.of(
+                Path.of("dummy"), List.of("foo/*.java"), 
List.of("glob:bar/*.java", "glob:foo/*.txt"), false);
+        assertFalse(matcher.toString().contains("glob:bar/*.java"));
+        assertFalse(matcher.toString().contains("glob:foo/*.txt"));
+    }
+
+    @Test
+    public void testRegexExcludes() {
+        Path directory = Path.of("dummy");
+        String exclude =
+                "regex:" + Pattern.quote(Path.of("foo", 
"Excluded.java").toString());
+        PathMatcher matcher = PathSelector.of(directory, 
List.of("foo/*.java"), List.of(exclude), false);
+        assertFalse(matcher.matches(directory.resolve("foo/Excluded.java")));
+        assertTrue(matcher.matches(directory.resolve("foo/Included.java")));
+    }
+
     /**
      * Creates a temporary directory and checks its list of content based on 
patterns.
      *

Reply via email to