use of java.nio.file.attribute.BasicFileAttributes in project buck by facebook.
the class ProjectFilesystem method walkRelativeFileTree.
/**
* Walks a project-root relative file tree with a visitor and visit options.
*/
public void walkRelativeFileTree(Path pathRelativeToProjectRoot, EnumSet<FileVisitOption> visitOptions, final FileVisitor<Path> fileVisitor) throws IOException {
FileVisitor<Path> relativizingVisitor = new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return fileVisitor.preVisitDirectory(relativize(dir), attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
return fileVisitor.visitFile(relativize(file), attrs);
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return fileVisitor.visitFileFailed(relativize(file), exc);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return fileVisitor.postVisitDirectory(relativize(dir), exc);
}
};
Path rootPath = getPathForRelativePath(pathRelativeToProjectRoot);
walkFileTree(rootPath, visitOptions, relativizingVisitor);
}
use of java.nio.file.attribute.BasicFileAttributes in project buck by facebook.
the class ProvisioningProfileCopyStepTest method setUp.
@Before
public void setUp() throws IOException {
testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles");
projectFilesystem = new FakeProjectFilesystem(testdataDir);
Files.walkFileTree(testdataDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
projectFilesystem.writeBytesToPath(Files.readAllBytes(file), projectFilesystem.resolve(file));
return FileVisitResult.CONTINUE;
}
});
tempOutputDir = tmp.getRoot();
outputFile = tempOutputDir.resolve("embedded.mobileprovision");
xcentFile = Paths.get("test.xcent");
dryRunResultFile = Paths.get("test_dry_run_results.plist");
executionContext = TestExecutionContext.newInstance();
codeSignIdentityStore = CodeSignIdentityStore.fromIdentities(ImmutableList.of());
entitlementsFile = testdataDir.resolve("Entitlements.plist");
}
use of java.nio.file.attribute.BasicFileAttributes 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.attribute.BasicFileAttributes 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.attribute.BasicFileAttributes 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();
}
Aggregations