Java 类org.gradle.api.file.FileVisitor 实例源码

项目:Reer    文件:PackageListGenerator.java   
private void processDirectory(File file, final Trie.Builder builder) {
    new DirectoryFileTree(file).visit(new FileVisitor() {
        @Override
        public void visitDir(FileVisitDetails dirDetails) {
        }

        @Override
        public void visitFile(FileVisitDetails fileDetails) {
            try {
                ZipEntry zipEntry = new ZipEntry(fileDetails.getPath());
                InputStream inputStream = fileDetails.open();
                try {
                    processEntry(zipEntry, builder);
                } finally {
                    inputStream.close();
                }
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
}
项目:Reer    文件:DefaultJarSnapshotter.java   
JarSnapshot createSnapshot(HashCode hash, FileTree classes, final ClassFilesAnalyzer analyzer) {
    final Map<String, HashCode> hashes = Maps.newHashMap();
    classes.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            analyzer.visitFile(fileDetails);
            String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
            HashCode classHash = hasher.hash(fileDetails.getFile());
            hashes.put(className, classHash);
        }
    });

    return new JarSnapshot(new JarSnapshotData(hash, hashes, analyzer.getAnalysis()));
}
项目:Reer    文件:TarFileTree.java   
@Override
public void visitTreeOrBackingFile(final FileVisitor visitor) {
    File backingFile = getBackingFile();
    if (backingFile!=null) {
        new SingletonFileTree(backingFile).visit(visitor);
    } else {
        // We need to wrap the visitor so that the file seen by the visitor has already
        // been extracted from the archive and we do not try to extract it again.
        // It's unsafe to keep the FileVisitDetails provided by TarFileTree directly
        // because we do not expect to visit the same paths again (after extracting everything).
        visit(new FileVisitor() {
            @Override
            public void visitDir(FileVisitDetails dirDetails) {
                visitor.visitDir(new DefaultFileVisitDetails(dirDetails.getFile(), chmod, stat));
            }

            @Override
            public void visitFile(FileVisitDetails fileDetails) {
                visitor.visitFile(new DefaultFileVisitDetails(fileDetails.getFile(), chmod, stat));
            }
        });
    }
}
项目:Reer    文件:SingleIncludePatternFileTree.java   
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (stopFlag.get()) {
        return;
    }

    String segment = patternSegments.get(segmentIndex);

    if (segment.contains("**")) {
        PatternSet patternSet = new PatternSet();
        patternSet.include(includePattern);
        patternSet.exclude(excludeSpec);
        DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
        fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
    } else if (segment.contains("*") || segment.contains("?")) {
        PatternStep step = PatternStepFactory.getStep(segment, false);
        File[] children = file.listFiles();
        if (children == null) {
            if (!file.canRead()) {
                throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
            }
            // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
            throw new GradleException(String.format("Could not list contents of '%s'.", file));
        }
        for (File child : children) {
            if (stopFlag.get()) {
                break;
            }
            String childName = child.getName();
            if (step.matches(childName)) {
                relativePath.addLast(childName);
                doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
                relativePath.removeLast();
            }
        }
    } else {
        relativePath.addLast(segment);
        doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
        relativePath.removeLast();
    }
}
项目:Pushjet-Android    文件:DefaultJarSnapshotter.java   
JarSnapshot createSnapshot(byte[] hash, FileTree classes, final ClassFilesAnalyzer analyzer) {
    final Map<String, byte[]> hashes = new HashMap<String, byte[]>();
    classes.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            analyzer.visitFile(fileDetails);
            String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
            byte[] classHash = hasher.hash(fileDetails.getFile());
            hashes.put(className, classHash);
        }
    });

    return new JarSnapshot(new JarSnapshotData(hash, hashes, analyzer.getAnalysis()));
}
项目:st-js-gradle-plugin    文件:GenerateStJsTask.java   
private Collection<String> accumulatePackages() {
    final Collection<String> result = new HashSet<>();

    compileSourceRoots.getAsFileTree().visit(new FileVisitor() {

        @Override
        public void visitDir(FileVisitDetails dirDetails) {
            final String packageName =
                    dirDetails.getRelativePath().getPathString().replace(File.separatorChar, '.');
            if (logger.isDebugEnabled()) {
                logger.debug("Packages: " + packageName);
            }
            result.add(packageName);
        }

        @Override
        public void visitFile(FileVisitDetails fileDetails) {
            // ignore
        }
    });
    return result;
}
项目:Reer    文件:SerializableCoffeeScriptCompileSpec.java   
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();

    fileTree.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
