use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class DefaultFileSystemSnapshotter method calculateDetails.
private FileSnapshot calculateDetails(File file) {
String path = internPath(file);
FileMetadataSnapshot stat = fileSystem.stat(file);
switch(stat.getType()) {
case Missing:
return new MissingFileSnapshot(path, new RelativePath(true, file.getName()));
case Directory:
return new DirectoryFileSnapshot(path, new RelativePath(false, file.getName()), true);
case RegularFile:
return new RegularFileSnapshot(path, new RelativePath(true, file.getName()), true, fileSnapshot(file, stat));
default:
throw new IllegalArgumentException("Unrecognized file type: " + stat.getType());
}
}
use of org.gradle.api.file.RelativePath 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.file.RelativePath 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);
}
}
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class NormalizingCopyActionDecorator method execute.
@Override
public WorkResult execute(final CopyActionProcessingStream stream) {
final Set<RelativePath> visitedDirs = new HashSet<>();
final ListMultimap<RelativePath, FileCopyDetailsInternal> pendingDirs = ArrayListMultimap.create();
return delegate.execute(action -> {
stream.process(details -> {
if (details.isDirectory()) {
RelativePath path = details.getRelativePath();
if (!visitedDirs.contains(path)) {
pendingDirs.put(path, details);
}
} else {
maybeVisit(details.getRelativePath().getParent(), details.isIncludeEmptyDirs(), action, visitedDirs, pendingDirs);
action.processFile(details);
}
});
for (RelativePath path : new LinkedHashSet<>(pendingDirs.keySet())) {
List<FileCopyDetailsInternal> detailsList = new ArrayList<>(pendingDirs.get(path));
for (FileCopyDetailsInternal details : detailsList) {
if (details.isIncludeEmptyDirs()) {
maybeVisit(path, details.isIncludeEmptyDirs(), action, visitedDirs, pendingDirs);
}
}
}
visitedDirs.clear();
pendingDirs.clear();
});
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class SingleFileTreeElementMatcher method elementWithRelativePathMatches.
public boolean elementWithRelativePathMatches(Spec<FileTreeElement> filter, File element, String relativePathString) {
// A better solution for output files would be to record the type of the output file and then using this type here instead of looking at the disk.
// Though that is more involved and as soon as the file has been produced, the right file type will be detected here as well.
boolean elementIsFile = !element.isDirectory();
RelativePath relativePath = RelativePath.parse(elementIsFile, relativePathString);
if (!filter.isSatisfiedBy(new ReadOnlyFileTreeElement(element, relativePath, stat))) {
return false;
}
// All parent paths need to match the spec as well, since this is how we implement the file system walking for file tree.
RelativePath parentRelativePath = relativePath.getParent();
File parentFile = element.getParentFile();
while (parentRelativePath != null && parentRelativePath != RelativePath.EMPTY_ROOT) {
if (!filter.isSatisfiedBy(new ReadOnlyFileTreeElement(parentFile, parentRelativePath, stat))) {
return false;
}
parentRelativePath = parentRelativePath.getParent();
parentFile = parentFile.getParentFile();
}
return true;
}
Aggregations