use of org.gradle.internal.snapshot.MissingFileSnapshot 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();
}
}
use of org.gradle.internal.snapshot.MissingFileSnapshot 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());
}
use of org.gradle.internal.snapshot.MissingFileSnapshot 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());
}
use of org.gradle.internal.snapshot.MissingFileSnapshot 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;
}
use of org.gradle.internal.snapshot.MissingFileSnapshot in project gradle by gradle.
the class IgnoredPathFingerprintingStrategy method collectFingerprints.
@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
HashSet<String> processedEntries = new HashSet<>();
roots.accept(snapshot -> {
snapshot.accept(new FileSystemLocationSnapshotVisitor() {
@Override
public void visitRegularFile(RegularFileSnapshot fileSnapshot) {
visitNonDirectoryEntry(snapshot);
}
@Override
public void visitMissing(MissingFileSnapshot missingSnapshot) {
visitNonDirectoryEntry(snapshot);
}
private void visitNonDirectoryEntry(FileSystemLocationSnapshot snapshot) {
String absolutePath = snapshot.getAbsolutePath();
if (processedEntries.add(absolutePath)) {
HashCode normalizedContentHash = getNormalizedContentHash(snapshot, normalizedContentHasher);
if (normalizedContentHash != null) {
builder.put(absolutePath, IgnoredPathFileSystemLocationFingerprint.create(snapshot.getType(), normalizedContentHash));
}
}
}
});
return SnapshotVisitResult.CONTINUE;
});
return builder.build();
}
Aggregations