项目:Reer    文件:TarFileTree.java   
private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException {
    AtomicBoolean stopFlag = new AtomicBoolean();
    NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
    TarEntry entry;
    while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
        if (entry.isDirectory()) {
            visitor.visitDir(new DetailsImpl(entry, tar, stopFlag, chmod));
        } else {
            visitor.visitFile(new DetailsImpl(entry, tar, stopFlag, chmod));
        }
    }
}
项目:Reer    文件:ZipFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    File backingFile = getBackingFile();
    if (backingFile!=null) {
        new SingletonFileTree(backingFile).visit(visitor);
    } else {
        visit(visitor);
    }
}
项目:Reer    文件:MapFileTree.java   
private void visitDirs(RelativePath path, FileVisitor visitor) {
    if (path == null || path.getParent() == null || !visitedDirs.add(path)) {
        return;
    }

    visitDirs(path.getParent(), visitor);
    visitor.visitDir(new FileVisitDetailsImpl(path, null, stopFlag, chmod));
}
项目:Reer    文件:DefaultDirectoryWalker.java   
@Override
public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) {
    File[] children = file.listFiles();
    if (children == null) {
        if (file.isDirectory() && !file.canRead()) {
            throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
        }
        // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
        throw new GradleException(String.format("Could not list contents of '%s'.", file));
    }
    List<FileVisitDetails> dirs = new ArrayList<FileVisitDetails>();
    for (int i = 0; !stopFlag.get() && i < children.length; i++) {
        File child = children[i];
        boolean isFile = child.isFile();
        RelativePath childPath = path.append(isFile, child.getName());
        FileVisitDetails details = new DefaultFileVisitDetails(child, childPath, stopFlag, fileSystem, fileSystem, !isFile);
        if (DirectoryFileTree.isAllowed(details, spec)) {
            if (isFile) {
                visitor.visitFile(details);
            } else {
                dirs.add(details);
            }
        }
    }

    // now handle dirs
    for (int i = 0; !stopFlag.get() && i < dirs.size(); i++) {
        FileVisitDetails dir = dirs.get(i);
        if (postfix) {
            walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
            visitor.visitDir(dir);
        } else {
            visitor.visitDir(dir);
            walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
        }
    }
}
项目:Reer    文件:DirectoryFileTree.java   
/**
 * Process the specified file or directory.  If it is a directory, then its contents
 * (but not the directory itself) will be checked with {@link #isAllowed(FileTreeElement, Spec)} and notified to
 * the listener.  If it is a file, the file will be checked and notified.
 */
public void visitFrom(FileVisitor visitor, File fileOrDirectory, RelativePath path) {
    AtomicBoolean stopFlag = new AtomicBoolean();
    Spec<FileTreeElement> spec = patternSet.getAsSpec();
    if (fileOrDirectory.exists()) {
        if (fileOrDirectory.isFile()) {
            processSingleFile(fileOrDirectory, visitor, spec, stopFlag);
        } else {
            walkDir(fileOrDirectory, path, visitor, spec, stopFlag);
        }
    } else {
        LOGGER.info("file or directory '{}', not found", fileOrDirectory);
    }
}
项目:Reer    文件:DirectoryFileTree.java   
private void processSingleFile(File file, FileVisitor visitor, Spec<FileTreeElement> spec, AtomicBoolean stopFlag) {
    RelativePath path = new RelativePath(true, file.getName());
    FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem, false);
    if (isAllowed(details, spec)) {
        visitor.visitFile(details);
    }
}
项目:Pushjet-Android    文件:SerializableCoffeeScriptCompileSpec.java   
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();

    fileTree.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
