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 261248767b [Backport maven-4.0.x] #14125: Keep a directory exclude in
PathSelector (#14153)
261248767b is described below
commit 261248767b90ced34d3525cdaa6ebed3dc5a62be
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 27 11:47:18 2026 +0100
[Backport maven-4.0.x] #14125: Keep a directory exclude in PathSelector
(#14153)
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.
Cherry-picked from fd1c8922bea3b5267b00c54fefef649aa7e446fd.
Co-authored-by: Sharang Gupta <[email protected]>
---
.../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 e1ad7e8660..1905a84ac0 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.
*