Search in sources :

Example 1 with FileSystemWatchingStatistics

use of org.gradle.internal.watch.vfs.FileSystemWatchingStatistics in project gradle by gradle.

the class WatchingVirtualFileSystem method beforeBuildFinished.

@Override
public void beforeBuildFinished(WatchMode watchMode, VfsLogging vfsLogging, WatchLogging watchLogging, BuildOperationRunner buildOperationRunner, int maximumNumberOfWatchedHierarchies) {
    rootReference.update(currentRoot -> buildOperationRunner.call(new CallableBuildOperation<SnapshotHierarchy>() {

        @Override
        public SnapshotHierarchy call(BuildOperationContext context) {
            watchableHierarchiesRegisteredEarly.clear();
            if (watchMode.isEnabled()) {
                if (reasonForNotWatchingFiles != null) {
                    // Log exception again so it doesn't get lost.
                    logWatchingError(reasonForNotWatchingFiles, FILE_WATCHING_ERROR_MESSAGE_AT_END_OF_BUILD, watchMode);
                    reasonForNotWatchingFiles = null;
                }
                SnapshotHierarchy newRoot;
                FileSystemWatchingStatistics statisticsDuringBuild;
                if (watchRegistry == null) {
                    statisticsDuringBuild = null;
                    newRoot = currentRoot.empty();
                } else {
                    FileWatcherRegistry.FileWatchingStatistics statistics = watchRegistry.getAndResetStatistics();
                    if (hasDroppedStateBecauseOfErrorsReceivedWhileWatching(statistics)) {
                        newRoot = stopWatchingAndInvalidateHierarchyAfterError(currentRoot);
                    } else {
                        newRoot = withWatcherChangeErrorHandling(currentRoot, () -> watchRegistry.updateVfsOnBuildFinished(currentRoot, watchMode, maximumNumberOfWatchedHierarchies, unsupportedFileSystems));
                    }
                    statisticsDuringBuild = new DefaultFileSystemWatchingStatistics(statistics, newRoot);
                    if (vfsLogging == VfsLogging.VERBOSE) {
                        LOGGER.warn("Received {} file system events during the current build while watching {} locations", statisticsDuringBuild.getNumberOfReceivedEvents(), statisticsDuringBuild.getNumberOfWatchedHierarchies());
                        LOGGER.warn("Virtual file system retains information about {} files, {} directories and {} missing files until next build", statisticsDuringBuild.getRetainedRegularFiles(), statisticsDuringBuild.getRetainedDirectories(), statisticsDuringBuild.getRetainedMissingFiles());
                        if (stateInvalidatedAtStartOfBuild) {
                            LOGGER.warn("Parts of the virtual file system have been removed at the start of the build since they didn't support watching");
                        }
                    }
                }
                boolean stoppedWatchingDuringTheBuild = watchRegistry == null;
                context.setResult(new BuildFinishedFileSystemWatchingBuildOperationType.Result() {

                    private final boolean stateInvalidatedAtStartOfBuild = WatchingVirtualFileSystem.this.stateInvalidatedAtStartOfBuild;

                    @Override
                    public boolean isWatchingEnabled() {
                        return true;
                    }

                    @Override
                    public boolean isStoppedWatchingDuringTheBuild() {
                        return stoppedWatchingDuringTheBuild;
                    }

                    @Override
                    public boolean isStateInvalidatedAtStartOfBuild() {
                        return stateInvalidatedAtStartOfBuild;
                    }

                    @Override
                    public FileSystemWatchingStatistics getStatistics() {
                        return statisticsDuringBuild;
                    }
                });
                return newRoot;
            } else {
                context.setResult(BuildFinishedFileSystemWatchingBuildOperationType.Result.WATCHING_DISABLED);
                return currentRoot.empty();
            }
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName(BuildFinishedFileSystemWatchingBuildOperationType.DISPLAY_NAME).details(BuildFinishedFileSystemWatchingBuildOperationType.Details.INSTANCE);
        }
    }));
    // Log problems to daemon log
    warningLogger = LOGGER;
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileSystemWatchingStatistics(org.gradle.internal.watch.vfs.FileSystemWatchingStatistics) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) BuildFinishedFileSystemWatchingBuildOperationType(org.gradle.internal.watch.vfs.BuildFinishedFileSystemWatchingBuildOperationType) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) CallableBuildOperation(org.gradle.internal.operations.CallableBuildOperation) FileWatcherRegistry(org.gradle.internal.watch.registry.FileWatcherRegistry)

Example 2 with FileSystemWatchingStatistics

use of org.gradle.internal.watch.vfs.FileSystemWatchingStatistics in project gradle by gradle.

the class WatchingVirtualFileSystem method afterBuildStarted.

