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