Search in sources :

Example 1 with DefaultFileVisitDetails

use of org.gradle.api.internal.file.DefaultFileVisitDetails in project gradle by gradle.

the class AbstractDirectoryWalker method walkDir.

@Override
public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) {
    File[] children = getChildren(file);
    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);
        }
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) FileVisitDetails(org.gradle.api.file.FileVisitDetails) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) File(java.io.File)

Example 2 with DefaultFileVisitDetails

use of org.gradle.api.internal.file.DefaultFileVisitDetails in project gradle by gradle.

the class ReproducibleDirectoryWalker method walkDir.

@Override
public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) {
    File[] children = getChildren(file);
    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);
        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);
        }
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) FileVisitDetails(org.gradle.api.file.FileVisitDetails) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) File(java.io.File)

Example 3 with DefaultFileVisitDetails

use of org.gradle.api.internal.file.DefaultFileVisitDetails in project gradle by gradle.

the class DirectoryFileTree method processSingleFile.

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);
    if (isAllowed(details, spec)) {
        visitor.visitFile(details);
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) FileVisitDetails(org.gradle.api.file.FileVisitDetails) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails)

Example 4 with DefaultFileVisitDetails

use of org.gradle.api.internal.file.DefaultFileVisitDetails in project gradle by gradle.

the class SingleIncludePatternFileTree method doVisitDirOrFile.

private void doVisitDirOrFile(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (file.isFile()) {
        if (segmentIndex == patternSegments.size()) {
            RelativePath path = new RelativePath(true, relativePath.toArray(new String[relativePath.size()]));
            FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem);
            if (!excludeSpec.isSatisfiedBy(details)) {
                visitor.visitFile(details);
            }
        }
    } else if (file.isDirectory()) {
        RelativePath path = new RelativePath(false, relativePath.toArray(new String[relativePath.size()]));
        FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem);
        if (!excludeSpec.isSatisfiedBy(details)) {
            visitor.visitDir(details);
        }
        if (segmentIndex < patternSegments.size()) {
            doVisit(visitor, file, relativePath, segmentIndex, stopFlag);
        }
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) FileVisitDetails(org.gradle.api.file.FileVisitDetails) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails)

Aggregations

FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 RelativePath (org.gradle.api.file.RelativePath)4 DefaultFileVisitDetails (org.gradle.api.internal.file.DefaultFileVisitDetails)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 GradleException (org.gradle.api.GradleException)2