use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.
the class NonHierarchicalFileWatcherUpdater method handleVirtualFileSystemContentsChanged.
@Override
protected boolean handleVirtualFileSystemContentsChanged(Collection<FileSystemLocationSnapshot> removedSnapshots, Collection<FileSystemLocationSnapshot> addedSnapshots, SnapshotHierarchy root) {
Map<String, Integer> changedWatchedDirectories = new HashMap<>();
removedSnapshots.stream().filter(watchableHierarchies::shouldWatch).forEach(snapshot -> {
String previousWatchedRoot = watchedDirectoryForSnapshot.remove(snapshot.getAbsolutePath());
decrement(previousWatchedRoot, changedWatchedDirectories);
snapshot.accept(new SubdirectoriesToWatchVisitor(path -> decrement(path, changedWatchedDirectories)));
});
addedSnapshots.stream().filter(watchableHierarchies::shouldWatch).forEach(snapshot -> {
File directoryToWatchForRoot = SnapshotWatchedDirectoryFinder.getDirectoryToWatch(snapshot);
String pathToWatchForRoot = directoryToWatchForRoot.getAbsolutePath();
if (!watchableHierarchies.isInWatchableHierarchy(pathToWatchForRoot)) {
return;
}
watchedDirectoryForSnapshot.put(snapshot.getAbsolutePath(), pathToWatchForRoot);
increment(pathToWatchForRoot, changedWatchedDirectories);
snapshot.accept(new SubdirectoriesToWatchVisitor(path -> increment(path, changedWatchedDirectories)));
});
if (changedWatchedDirectories.isEmpty()) {
return false;
}
updateWatchedDirectories(changedWatchedDirectories);
return true;
}
use of org.gradle.internal.snapshot.FileSystemLocationSnapshot in project gradle by gradle.
the class TarBuildCacheEntryPacker method unpack.
private UnpackResult unpack(CacheableEntity entity, TarArchiveInputStream tarInput, OriginReader readOriginAction) throws IOException {
ImmutableMap.Builder<String, CacheableTree> treesBuilder = ImmutableMap.builder();
entity.visitOutputTrees((name, type, root) -> treesBuilder.put(name, new CacheableTree(type, root)));
ImmutableMap<String, CacheableTree> treesByName = treesBuilder.build();
TarArchiveEntry tarEntry;
OriginMetadata originMetadata = null;
Map<String, FileSystemLocationSnapshot> snapshots = new HashMap<>();
tarEntry = tarInput.getNextTarEntry();
AtomicLong entries = new AtomicLong();
while (tarEntry != null) {
entries.incrementAndGet();
String path = tarEntry.getName();
if (path.equals(METADATA_PATH)) {
// handle origin metadata
originMetadata = readOriginAction.execute(new CloseShieldInputStream(tarInput));
tarEntry = tarInput.getNextTarEntry();
} else {
// handle tree
Matcher matcher = TREE_PATH.matcher(path);
if (!matcher.matches()) {
throw new IllegalStateException("Cached entry format error, invalid contents: " + path);
}
String treeName = unescape(matcher.group(2));
CacheableTree tree = treesByName.get(treeName);
if (tree == null) {
throw new IllegalStateException(String.format("No tree '%s' registered", treeName));
}
boolean missing = matcher.group(1) != null;
String childPath = matcher.group(3);
tarEntry = unpackTree(treeName, tree.getType(), tree.getRoot(), tarInput, tarEntry, childPath, missing, snapshots, entries);
}
}
if (originMetadata == null) {
throw new IllegalStateException("Cached result format error, no origin metadata was found.");
}
return new UnpackResult(originMetadata, entries.get(), snapshots);
}
Aggregations