Search in sources :

Example 51 with FileVisitResult

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;
}
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 52 with FileVisitResult

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

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

Example 54 with FileVisitResult

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

Example 55 with FileVisitResult

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

Aggregations

FileVisitResult (java.nio.file.FileVisitResult)74 Path (java.nio.file.Path)67 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)66 IOException (java.io.IOException)65 File (java.io.File)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 JarEntry (java.util.jar.JarEntry)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 FileOutputStream (java.io.FileOutputStream)3 JarOutputStream (java.util.jar.JarOutputStream)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)2 FileSystemException (io.vertx.core.file.FileSystemException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2