private ImmutableSortedSet<Path> getRecordedOutputDirsAndFiles() throws IOException { final ImmutableSortedSet.Builder<Path> paths = ImmutableSortedSet.naturalOrder(); // Add files from output directories. for (final Path output : pathsToOutputs) { projectFilesystem.walkRelativeFileTree( output, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { paths.add(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { paths.add(dir); return FileVisitResult.CONTINUE; } }); } return paths.build(); }
public ImmutableSet<Path> getFilesUnderPath( Path pathRelativeToProjectRoot, final Predicate<Path> predicate, EnumSet<FileVisitOption> visitOptions) throws IOException { final ImmutableSet.Builder<Path> paths = ImmutableSet.builder(); walkRelativeFileTree( pathRelativeToProjectRoot, visitOptions, wrapWithIgnoringFileVisitor( new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) { if (predicate.apply(path)) { paths.add(path); } return FileVisitResult.CONTINUE; } })); return paths.build(); }
public ImmutableSet<IjFolder> createExcludes(IjModule module) throws IOException { final ImmutableSet.Builder<IjFolder> excludesBuilder = ImmutableSet.builder(); final Path moduleBasePath = module.getModuleBasePath(); projectFilesystem.walkRelativeFileTree( moduleBasePath, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { // This is another module that's nested in this one. The entire subtree will be handled // When we create excludes for that module. if (filesystemTraversalBoundaryPaths.contains(dir) && !moduleBasePath.equals(dir)) { return FileVisitResult.SKIP_SUBTREE; } if (!referencedFolderPaths.contains(dir)) { excludesBuilder.add(new ExcludeFolder(dir)); return FileVisitResult.SKIP_SUBTREE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); return excludesBuilder.build(); }
@Override public Set<Path> findDrawables(Collection<Path> dirs, ProjectFilesystem filesystem) throws IOException { final ImmutableSet.Builder<Path> drawableBuilder = ImmutableSet.builder(); for (Path dir : dirs) { filesystem.walkRelativeFileTree( dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) { String unixPath = MorePaths.pathWithUnixSeparators(path); if (DRAWABLE_PATH_PATTERN.matcher(unixPath).matches() && !DRAWABLE_EXCLUDE_PATTERN.matcher(unixPath).matches()) { // The path is normalized so that the value can be matched against patterns. drawableBuilder.add(path); } return FileVisitResult.CONTINUE; } }); } return drawableBuilder.build(); }
/** * Similar to {@link #walkFileTree(Path, FileVisitor)} except this takes in a path relative to the * project root. */ public void walkRelativeFileTree( Path pathRelativeToProjectRoot, final FileVisitor<Path> fileVisitor) throws IOException { walkRelativeFileTree( pathRelativeToProjectRoot, EnumSet.of(FileVisitOption.FOLLOW_LINKS), fileVisitor); }