Search in sources :

Example 66 with PathMatcher

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]"));
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 67 with PathMatcher

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;
}
Also used : PathMatcher(java.nio.file.PathMatcher) FileVisitOption(java.nio.file.FileVisitOption) IOException(java.io.IOException) File(java.io.File)

Example 68 with PathMatcher

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;
        }
    });
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 69 with PathMatcher

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);
    }
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem)

Example 70 with PathMatcher

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;
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5