Search in sources :

Example 21 with RelativePath

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());
    }
}
Also used : FileMetadataSnapshot(org.gradle.internal.file.FileMetadataSnapshot) RelativePath(org.gradle.api.file.RelativePath)

Example 22 with RelativePath

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);
    }
}
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 23 with RelativePath

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);
        }
    }
}
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 24 with RelativePath

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();
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RelativePath(org.gradle.api.file.RelativePath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 25 with RelativePath

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;
}
Also used : RelativePath(org.gradle.api.file.RelativePath) File(java.io.File)

Aggregations

RelativePath (org.gradle.api.file.RelativePath)25 File (java.io.File)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 FileVisitDetails (org.gradle.api.file.FileVisitDetails)5 DefaultFileVisitDetails (org.gradle.api.internal.file.DefaultFileVisitDetails)4 GradleException (org.gradle.api.GradleException)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Spec (org.gradle.api.specs.Spec)2 PatternSet (org.gradle.api.tasks.util.PatternSet)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1