@Override
public boolean afterBuildStarted(WatchMode watchMode, VfsLogging vfsLogging, WatchLogging watchLogging, BuildOperationRunner buildOperationRunner) {
    warningLogger = watchMode.loggerForWarnings(LOGGER);
    stateInvalidatedAtStartOfBuild = false;
    reasonForNotWatchingFiles = null;
    rootReference.update(currentRoot -> buildOperationRunner.call(new CallableBuildOperation<SnapshotHierarchy>() {

        @Override
        public SnapshotHierarchy call(BuildOperationContext context) {
            if (watchMode.isEnabled()) {
                SnapshotHierarchy newRoot;
                boolean couldDetectUnsupportedFileSystems;
                try {
                    unsupportedFileSystems.clear();
                    if (watchMode == WatchMode.DEFAULT) {
                        watchableFileSystemDetector.detectUnsupportedFileSystems().forEach(unsupportedFileSystems::add);
                    }
                    couldDetectUnsupportedFileSystems = true;
                } catch (NativeException e) {
                    couldDetectUnsupportedFileSystems = false;
                    LOGGER.info("Unable to list file systems to check whether they can be watched. Disabling watching. Reason: {}", e.getMessage());
                }
                FileSystemWatchingStatistics statisticsSinceLastBuild;
                if (watchRegistry == null) {
                    if (couldDetectUnsupportedFileSystems) {
                        context.setStatus("Starting file system watching");
                        newRoot = startWatching(currentRoot, watchMode, unsupportedFileSystems);
                    } else {
                        newRoot = currentRoot.empty();
                    }
                    statisticsSinceLastBuild = null;
                } else {
                    FileWatcherRegistry.FileWatchingStatistics statistics = watchRegistry.getAndResetStatistics();
                    if (hasDroppedStateBecauseOfErrorsReceivedWhileWatching(statistics) || !couldDetectUnsupportedFileSystems) {
                        newRoot = stopWatchingAndInvalidateHierarchyAfterError(currentRoot);
                    } else {
                        newRoot = watchRegistry.updateVfsOnBuildStarted(currentRoot, watchMode, unsupportedFileSystems);
                    }
                    stateInvalidatedAtStartOfBuild = newRoot != currentRoot;
                    statisticsSinceLastBuild = new DefaultFileSystemWatchingStatistics(statistics, newRoot);
                    if (vfsLogging == VfsLogging.VERBOSE) {
                        LOGGER.warn("Received {} file system events since last build while watching {} locations", statisticsSinceLastBuild.getNumberOfReceivedEvents(), statisticsSinceLastBuild.getNumberOfWatchedHierarchies());
                        LOGGER.warn("Virtual file system retained information about {} files, {} directories and {} missing files since last build", statisticsSinceLastBuild.getRetainedRegularFiles(), statisticsSinceLastBuild.getRetainedDirectories(), statisticsSinceLastBuild.getRetainedMissingFiles());
                        if (stateInvalidatedAtStartOfBuild) {
                            LOGGER.warn("Parts of the virtual file system have been invalidated since they didn't support watching");
                        }
                    }
                }
                if (watchRegistry != null) {
                    watchRegistry.setDebugLoggingEnabled(watchLogging == WatchLogging.DEBUG);
                }
                context.setResult(new BuildStartedFileSystemWatchingBuildOperationType.Result() {

                    @Override
                    public boolean isWatchingEnabled() {
                        return true;
                    }

                    @Override
                    public boolean isStartedWatching() {
                        return statisticsSinceLastBuild == null;
                    }

                    @Override
                    public FileSystemWatchingStatistics getStatistics() {
                        return statisticsSinceLastBuild;
                    }
                });
                return newRoot;
            } else {
                context.setResult(BuildStartedFileSystemWatchingBuildOperationType.Result.WATCHING_DISABLED);
                return stopWatchingAndInvalidateHierarchy(currentRoot);
            }
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName(BuildStartedFileSystemWatchingBuildOperationType.DISPLAY_NAME).details(BuildStartedFileSystemWatchingBuildOperationType.Details.INSTANCE);
        }
    }));
    return watchRegistry != null;
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileSystemWatchingStatistics(org.gradle.internal.watch.vfs.FileSystemWatchingStatistics) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) BuildStartedFileSystemWatchingBuildOperationType(org.gradle.internal.watch.vfs.BuildStartedFileSystemWatchingBuildOperationType) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) CallableBuildOperation(org.gradle.internal.operations.CallableBuildOperation) FileWatcherRegistry(org.gradle.internal.watch.registry.FileWatcherRegistry) NativeException(net.rubygrapefruit.platform.NativeException)

Aggregations

BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)2 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)2 CallableBuildOperation (org.gradle.internal.operations.CallableBuildOperation)2 SnapshotHierarchy (org.gradle.internal.snapshot.SnapshotHierarchy)2 FileWatcherRegistry (org.gradle.internal.watch.registry.FileWatcherRegistry)2 FileSystemWatchingStatistics (org.gradle.internal.watch.vfs.FileSystemWatchingStatistics)2 NativeException (net.rubygrapefruit.platform.NativeException)1 BuildFinishedFileSystemWatchingBuildOperationType (org.gradle.internal.watch.vfs.BuildFinishedFileSystemWatchingBuildOperationType)1 BuildStartedFileSystemWatchingBuildOperationType (org.gradle.internal.watch.vfs.BuildStartedFileSystemWatchingBuildOperationType)1