Search in sources :

Example 76 with PathMatcher

use of java.nio.file.PathMatcher in project sts4 by spring-projects.

the class BasicFileObserver method notify.

private static void notify(Map<String, ImmutablePair<List<PathMatcher>, Consumer<String>>> registry, String uri) {
    Path path = Paths.get(URI.create(uri));
    registry.values().stream().filter(pair -> pair.left.stream().filter(matcher -> matcher.matches(path)).findFirst().isPresent()).forEach(pair -> pair.right.accept(uri));
}
Also used : Path(java.nio.file.Path) Consumer(java.util.function.Consumer) List(java.util.List) Paths(java.nio.file.Paths) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URI(java.net.URI) UUID(java.util.UUID) Path(java.nio.file.Path) Collectors(java.util.stream.Collectors) FileSystems(java.nio.file.FileSystems) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 77 with PathMatcher

use of java.nio.file.PathMatcher in project sonar-java by SonarSource.

the class AbstractJavaClasspath method getMatchingLibraries.

private static Set<File> getMatchingLibraries(String pattern, Path dir) throws IOException {
    Set<File> matches = new LinkedHashSet<>();
    Set<File> dirs = getMatchingDirs(pattern, dir);
    PathMatcher matcher = FileSystems.getDefault().getPathMatcher(getGlob(dir, pattern));
    for (File d : dirs) {
        matches.addAll(getLibs(d.toPath()));
    }
    matches.addAll(dirs);
    matches.addAll(new LibraryFinder().find(dir, matcher));
    if (pattern.startsWith("**/")) {
        // match jar in the base dir when using wildcard
        matches.addAll(new LibraryFinder().find(dir, FileSystems.getDefault().getPathMatcher(getGlob(dir, pattern.substring(3)))));
    }
    return matches;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PathMatcher(java.nio.file.PathMatcher) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File)

Example 78 with PathMatcher

use of java.nio.file.PathMatcher in project moco by dreamhead.

the class Globs method doGlob.

private static ImmutableList<String> doGlob(final Path path, final Path searchPath) {
    final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + path);
    try {
        final ImmutableList.Builder<String> builder = ImmutableList.builder();
        Files.walkFileTree(searchPath, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
                if (matcher.matches(file)) {
                    builder.add(file.toString());
                }
                return FileVisitResult.CONTINUE;
            }
        });
        return builder.build();
    } catch (IOException e) {
        throw new MocoException(e);
    }
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) ImmutableList(com.google.common.collect.ImmutableList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) MocoException(com.github.dreamhead.moco.MocoException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 79 with PathMatcher

use of java.nio.file.PathMatcher in project moco by dreamhead.

the class MocoMount method include.

public static MountPredicate include(final String glob) {
    checkNotNullOrEmpty(glob, "Glob should not be null or empty");
    final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);
    return filename -> matcher.matches(Paths.get(filename));
}
Also used : Paths(java.nio.file.Paths) PathMatcher(java.nio.file.PathMatcher) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MountTo(com.github.dreamhead.moco.mount.MountTo) MountPredicate(com.github.dreamhead.moco.mount.MountPredicate) FileSystems(java.nio.file.FileSystems) Preconditions.checkNotNullOrEmpty(com.github.dreamhead.moco.util.Preconditions.checkNotNullOrEmpty) PathMatcher(java.nio.file.PathMatcher)

Example 80 with PathMatcher

use of java.nio.file.PathMatcher in project jadx by skylot.

the class TestInput method decompile.

private void decompile(String tmpDirName, String... inputSamples) throws URISyntaxException, IOException {
    List<String> args = new ArrayList<>();
    Path tempDir = FileUtils.createTempDir(tmpDirName);
    args.add("-v");
    args.add("-d");
    args.add(tempDir.toAbsolutePath().toString());
    for (String inputSample : inputSamples) {
        URL resource = getClass().getClassLoader().getResource(inputSample);
        assertThat(resource).isNotNull();
        String sampleFile = resource.toURI().getRawPath();
        args.add(sampleFile);
    }
    int result = JadxCLI.execute(args.toArray(new String[0]));
    assertThat(result).isEqualTo(0);
    List<Path> resultJavaFiles = collectJavaFilesInDir(tempDir);
    assertThat(resultJavaFiles).isNotEmpty();
    // do not copy input files as resources
    PathMatcher logAllFiles = path -> {
        LOG.debug("File in result dir: {}", path);
        return true;
    };
    for (Path path : collectFilesInDir(tempDir, logAllFiles)) {
        for (String inputSample : inputSamples) {
            assertThat(path.toAbsolutePath().toString()).doesNotContain(inputSample);
        }
    }
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) Files(java.nio.file.Files) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) LinkOption(java.nio.file.LinkOption) List(java.util.List) Stream(java.util.stream.Stream) PathMatcher(java.nio.file.PathMatcher) Path(java.nio.file.Path) FileUtils(jadx.core.utils.files.FileUtils) PathMatcher(java.nio.file.PathMatcher) ArrayList(java.util.ArrayList) URL(java.net.URL)

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