Search in sources :

Example 1 with FileHierarchySet

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

the class AbstractFileWatcherUpdater method update.

private void update(SnapshotHierarchy root) {
    FileHierarchySet oldWatchedFiles = watchedFiles;
    watchedFiles = resolveWatchedFiles(watchableHierarchies, root);
    if (!watchedFiles.equals(oldWatchedFiles)) {
        updateWatchesOnChangedWatchedFiles(watchedFiles);
    }
    // Probe every hierarchy that is watched, even ones nested inside others
    ImmutableSet<File> oldProbedHierarchies = probedHierarchies;
    probedHierarchies = watchableHierarchies.stream().filter(watchedFiles::contains).collect(ImmutableSet.toImmutableSet());
    if (oldProbedHierarchies.equals(probedHierarchies)) {
        return;
    }
    oldProbedHierarchies.stream().filter(oldProbedHierarchy -> !probedHierarchies.contains(oldProbedHierarchy)).forEach(probedHierarchy -> {
        File probeDirectory = probeRegistry.getProbeDirectory(probedHierarchy);
        probeRegistry.disarmWatchProbe(probedHierarchy);
        stopWatchingProbeDirectory(probeDirectory);
    });
    probedHierarchies.stream().filter(newProbedHierarchy -> !oldProbedHierarchies.contains(newProbedHierarchy)).forEach(probedHierarchy -> {
        File probeDirectory = probeRegistry.getProbeDirectory(probedHierarchy);
        // Make sure the directory exists, this can be necessary when
        // included builds are evaluated with configuration cache
        // noinspection ResultOfMethodCallIgnored
        probeDirectory.mkdirs();
        startWatchingProbeDirectory(probeDirectory);
        probeRegistry.armWatchProbe(probedHierarchy);
    });
}
Also used : FileWatcherUpdater(org.gradle.internal.watch.registry.FileWatcherUpdater) ImmutableSet(com.google.common.collect.ImmutableSet) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) Logger(org.slf4j.Logger) WatchMode(org.gradle.internal.watch.registry.WatchMode) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Collection(java.util.Collection) FileMetadata(org.gradle.internal.file.FileMetadata) LoggerFactory(org.slf4j.LoggerFactory) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) File(java.io.File) CheckReturnValue(javax.annotation.CheckReturnValue) List(java.util.List) Stream(java.util.stream.Stream) FileWatcherProbeRegistry(org.gradle.internal.watch.registry.FileWatcherProbeRegistry) FileType(org.gradle.internal.file.FileType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) File(java.io.File)

Example 2 with FileHierarchySet

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

the class WatchableHierarchies method updateUnwatchableFilesOnBuildStart.

@CheckReturnValue
private SnapshotHierarchy updateUnwatchableFilesOnBuildStart(SnapshotHierarchy root, Invalidator invalidator, List<File> unsupportedFileSystems) {
    SnapshotHierarchy newRoot = root;
    FileHierarchySet oldUnwatchableFiles = unwatchableFiles;
    unwatchableFiles = unsupportedFileSystems.stream().reduce(FileHierarchySet.empty(), FileHierarchySet::plus, nonCombining());
    if (!oldUnwatchableFiles.equals(unwatchableFiles)) {
        // Remove previously unwatchable files, since they may become watchable.
        // If we register a watchable hierarchy, then there mustn't be anything in the VFS at that location.
        newRoot = invalidateUnwatchableHierarchies(newRoot, invalidator, oldUnwatchableFiles);
        // Remove current unwatchable files, since they still may be watched.
        newRoot = invalidateUnwatchableHierarchies(newRoot, invalidator, unwatchableFiles);
        hierarchies.removeIf(unwatchableFiles::contains);
        watchableFiles = buildWatchableFilesFromHierarchies(hierarchies);
        // Replay the watchable hierarchies since the end of last build, since they have become watchable.
        for (File watchableHierarchy : watchableHierarchiesSinceLastBuildFinish) {
            if (!unwatchableFiles.contains(watchableHierarchy)) {
                doRegisterWatchableHierarchy(watchableHierarchy, newRoot);
            }
        }
    }
    return newRoot;
}
Also used : SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) File(java.io.File) CheckReturnValue(javax.annotation.CheckReturnValue)

Aggregations

File (java.io.File)2 CheckReturnValue (javax.annotation.CheckReturnValue)2 FileHierarchySet (org.gradle.internal.file.FileHierarchySet)2 SnapshotHierarchy (org.gradle.internal.snapshot.SnapshotHierarchy)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 FileMetadata (org.gradle.internal.file.FileMetadata)1 FileType (org.gradle.internal.file.FileType)1 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)1 FileWatcherProbeRegistry (org.gradle.internal.watch.registry.FileWatcherProbeRegistry)1 FileWatcherUpdater (org.gradle.internal.watch.registry.FileWatcherUpdater)1 WatchMode (org.gradle.internal.watch.registry.WatchMode)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1