Search in sources :

Example 1 with FileMetadata

use of org.gradle.internal.file.FileMetadata 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 2 with FileMetadata

use of org.gradle.internal.file.FileMetadata 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 FileMetadata

use of org.gradle.internal.file.FileMetadata in project gradle by gradle.

the class ClasspathWalker method visitDir.

private void visitDir(File dir, String prefix, ClasspathEntryVisitor visitor) throws IOException {
    File[] files = dir.listFiles();
    // Apply a consistent order, regardless of file system ordering
    Arrays.sort(files, Comparator.comparing(File::getName));
    for (File file : files) {
        FileMetadata fileMetadata = stat.stat(file);
        if (fileMetadata.getType() == FileType.RegularFile) {
            visitFile(file, prefix + file.getName(), visitor);
        } else if (fileMetadata.getType() == FileType.Directory) {
            visitDir(file, prefix + file.getName() + "/", visitor);
        }
    }
}
Also used : FileMetadata(org.gradle.internal.file.FileMetadata) File(java.io.File)

Aggregations

FileMetadata (org.gradle.internal.file.FileMetadata)3 File (java.io.File)2 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)2 MissingFileSnapshot (org.gradle.internal.snapshot.MissingFileSnapshot)2 RegularFileSnapshot (org.gradle.internal.snapshot.RegularFileSnapshot)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DefaultFileMetadata (org.gradle.internal.file.impl.DefaultFileMetadata)1 HashCode (org.gradle.internal.hash.HashCode)1 DirectorySnapshot (org.gradle.internal.snapshot.DirectorySnapshot)1 RootTrackingFileSystemSnapshotHierarchyVisitor (org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor)1 SnapshotVisitResult (org.gradle.internal.snapshot.SnapshotVisitResult)1