Search in sources :

Example 81 with BasicFileAttributes

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);
}
Also used : Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) FileVisitor(java.nio.file.FileVisitor) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 82 with BasicFileAttributes

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");
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Before(org.junit.Before)

Example 83 with BasicFileAttributes

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;
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) FileVisitResult(java.nio.file.FileVisitResult) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 84 with BasicFileAttributes

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()));
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) Config(com.facebook.buck.config.Config) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 85 with BasicFileAttributes

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();
}
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

BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)119 Path (java.nio.file.Path)93 IOException (java.io.IOException)87 FileVisitResult (java.nio.file.FileVisitResult)66 File (java.io.File)18 Test (org.junit.Test)13 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)11 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)8 FileNotFoundException (java.io.FileNotFoundException)7 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)5 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)5 SourcePath (com.facebook.buck.rules.SourcePath)4 ImmutableList (com.google.common.collect.ImmutableList)4 OutputStream (java.io.OutputStream)4 URI (java.net.URI)4 FileSystem (java.nio.file.FileSystem)4 FileVisitor (java.nio.file.FileVisitor)4