Search in sources :

Example 11 with PathOrGlobMatcher

use of com.facebook.buck.io.PathOrGlobMatcher in project buck by facebook.

the class FilesystemBackedBuildFileTree method getChildPaths.

/**
   * @return paths relative to BuildTarget that contain their own build files.
   */
@Override
public Collection<Path> getChildPaths(BuildTarget target) {
    // Crawl the subdirectories of target's base path, looking for build files.
    // When we find one, we can stop crawling anything under the directory it's in.
    final ImmutableSet.Builder<Path> childPaths = ImmutableSet.builder();
    final Path basePath = target.getBasePath();
    final ImmutableSet<PathOrGlobMatcher> ignoredPaths = projectFilesystem.getIgnorePaths();
    try {
        projectFilesystem.walkRelativeFileTree(basePath, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                for (PathOrGlobMatcher ignoredPath : ignoredPaths) {
                    if (ignoredPath.matches(dir)) {
                        return FileVisitResult.SKIP_SUBTREE;
                    }
                }
                if (dir.equals(basePath)) {
                    return FileVisitResult.CONTINUE;
                }
                Path buildFile = dir.resolve(buildFileName);
                if (pathExistenceCache.getUnchecked(buildFile)) {
                    childPaths.add(basePath.relativize(dir));
                    return FileVisitResult.SKIP_SUBTREE;
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return childPaths.build();
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

PathOrGlobMatcher (com.facebook.buck.io.PathOrGlobMatcher)11 Path (java.nio.file.Path)7 Test (org.junit.Test)6 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 WatchmanQuery (com.facebook.buck.io.WatchmanQuery)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 NdkLibrary (com.facebook.buck.android.NdkLibrary)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 Logger (com.facebook.buck.log.Logger)2 BuildId (com.facebook.buck.model.BuildId)2 FakeClock (com.facebook.buck.timing.FakeClock)2 Ansi (com.facebook.buck.util.Ansi)2 Console (com.facebook.buck.util.Console)2 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)2 Verbosity (com.facebook.buck.util.Verbosity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Joiner (com.google.common.base.Joiner)2 Preconditions (com.google.common.base.Preconditions)2