项目:Pushjet-Android    文件:TarFileTree.java   
private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException {
    AtomicBoolean stopFlag = new AtomicBoolean();
    NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
    TarEntry entry;
    while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
        if (entry.isDirectory()) {
            visitor.visitDir(new DetailsImpl(entry, tar, stopFlag, chmod));
        } else {
            visitor.visitFile(new DetailsImpl(entry, tar, stopFlag, chmod));
        }
    }
}
项目:Pushjet-Android    文件:MapFileTree.java   
private void visitDirs(RelativePath path, FileVisitor visitor) {
    if (path == null || path.getParent() == null || !visitedDirs.add(path)) {
        return;
    }

    visitDirs(path.getParent(), visitor);
    visitor.visitDir(new FileVisitDetailsImpl(path, null, stopFlag, chmod));
}
项目:Pushjet-Android    文件:SingleIncludePatternFileTree.java   
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (stopFlag.get()) {
        return;
    }

    String segment = patternSegments.get(segmentIndex);

    if (segment.contains("**")) {
        PatternSet patternSet = new PatternSet();
        patternSet.include(includePattern);
        patternSet.exclude(excludeSpec);
        DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
        fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
    } else if (segment.contains("*") || segment.contains("?")) {
        PatternStep step = PatternStepFactory.getStep(segment, false);
        File[] children = file.listFiles();
        if (children == null) {
            if (!file.canRead()) {
                throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
            }
            // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
            throw new GradleException(String.format("Could not list contents of '%s'.", file));
        }
        for (File child : children) {
            if (stopFlag.get()) { break; }
            if (step.matches(child.getName())) {
                relativePath.addLast(child.getName());
                doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
                relativePath.removeLast();
            }
        }
    } else {
        relativePath.addLast(segment);
        doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
        relativePath.removeLast();
    }
}
项目:Pushjet-Android    文件:SerializableCoffeeScriptCompileSpec.java   
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();

    fileTree.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
