All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jasmine.SpecScanner Maven / Gradle / Ivy

The newest version!
package org.jasmine;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

public class SpecScanner {
    private final FileSystem fileSystem = FileSystems.getDefault();

    public Iterable findSpecs(String pattern){
        if(!pattern.startsWith("./")){
            pattern = "./" + pattern;
        }
        final PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + pattern);

        final List paths = newArrayList();
        try{
            Files.walkFileTree(fileSystem.getPath("."), new SimpleFileVisitor() {
                @Override
                public FileVisitResult visitFile(final Path file, BasicFileAttributes attrs) throws IOException {
                    if (pathMatcher.matches(file)) {
                        paths.add(file.toString());
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return paths;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy