use of java.nio.file.FileVisitResult in project buck by facebook.
the class NdkLibraryDescription method findSources.
@VisibleForTesting
protected ImmutableSortedSet<SourcePath> findSources(final ProjectFilesystem filesystem, final Path buildRulePath) {
final ImmutableSortedSet.Builder<SourcePath> srcs = ImmutableSortedSet.naturalOrder();
try {
final Path rootDirectory = filesystem.resolve(buildRulePath);
Files.walkFileTree(rootDirectory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), /* maxDepth */
Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (EXTENSIONS_REGEX.matcher(file.toString()).matches()) {
srcs.add(new PathSourcePath(filesystem, buildRulePath.resolve(rootDirectory.relativize(file))));
}
return super.visitFile(file, attrs);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
return srcs.build();
}
use of java.nio.file.FileVisitResult in project buck by facebook.
the class IjProjectTemplateDataPreparer method createExcludes.
public ImmutableSet<IjFolder> createExcludes(final 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 {
// When we create excludes for that module.
if (filesystemTraversalBoundaryPaths.contains(dir) && !moduleBasePath.equals(dir)) {
return FileVisitResult.SKIP_SUBTREE;
}
if (isRootAndroidResourceDirectory(module, 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();
}
use of java.nio.file.FileVisitResult in project buck by facebook.
the class ProjectFilesystemTest method testWalkFileTreeWhenProjectRootIsWorkingDir.
@Test
public void testWalkFileTreeWhenProjectRootIsWorkingDir() throws IOException {
ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get(".").toAbsolutePath());
final ImmutableList.Builder<String> fileNames = ImmutableList.builder();
Path pathRelativeToProjectRoot = Paths.get("test/com/facebook/buck/io/testdata/directory_traversal_ignore_paths");
projectFilesystem.walkRelativeFileTree(pathRelativeToProjectRoot, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
fileNames.add(file.getFileName().toString());
return FileVisitResult.CONTINUE;
}
});
assertThat(fileNames.build(), containsInAnyOrder("file", "a_file", "b_file", "b_c_file", "b_d_file"));
}
use of java.nio.file.FileVisitResult in project buck by facebook.
the class FakeProjectFilesystem method walkRelativeFileTree.
/**
* TODO(natthu): (1) Also traverse the directories. (2) Do not ignore return value of
* {@code fileVisitor}.
*/
@Override
public final void walkRelativeFileTree(Path path, EnumSet<FileVisitOption> visitOptions, FileVisitor<Path> fileVisitor) throws IOException {
if (!isDirectory(path)) {
fileVisitor.visitFile(path, DEFAULT_FILE_ATTRIBUTES);
return;
}
ImmutableCollection<Path> ents = getDirectoryContents(path);
for (Path ent : ents) {
if (!isDirectory(ent)) {
FileVisitResult result = fileVisitor.visitFile(ent, DEFAULT_FILE_ATTRIBUTES);
if (result == FileVisitResult.SKIP_SIBLINGS) {
return;
}
} else {
FileVisitResult result = fileVisitor.preVisitDirectory(ent, DEFAULT_DIR_ATTRIBUTES);
if (result == FileVisitResult.SKIP_SIBLINGS) {
return;
}
if (result != FileVisitResult.SKIP_SUBTREE) {
walkRelativeFileTree(ent, fileVisitor);
fileVisitor.postVisitDirectory(ent, null);
}
}
}
}
use of java.nio.file.FileVisitResult in project elasticsearch-jdbc by jprante.
the class NodeTestUtils method deleteFiles.
private static void deleteFiles() throws IOException {
Path directory = Paths.get(System.getProperty("path.home") + "/data");
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
Aggregations