项目:Pushjet-Android    文件:TarFileTree.java   
public void visit(FileVisitor visitor) {
    InputStream inputStream;
    try {
        inputStream = resource.read();
        assert inputStream != null;
    } catch (MissingResourceException e) {
        DeprecationLogger.nagUserOfDeprecatedBehaviour(
                String.format("The specified tar file %s does not exist and will be silently ignored", getDisplayName())
        );
        return;
    } catch (ResourceException e) {
        throw new InvalidUserDataException(String.format("Cannot expand %s.", getDisplayName()), e);
    }

    try {
        try {
            visitImpl(visitor, inputStream);
        } finally {
            inputStream.close();
        }
    } catch (Exception e) {
        String message = "Unable to expand " + getDisplayName() + "\n"
                + "  The tar might be corrupted or it is compressed in an unexpected way.\n"
                + "  By default the tar tree tries to guess the compression based on the file extension.\n"
                + "  If you need to specify the compression explicitly please refer to the DSL reference.";
        throw new GradleException(message, e);
    }
}
项目:Pushjet-Android    文件:TarFileTree.java   
private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException {
    AtomicBoolean stopFlag = new AtomicBoolean();
    NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
    TarEntry entry;
    while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
        if (entry.isDirectory()) {
            visitor.visitDir(new DetailsImpl(entry, tar, stopFlag, chmod));
        } else {
            visitor.visitFile(new DetailsImpl(entry, tar, stopFlag, chmod));
        }
    }
}
项目:Pushjet-Android    文件:MapFileTree.java   
private void visitDirs(RelativePath path, FileVisitor visitor) {
    if (path == null || path.getParent() == null || !visitedDirs.add(path)) {
        return;
    }

    visitDirs(path.getParent(), visitor);
    visitor.visitDir(new FileVisitDetailsImpl(path, null, stopFlag, chmod));
}
项目:Pushjet-Android    文件:SingleIncludePatternFileTree.java   
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (stopFlag.get()) {
        return;
    }

    String segment = patternSegments.get(segmentIndex);

    if (segment.contains("**")) {
        PatternSet patternSet = new PatternSet();
        patternSet.include(includePattern);
        patternSet.exclude(excludeSpec);
        DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
        fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
    } else if (segment.contains("*") || segment.contains("?")) {
        PatternStep step = PatternStepFactory.getStep(segment, false);
        File[] children = file.listFiles();
        if (children == null) {
            if (!file.canRead()) {
                throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
            }
            // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
            throw new GradleException(String.format("Could not list contents of '%s'.", file));
        }
        for (File child : children) {
            if (stopFlag.get()) { break; }
            if (step.matches(child.getName())) {
                relativePath.addLast(child.getName());
                doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
                relativePath.removeLast();
            }
        }
    } else {
        relativePath.addLast(segment);
        doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
        relativePath.removeLast();
    }
}
项目:Pushjet-Android    文件:JarSnapshotter.java   
JarSnapshot createSnapshot(FileTree archivedClasses) {
    final Map<String, byte[]> hashes = new HashMap<String, byte[]>();
    archivedClasses.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            hashes.put(fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", ""), hasher.hash(fileDetails.getFile()));
        }
    });
    return new JarSnapshot(hashes);
}
项目:Pushjet-Android    文件:AllFromJarRebuildInfo.java   
private static Set<String> classesInJar(FileTree jarContents) {
    final Set<String> out = new HashSet<String>();
    jarContents.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}
        public void visitFile(FileVisitDetails fileDetails) {
            out.add(fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", ""));
        }
    });
    return out;
}
项目:Reer    文件:CompositeFileTree.java   
public FileTree visit(FileVisitor visitor) {
    for (FileTree tree : getSourceCollections()) {
        tree.visit(visitor);
    }
    return this;
}
项目:Reer    文件:CompositeFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    visit(visitor);
}
项目:Reer    文件:FileTreeAdapter.java   
public FileTree visit(FileVisitor visitor) {
    tree.visit(visitor);
    return this;
}
项目:Reer    文件:FileTreeAdapter.java   
public void visitTreeOrBackingFile(FileVisitor visitor) {
    tree.visitTreeOrBackingFile(visitor);
}
项目:Reer    文件:MapFileTree.java   
public Visit(FileVisitor visitor, AtomicBoolean stopFlag) {
    this.visitor = visitor;
    this.stopFlag = stopFlag;
}
项目:Reer    文件:MapFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    visit(visitor);
}
项目:Reer    文件:SingleIncludePatternFileTree.java   
public void visit(FileVisitor visitor) {
    doVisit(visitor, baseDir, new LinkedList<String>(), 0, new AtomicBoolean());
}
项目:Reer    文件:SingleIncludePatternFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    visit(visitor);
}
项目:Reer    文件:SingletonFileTree.java   
public void visit(FileVisitor visitor) {
    visitor.visitFile(new SingletonFileVisitDetails(file, fileSystem, false));
}
项目:Reer    文件:SingletonFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    visit(visitor);
}
项目:Reer    文件:DirectoryFileTree.java   
@Override
public void visitTreeOrBackingFile(FileVisitor visitor) {
    visit(visitor);
}
项目:Reer    文件:DirectoryFileTree.java   
public void visit(FileVisitor visitor) {
    visitFrom(visitor, dir, RelativePath.EMPTY_ROOT);
}
项目:Reer    文件:DirectoryFileTree.java   
private void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<FileTreeElement> spec, AtomicBoolean stopFlag) {
    directoryWalkerFactory.create().walkDir(file, path, visitor, spec, stopFlag, postfix);
}
项目:Pushjet-Android    文件:CompositeFileTree.java   
public FileTree visit(FileVisitor visitor) {
    for (FileTree tree : getSourceCollections()) {
        tree.visit(visitor);
    }
    return this;
}
项目:Pushjet-Android    文件:FileTreeAdapter.java   
public FileTree visit(FileVisitor visitor) {
    tree.visit(visitor);
    return this;
}
项目:Pushjet-Android    文件:EmptyFileTree.java   
public void visit(FileVisitor visitor) {
}