Search in sources :

Example 11 with FileSystemLocationSnapshot

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;
}
Also used : SnapshotVisitResult(org.gradle.internal.snapshot.SnapshotVisitResult) WatchingNotSupportedException(org.gradle.internal.watch.WatchingNotSupportedException) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) Multiset(com.google.common.collect.Multiset) RootTrackingFileSystemSnapshotHierarchyVisitor(org.gradle.internal.snapshot.RootTrackingFileSystemSnapshotHierarchyVisitor) LoggerFactory(org.slf4j.LoggerFactory) FileWatcher(net.rubygrapefruit.platform.file.FileWatcher) HashMap(java.util.HashMap) HashSet(java.util.HashSet) HashMultiset(com.google.common.collect.HashMultiset) MissingFileSnapshot(org.gradle.internal.snapshot.MissingFileSnapshot) Map(java.util.Map) FileWatcherProbeRegistry(org.gradle.internal.watch.registry.FileWatcherProbeRegistry) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Collection(java.util.Collection) Set(java.util.Set) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) File(java.io.File) Consumer(java.util.function.Consumer) NativeException(net.rubygrapefruit.platform.NativeException) DirectorySnapshot(org.gradle.internal.snapshot.DirectorySnapshot) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) FileSystemLocationSnapshotTransformer(org.gradle.internal.snapshot.FileSystemLocationSnapshot.FileSystemLocationSnapshotTransformer) HashMap(java.util.HashMap) File(java.io.File)

Example 12 with FileSystemLocationSnapshot

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);
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) AtomicLong(java.util.concurrent.atomic.AtomicLong) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream)

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