Skip to content

Commit

Permalink
isExcludedFile(..) to return false immediately when no patterns.
Browse files Browse the repository at this point in the history
- Work around potential issues with document URI conversation when
  non-ASCII characters used

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Aug 13, 2024
1 parent 0fc400f commit d9a899b
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
Expand Down Expand Up @@ -1855,14 +1856,24 @@ public static ICompilationUnit getWorkingCopy(IClassFile classFile, String conte
}

public static boolean isExcludedFile(List<String> patterns, String uriString) {
if (patterns.isEmpty()) {
return false;
}

URI uri = toURI(uriString);
if (uri == null) {
return false;
}

java.nio.file.Path path = Paths.get(uri);
FileSystem fileSystems = path.getFileSystem();
return !patterns.stream().filter(pattern -> fileSystems.getPathMatcher("glob:" + pattern).matches(path)).collect(Collectors.toList()).isEmpty();
// https://github.com/redhat-developer/vscode-java/issues/3735
java.nio.file.Path[] path = new java.nio.file.Path[1];
try {
path[0] = Paths.get(uri.toURL().getPath());
} catch (MalformedURLException e) {
path[0] = Paths.get(uri);
}
FileSystem fileSystems = path[0].getFileSystem();
return !patterns.stream().filter(pattern -> fileSystems.getPathMatcher("glob:" + pattern).matches(path[0])).collect(Collectors.toList()).isEmpty();
}

/**
Expand Down

0 comments on commit d9a899b

Please sign in to comment.