use of java.nio.file.PathMatcher in project cryptofs by cryptomator.
the class PathMatcherFactoryTest method testSyntaxAndPatternStartingWithRegexCreatesPatternPathMatcherWithCorrectPattern.
@Test
@SuppressWarnings("deprecation")
public void testSyntaxAndPatternStartingWithRegexCreatesPatternPathMatcherWithCorrectPattern() {
PathMatcher pathMatcher = inTest.pathMatcherFrom("regex:test[02]");
assertThat(pathMatcher, is(instanceOf(PatternPathMatcher.class)));
assertThat(((PatternPathMatcher) pathMatcher).getPattern().pattern(), is("test[02]"));
}
use of java.nio.file.PathMatcher in project java-mapollage by trixon.
the class Operation method generateFileList.
private boolean generateFileList() throws IOException {
mListener.onOperationLog("");
mListener.onOperationLog(Dict.GENERATING_FILELIST.toString());
PathMatcher pathMatcher = mProfileSource.getPathMatcher();
EnumSet<FileVisitOption> fileVisitOptions;
if (mProfileSource.isFollowLinks()) {
fileVisitOptions = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
} else {
fileVisitOptions = EnumSet.noneOf(FileVisitOption.class);
}
File file = mProfileSource.getDir();
if (file.isDirectory()) {
FileVisitor fileVisitor = new FileVisitor(pathMatcher, mFiles, file, this);
try {
if (mProfileSource.isRecursive()) {
Files.walkFileTree(file.toPath(), fileVisitOptions, Integer.MAX_VALUE, fileVisitor);
} else {
Files.walkFileTree(file.toPath(), fileVisitOptions, 1, fileVisitor);
}
if (fileVisitor.isInterrupted()) {
return false;
}
} catch (IOException ex) {
throw new IOException(String.format("E000 %s", file.getAbsolutePath()));
}
} else if (file.isFile() && pathMatcher.matches(file.toPath().getFileName())) {
mFiles.add(file);
}
if (mFiles.isEmpty()) {
mListener.onOperationFinished(Dict.FILELIST_EMPTY.toString(), 0);
} else {
Collections.sort(mFiles);
}
return true;
}
use of java.nio.file.PathMatcher in project closure-compiler by google.
the class CommandLineRunner method matchPaths.
private static void matchPaths(String pattern, final Map<String, String> allJsInputs, final Set<String> excludes) throws IOException {
FileSystem fs = FileSystems.getDefault();
final boolean remove = pattern.indexOf('!') == 0;
if (remove) {
pattern = pattern.substring(1);
}
String separator = File.separator.equals("\\") ? "\\\\" : File.separator;
// Split the pattern into two pieces: the globbing part
// and the non-globbing prefix.
List<String> patternParts = Splitter.on(File.separator).splitToList(pattern);
String prefix = ".";
for (int i = 0; i < patternParts.size(); i++) {
if (patternParts.get(i).contains("*")) {
if (i > 0) {
prefix = Joiner.on(separator).join(patternParts.subList(0, i));
pattern = Joiner.on(separator).join(patternParts.subList(i, patternParts.size()));
}
break;
}
}
final PathMatcher matcher = fs.getPathMatcher("glob:" + prefix + separator + pattern);
java.nio.file.Files.walkFileTree(fs.getPath(prefix), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path p, BasicFileAttributes attrs) {
if (matcher.matches(p) || matcher.matches(p.normalize())) {
String pathStringAbsolute = p.normalize().toAbsolutePath().toString();
if (remove) {
excludes.add(pathStringAbsolute);
allJsInputs.remove(pathStringAbsolute);
} else if (!excludes.contains(pathStringAbsolute)) {
allJsInputs.put(pathStringAbsolute, p.toString());
}
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException e) {
return FileVisitResult.SKIP_SUBTREE;
}
});
}
use of java.nio.file.PathMatcher in project open-kilda by telstra.
the class RouteAction method handleMessage.
private void handleMessage(CtrlRequest payload) throws JsonProcessingException {
RouteMessage message = new RouteMessage(payload.getData(), payload.getCorrelationId(), topologyName);
List<Object> packedMessage = message.pack();
String glob = payload.getRoute();
if (Strings.isNullOrEmpty(glob)) {
glob = "**";
} else if (glob.equals("*")) {
glob = "**";
}
FileSystem fs = FileSystems.getDefault();
PathMatcher matcher = fs.getPathMatcher("glob:" + glob);
for (String bolt : endpoints.keySet()) {
Path route = fs.getPath(topologyName, bolt);
if (!matcher.matches(route)) {
continue;
}
getOutputCollector().emit(endpoints.get(bolt), getTuple(), packedMessage);
}
}
use of java.nio.file.PathMatcher in project graphql-java by graphql-java.
the class DataFetchingFieldSelectionSetImpl method contains.
@Override
public boolean contains(String fieldGlobPattern) {
if (fieldGlobPattern == null || fieldGlobPattern.isEmpty()) {
return false;
}
computeValuesLazily();
PathMatcher globMatcher = FileSystems.getDefault().getPathMatcher("glob:" + fieldGlobPattern);
for (String flattenedField : flattenedFields) {
Path path = Paths.get(flattenedField);
if (globMatcher.matches(path)) {
return true;
}
}
return false;
}
Aggregations