Search in sources :

Example 1 with RootTrackingFileSystemSnapshotHierarchyVisitor

use of org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor 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 RootTrackingFileSystemSnapshotHierarchyVisitor

use of org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor 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 3 with RootTrackingFileSystemSnapshotHierarchyVisitor

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

the class OutputFileChanges method index.

private static Map<String, FileSystemLocationSnapshot> index(FileSystemSnapshot snapshot) {
    Map<String, FileSystemLocationSnapshot> index = new LinkedHashMap<>();
    snapshot.accept(new RootTrackingFileSystemSnapshotHierarchyVisitor() {

        @Override
        public SnapshotVisitResult visitEntry(FileSystemLocationSnapshot snapshot, boolean isRoot) {
            // Remove missing roots so they show up as added/removed instead of changed
            if (!(isRoot && snapshot instanceof MissingFileSnapshot)) {
                index.put(snapshot.getAbsolutePath(), snapshot);
            }
            return SnapshotVisitResult.CONTINUE;
        }
    });
    return index;
}
Also used : RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) MissingFileSnapshot(org.gradle.internal.snapshot.MissingFileSnapshot) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RootTrackingFileSystemSnapshotHierarchyVisitor

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

the class NameOnlyFingerprintingStrategy method collectFingerprints.

@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
    ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
    HashSet<String> processedEntries = new HashSet<>();
    roots.accept(new RootTrackingFileSystemSnapshotHierarchyVisitor() {

        @Override
        public SnapshotVisitResult visitEntry(FileSystemLocationSnapshot snapshot, boolean isRoot) {
            String absolutePath = snapshot.getAbsolutePath();
            if (processedEntries.add(absolutePath) && getDirectorySensitivity().shouldFingerprint(snapshot)) {
                if (isRoot && snapshot.getType() == FileType.Directory) {
                    builder.put(absolutePath, IgnoredPathFileSystemLocationFingerprint.DIRECTORY);
                } else {
                    HashCode normalizedContentHash = getNormalizedContentHash(snapshot, normalizedContentHasher);
                    if (normalizedContentHash != null) {
                        builder.put(absolutePath, new DefaultFileSystemLocationFingerprint(snapshot.getName(), snapshot.getType(), normalizedContentHash));
                    }
                }
            }
            return SnapshotVisitResult.CONTINUE;
        }
    });
    return builder.build();
}
Also used : SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) ImmutableMap(com.google.common.collect.ImmutableMap) RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) HashCode(org.gradle.internal.hash.HashCode) HashSet(java.util.HashSet)

Example 5 with RootTrackingFileSystemSnapshotHierarchyVisitor

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

the class AbsolutePathFingerprintingStrategy method collectFingerprints.

@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
    ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
    HashSet<String> processedEntries = new HashSet<>();
    roots.accept(new RootTrackingFileSystemSnapshotHierarchyVisitor() {

        @Override
        public SnapshotVisitResult visitEntry(FileSystemLocationSnapshot snapshot, boolean isRoot) {
            String absolutePath = snapshot.getAbsolutePath();
            if (processedEntries.add(absolutePath) && getDirectorySensitivity().shouldFingerprint(snapshot)) {
                HashCode normalizedContentHash = getNormalizedContentHash(snapshot, normalizedContentHasher);
                if (normalizedContentHash != null) {
                    builder.put(absolutePath, new DefaultFileSystemLocationFingerprint(snapshot.getAbsolutePath(), snapshot.getType(), normalizedContentHash));
                }
            }
            return SnapshotVisitResult.CONTINUE;
        }
    });
    return builder.build();
}
Also used : SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) ImmutableMap(com.google.common.collect.ImmutableMap) RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) HashCode(org.gradle.internal.hash.HashCode) HashSet(java.util.HashSet)

Aggregations

FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)5 RootTrackingFileSystemSnapshotHierarchyVisitor (org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor)5 SnapshotVisitResult (org.gradle.internal.snapshot.SnapshotVisitResult)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashSet (java.util.HashSet)2 FileSystemLocationFingerprint (org.gradle.internal.fingerprint.FileSystemLocationFingerprint)2 HashCode (org.gradle.internal.hash.HashCode)2 MissingFileSnapshot (org.gradle.internal.snapshot.MissingFileSnapshot)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 LinkedHashMap (java.util.LinkedHashMap)1 FileMetadata (org.gradle.internal.file.FileMetadata)1 DefaultFileMetadata (org.gradle.internal.file.impl.DefaultFileMetadata)1 DirectorySnapshot (org.gradle.internal.snapshot.DirectorySnapshot)1 RegularFileSnapshot (org.gradle.internal.snapshot.RegularFileSnapshot)1