Search in sources :

Example 31 with PathMatcher

use of java.nio.file.PathMatcher in project JMRI by JMRI.

the class FileLineEndingsTest method getFiles.

/**
     * Get all files with the given prefixes in a directory and validate them.
     *
     * @param directory the directory containing the files
     * @param patterns  glob patterns of files to match
     * @return a collection of files to validate
     */
public static Collection<Object[]> getFiles(File directory, String[] patterns) {
    // setup logging early so this method can log
    Log4JFixture.setUp();
    ArrayList<Object[]> files = new ArrayList<>();
    try {
        for (String pattern : patterns) {
            PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
            // ignore the build directory if immediately under the passed in directory
            PathMatcher target = FileSystems.getDefault().getPathMatcher("glob:./target/**");
            Files.walk(directory.toPath()).filter(path -> !target.matches(path)).filter(matcher::matches).forEach((path) -> {
                if (path.toFile().isFile()) {
                    files.add(new Object[] { path.toFile() });
                }
            });
        }
    } catch (IOException ex) {
        log.error("Unable to get files in {}", directory, ex);
    }
    return files;
}
Also used : PathMatcher(java.nio.file.PathMatcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

PathMatcher (java.nio.file.PathMatcher)31 Path (java.nio.file.Path)15 File (java.io.File)9 HashSet (java.util.HashSet)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 Test (org.junit.Test)5 IOException (java.io.IOException)4 FileSystem (java.nio.file.FileSystem)4 ArrayList (java.util.ArrayList)4 EventService (org.eclipse.che.api.core.notification.EventService)4 FileVisitResult (java.nio.file.FileVisitResult)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 Set (java.util.Set)3 ProjectManager (org.eclipse.che.api.project.server.ProjectManager)3