use of java.nio.file.FileVisitResult in project buck by facebook.
the class InterCellIntegrationTest method findObjectFiles.
private ImmutableMap<String, HashCode> findObjectFiles(final ProjectWorkspace workspace) throws IOException {
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
final Path buckOut = workspace.getPath(filesystem.getBuckPaths().getBuckOut());
final ImmutableMap.Builder<String, HashCode> objectHashCodes = ImmutableMap.builder();
Files.walkFileTree(buckOut, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (MorePaths.getFileExtension(file).equals("o")) {
HashCode hash = MorePaths.asByteSource(file).hash(Hashing.sha1());
objectHashCodes.put(buckOut.relativize(file).toString(), hash);
}
return FileVisitResult.CONTINUE;
}
});
ImmutableMap<String, HashCode> toReturn = objectHashCodes.build();
Preconditions.checkState(!toReturn.isEmpty());
return toReturn;
}
use of java.nio.file.FileVisitResult in project buck by facebook.
the class ProjectFilesystemTest method ignoredPathsShouldBeIgnoredWhenWalkingTheFilesystem.
@Test
public void ignoredPathsShouldBeIgnoredWhenWalkingTheFilesystem() throws IOException {
Config config = ConfigBuilder.createFromText("[project]", "ignore = **/*.orig");
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot(), config);
Files.createDirectories(tmp.getRoot().resolve("foo/bar"));
filesystem.touch(Paths.get("foo/bar/cake.txt"));
filesystem.touch(Paths.get("foo/bar/cake.txt.orig"));
final ImmutableSet.Builder<String> allPaths = ImmutableSet.builder();
filesystem.walkRelativeFileTree(tmp.getRoot(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
allPaths.add(file.toString());
return FileVisitResult.CONTINUE;
}
});
ImmutableSet<String> found = allPaths.build();
assertTrue(found.contains(Paths.get("foo/bar/cake.txt").toString()));
assertFalse(found.contains(Paths.get("foo/bar/cake.txt.orig").toString()));
}
use of java.nio.file.FileVisitResult 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();
}
use of java.nio.file.FileVisitResult in project gradle by gradle.
the class WatchServiceRegistrar method watch.
void watch(FileSystemSubset fileSystemSubset) throws IOException {
lock.lock();
try {
LOG.debug("Begin - adding watches for {}", fileSystemSubset);
final WatchPointsRegistry.Delta delta = watchPointsRegistry.appendFileSystemSubset(fileSystemSubset, getCurrentWatchPoints());
Iterable<? extends File> startingWatchPoints = delta.getStartingWatchPoints();
for (File dir : startingWatchPoints) {
LOG.debug("Begin - handling starting point {}", dir);
final Path dirPath = dir.toPath();
watchDir(dirPath);
if (!FILE_TREE_WATCHING_SUPPORTED) {
Files.walkFileTree(dirPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException {
if (!path.equals(dirPath)) {
if (delta.shouldWatch(path.toFile())) {
watchDir(path);
return FileVisitResult.CONTINUE;
} else {
LOG.debug("Skipping watching for {}, filtered by WatchPointsRegistry", path);
return FileVisitResult.SKIP_SUBTREE;
}
} else {
return FileVisitResult.CONTINUE;
}
}
});
}
LOG.debug("End - handling starting point {}", dir);
}
LOG.debug("End - adding watches for {}", fileSystemSubset);
} finally {
lock.unlock();
}
}
use of java.nio.file.FileVisitResult in project orientdb by orientechnologies.
the class LocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords method copyDataFromTestWithoutClose.
private void copyDataFromTestWithoutClose() throws Exception {
final Path testStoragePath = Paths.get(baseDocumentTx.getURL().substring("plocal:".length()));
Path buildPath = Paths.get(buildDir.toURI());
final Path copyTo = buildPath.resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords");
Files.copy(testStoragePath, copyTo);
Files.walkFileTree(testStoragePath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Path fileToCopy = copyTo.resolve(testStoragePath.relativize(file));
if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.wmr"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.wmr");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.0.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.0.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.1.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.1.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.2.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.2.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.3.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.3.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.4.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.4.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.5.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.5.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.6.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.6.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.7.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.7.wal");
else if (fileToCopy.endsWith("baseLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.8.wal"))
fileToCopy = fileToCopy.getParent().resolve("testLocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords.8.wal");
if (fileToCopy.endsWith("dirty.fl"))
return FileVisitResult.CONTINUE;
Files.copy(file, fileToCopy);
return FileVisitResult.CONTINUE;
}
});
}
Aggregations