Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,6 @@ private final class DirectoryPrefiltering implements PathMatcher {
*/
private final PathMatcher[] dirExcludes;

/**
* Whether to ignore the includes defined by the enclosing class.
* This flag can be {@code false} if we determined that all includes are applicable to directories.
* This flag should be {@code true} in case of doubt since directory filtering is only an optimization.
*/
private final boolean ignoreIncludes;

/**
* Creates a new matcher for directories.
*/
Expand All @@ -558,17 +551,9 @@ private final class DirectoryPrefiltering implements PathMatcher {
if (excludeDirPatterns.contains(DEFAULT_SYNTAX)) {
// A pattern was something like "glob:{/**,}", which exclude everything.
dirExcludes = new PathMatcher[] {INCLUDES_ALL};
ignoreIncludes = true;
return;
}
dirExcludes = matchers(baseDirectory.getFileSystem(), excludeDirPatterns.toArray(String[]::new));
for (String pattern : includePatterns) {
if (trimSuffixes(pattern) == pattern) { // Identity comparison is sufficient here.
ignoreIncludes = true;
return;
}
} else {
dirExcludes = matchers(baseDirectory.getFileSystem(), excludeDirPatterns.toArray(String[]::new));
}
ignoreIncludes = (includes.length == 0);
}

/**
Expand All @@ -593,12 +578,7 @@ private static String trimSuffixes(String pattern) {
*/
PathMatcher simplify() {
if (dirExcludes.length == 0) {
if (ignoreIncludes) {
return INCLUDES_ALL;
}
if (includes.length == 1) {
return includes[0];
}
return INCLUDES_ALL;
}
return this;
}
Expand All @@ -619,7 +599,7 @@ public boolean matches(Path directory) {
if (isMatched(directory, dirExcludes)) {
return false;
}
return ignoreIncludes || isMatched(directory, includes);
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,16 @@ public void testWildcardMatchesAlsoZeroDirectory() {
assertTrue(anyMatcher.matches(dir.resolve(Path.of("org", "foo", "more"))));
assertTrue(dirMatcher.matches(dir.resolve(Path.of("org", "0foo0", "more"))));
assertTrue(anyMatcher.matches(dir.resolve(Path.of("org", "0foo0", "more"))));
assertFalse(dirMatcher.matches(dir.resolve(Path.of("org", "bar", "more"))));

// Before matching an "org/foo" directory, a `FileVisitor` will need to traverse the "org" directory first.
assertTrue(dirMatcher.matches(dir.resolve(Path.of("org"))));

// Ideally, `dirMatcher` would return false. But it is hard to implement without false negative on "org".
assertTrue(dirMatcher.matches(dir.resolve(Path.of("org", "bar", "more"))));
assertFalse(anyMatcher.matches(dir.resolve(Path.of("org", "bar", "more"))));
assertFalse(dirMatcher.matches(dir.resolve(Path.of("bar"))));

// Same reason as above.
assertTrue(dirMatcher.matches(dir.resolve(Path.of("bar"))));
assertFalse(anyMatcher.matches(dir.resolve(Path.of("bar"))));
}
}
Loading