Search in sources :

Example 1 with FileSystemLocationSnapshot

use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.

the class FilteredTrackingMerkleDirectorySnapshotBuilder method leaveDirectory.

@Override
public FileSystemLocationSnapshot leaveDirectory() {
    FileSystemLocationSnapshot directorySnapshot = delegate.leaveDirectory();
    boolean leftLevelUnfiltered = isCurrentLevelUnfiltered.removeLast();
    isCurrentLevelUnfiltered.addLast(isCurrentLevelUnfiltered.removeLast() && leftLevelUnfiltered);
    if (!leftLevelUnfiltered && directorySnapshot != null) {
        directorySnapshot.accept(new RootTrackingFileSystemSnapshotHierarchyVisitor() {

            @Override
            public SnapshotVisitResult visitEntry(FileSystemLocationSnapshot snapshot, boolean isRoot) {
                if (isRoot) {
                    return SnapshotVisitResult.CONTINUE;
                } else {
                    unfilteredSnapshotConsumer.accept(snapshot);
                }
                return SnapshotVisitResult.SKIP_SUBTREE;
            }
        });
    }
    return directorySnapshot;
}
Also used : RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot)

Example 2 with FileSystemLocationSnapshot

use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.

the class DefaultFileSystemAccess method snapshot.

private FileSystemLocationSnapshot snapshot(String location, SnapshottingFilter filter) {
    File file = new File(location);
    FileMetadata fileMetadata = this.stat.stat(file);
    switch(fileMetadata.getType()) {
        case RegularFile:
            HashCode hash = hasher.hash(file, fileMetadata.getLength(), fileMetadata.getLastModified());
            RegularFileSnapshot regularFileSnapshot = new RegularFileSnapshot(location, file.getName(), hash, fileMetadata);
            virtualFileSystem.store(regularFileSnapshot.getAbsolutePath(), regularFileSnapshot);
            return regularFileSnapshot;
        case Missing:
            MissingFileSnapshot missingFileSnapshot = new MissingFileSnapshot(location, fileMetadata.getAccessType());
            virtualFileSystem.store(missingFileSnapshot.getAbsolutePath(), missingFileSnapshot);
            return missingFileSnapshot;
        case Directory:
            AtomicBoolean hasBeenFiltered = new AtomicBoolean(false);
            FileSystemLocationSnapshot directorySnapshot = directorySnapshotter.snapshot(location, filter.isEmpty() ? null : filter.getAsDirectoryWalkerPredicate(), hasBeenFiltered, snapshot -> virtualFileSystem.store(snapshot.getAbsolutePath(), snapshot));
            if (!hasBeenFiltered.get()) {
                virtualFileSystem.store(directorySnapshot.getAbsolutePath(), directorySnapshot);
            }
            return directorySnapshot;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashCode(org.gradle.internal.hash.HashCode) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) FileMetadata(org.gradle.internal.file.FileMetadata) MissingFileSnapshot(org.gradle.internal.snapshot.MissingFileSnapshot) File(java.io.File)

Example 3 with FileSystemLocationSnapshot

use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.

the class DefaultOverlappingOutputDetector method detect.

@Nullable
private static OverlappingOutputs detect(String propertyName, FileSystemSnapshot previous, FileSystemSnapshot before) {
    Map<String, FileSystemLocationSnapshot> previousIndex = SnapshotUtil.index(previous);
    OverlappingOutputsDetectingVisitor outputsDetectingVisitor = new OverlappingOutputsDetectingVisitor(previousIndex);
    before.accept(outputsDetectingVisitor);
    String overlappingPath = outputsDetectingVisitor.getOverlappingPath();
    return overlappingPath == null ? null : new OverlappingOutputs(propertyName, overlappingPath);
}
Also used : OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Nullable(javax.annotation.Nullable)

Example 4 with FileSystemLocationSnapshot

use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.

the class FileSystemSnapshotSerializer method write.

@Override
public void write(Encoder encoder, FileSystemSnapshot value) throws Exception {
    value.accept(new RootTrackingFileSystemSnapshotHierarchyVisitor() {

        @Override
        public void enterDirectory(DirectorySnapshot directorySnapshot, boolean isRoot) {
            try {
                writeEntryType(encoder, EntryType.DIR_OPEN);
                writePath(encoder, isRoot, directorySnapshot);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        @Override
        public SnapshotVisitResult visitEntry(FileSystemLocationSnapshot snapshot, boolean isRoot) {
            snapshot.accept(new FileSystemLocationSnapshot.FileSystemLocationSnapshotVisitor() {

                @Override
                public void visitRegularFile(RegularFileSnapshot fileSnapshot) {
                    try {
                        writeEntryType(encoder, EntryType.REGULAR_FILE);
                        writePath(encoder, isRoot, fileSnapshot);
                        writeAccessType(encoder, fileSnapshot.getAccessType());
                        writeHashCode(encoder, fileSnapshot.getHash());
                        FileMetadata metadata = fileSnapshot.getMetadata();
                        encoder.writeSmallLong(metadata.getLastModified());
                        encoder.writeSmallLong(metadata.getLength());
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }

                @Override
                public void visitMissing(MissingFileSnapshot missingSnapshot) {
                    try {
                        writeEntryType(encoder, EntryType.MISSING);
                        writePath(encoder, isRoot, missingSnapshot);
                        writeAccessType(encoder, missingSnapshot.getAccessType());
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }
            });
            return SnapshotVisitResult.CONTINUE;
        }

        @Override
        public void leaveDirectory(DirectorySnapshot directorySnapshot, boolean isRoot) {
            try {
                writeEntryType(encoder, EntryType.DIR_CLOSE);
                writeAccessType(encoder, directorySnapshot.getAccessType());
                writeHashCode(encoder, directorySnapshot.getHash());
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
    encoder.writeByte((byte) EntryType.END.ordinal());
}
Also used : RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) FileMetadata(org.gradle.internal.file.FileMetadata) DefaultFileMetadata(org.gradle.internal.file.impl.DefaultFileMetadata) MissingFileSnapshot(org.gradle.internal.snapshot.MissingFileSnapshot) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DirectorySnapshot(org.gradle.internal.snapshot.DirectorySnapshot)

Example 5 with FileSystemLocationSnapshot

use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.

the class FileSystemSnapshotSerializer method read.

@Override
public FileSystemSnapshot read(Decoder decoder) throws Exception {
    SnapshotStack stack = new SnapshotStack();
    stack.push();
    Deque<String> pathTracker = new ArrayDeque<>();
    while (true) {
        EntryType type = readEntryType(decoder);
        if (type == EntryType.END) {
            break;
        }
        if (type != EntryType.DIR_CLOSE) {
            String path = decoder.readString();
            String internedPath = stringInterner.intern(path);
            pathTracker.addLast(internedPath);
            if (type == EntryType.DIR_OPEN) {
                stack.push();
                continue;
            }
        }
        String internedAbsolutePath;
        String internedName;
        String path = pathTracker.removeLast();
        if (pathTracker.isEmpty()) {
            internedAbsolutePath = path;
            internedName = stringInterner.intern(PathUtil.getFileName(internedAbsolutePath));
        } else {
            internedAbsolutePath = stringInterner.intern(toAbsolutePath(pathTracker, path));
            internedName = path;
        }
        FileMetadata.AccessType accessType = readAccessType(decoder);
        switch(type) {
            case REGULAR_FILE:
                HashCode contentHash = readHashCode(decoder);
                long lastModified = decoder.readSmallLong();
                long length = decoder.readSmallLong();
                stack.add(new RegularFileSnapshot(internedAbsolutePath, internedName, contentHash, DefaultFileMetadata.file(lastModified, length, accessType)));
                break;
            case MISSING:
                stack.add(new MissingFileSnapshot(internedAbsolutePath, internedName, accessType));
                break;
            case DIR_CLOSE:
                HashCode merkleHash = readHashCode(decoder);
                List<FileSystemLocationSnapshot> children = stack.pop();
                stack.add(new DirectorySnapshot(internedAbsolutePath, internedName, accessType, merkleHash, children));
                break;
            default:
                throw new AssertionError();
        }
    }
    return CompositeFileSystemSnapshot.of(stack.pop());
}
Also used : FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) FileMetadata(org.gradle.internal.file.FileMetadata) DefaultFileMetadata(org.gradle.internal.file.impl.DefaultFileMetadata) ArrayDeque(java.util.ArrayDeque) DirectorySnapshot(org.gradle.internal.snapshot.DirectorySnapshot) HashCode(org.gradle.internal.hash.HashCode) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) MissingFileSnapshot(org.gradle.internal.snapshot.MissingFileSnapshot)

Aggregations

FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)12 HashCode (org.gradle.internal.hash.HashCode)6 MissingFileSnapshot (org.gradle.internal.snapshot.MissingFileSnapshot)6 RootTrackingFileSystemSnapshotHierarchyVisitor (org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor)6 SnapshotVisitResult (org.gradle.internal.snapshot.SnapshotVisitResult)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 RegularFileSnapshot (org.gradle.internal.snapshot.RegularFileSnapshot)5 HashSet (java.util.HashSet)4 FileMetadata (org.gradle.internal.file.FileMetadata)3 FileSystemLocationFingerprint (org.gradle.internal.fingerprint.FileSystemLocationFingerprint)3 DirectorySnapshot (org.gradle.internal.snapshot.DirectorySnapshot)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Nullable (javax.annotation.Nullable)2 DefaultFileMetadata (org.gradle.internal.file.impl.DefaultFileMetadata)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayDeque (java.util.ArrayDeque)1