Search in sources :

Example 1 with DefaultFileWatcherEventListener

use of org.gradle.internal.filewatch.DefaultFileWatcherEventListener in project gradle by gradle.

the class ContinuousBuildActionExecuter method executeMultipleBuilds.

private Object executeMultipleBuilds(BuildAction action, BuildRequestContext requestContext, final BuildActionParameters actionParameters, final ServiceRegistry buildSessionScopeServices, CancellableOperationManager cancellableOperationManager, ContinuousExecutionGate continuousExecutionGate) {
    BuildCancellationToken cancellationToken = requestContext.getCancellationToken();
    BuildStartedTime buildStartedTime = buildSessionScopeServices.get(BuildStartedTime.class);
    Clock clock = buildSessionScopeServices.get(Clock.class);
    Object lastResult;
    while (true) {
        PendingChangesListener pendingChangesListener = buildSessionScopeServices.get(ListenerManager.class).getBroadcaster(PendingChangesListener.class);
        final FileSystemChangeWaiter waiter = changeWaiterFactory.createChangeWaiter(new SingleFirePendingChangesListener(pendingChangesListener), cancellationToken, continuousExecutionGate);
        try {
            try {
                lastResult = executeBuildAndAccumulateInputs(action, requestContext, actionParameters, waiter, buildSessionScopeServices);
            } catch (ReportedException t) {
                lastResult = t;
            }
            if (!waiter.isWatching()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as no executed tasks declared file system inputs.");
                if (lastResult instanceof ReportedException) {
                    throw (ReportedException) lastResult;
                }
                return lastResult;
            } else {
                cancellableOperationManager.monitorInput(new Action<BuildCancellationToken>() {

                    @Override
                    public void execute(BuildCancellationToken cancellationToken) {
                        FileWatcherEventListener reporter = new DefaultFileWatcherEventListener();
                        waiter.wait(new Runnable() {

                            @Override
                            public void run() {
                                logger.println().println("Waiting for changes to input files of tasks..." + determineExitHint(actionParameters));
                            }
                        }, reporter);
                        if (!cancellationToken.isCancellationRequested()) {
                            reporter.reportChanges(logger);
                        }
                    }
                });
            }
        } finally {
            waiter.stop();
        }
        if (cancellationToken.isCancellationRequested()) {
            break;
        } else {
            logger.println("Change detected, executing build...").println();
            buildStartedTime.reset(clock.getCurrentTime());
        }
    }
    logger.println("Build cancelled.");
    if (lastResult instanceof ReportedException) {
        throw (ReportedException) lastResult;
    }
    return lastResult;
}
Also used : FileWatcherEventListener(org.gradle.internal.filewatch.FileWatcherEventListener) DefaultFileWatcherEventListener(org.gradle.internal.filewatch.DefaultFileWatcherEventListener) DefaultFileWatcherEventListener(org.gradle.internal.filewatch.DefaultFileWatcherEventListener) Clock(org.gradle.internal.time.Clock) SingleFirePendingChangesListener(org.gradle.internal.filewatch.SingleFirePendingChangesListener) PendingChangesListener(org.gradle.internal.filewatch.PendingChangesListener) SingleFirePendingChangesListener(org.gradle.internal.filewatch.SingleFirePendingChangesListener) FileSystemChangeWaiter(org.gradle.internal.filewatch.FileSystemChangeWaiter) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Aggregations

BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 ReportedException (org.gradle.initialization.ReportedException)1 BuildStartedTime (org.gradle.internal.buildevents.BuildStartedTime)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 DefaultFileWatcherEventListener (org.gradle.internal.filewatch.DefaultFileWatcherEventListener)1 FileSystemChangeWaiter (org.gradle.internal.filewatch.FileSystemChangeWaiter)1 FileWatcherEventListener (org.gradle.internal.filewatch.FileWatcherEventListener)1 PendingChangesListener (org.gradle.internal.filewatch.PendingChangesListener)1 SingleFirePendingChangesListener (org.gradle.internal.filewatch.SingleFirePendingChangesListener)1 Clock (org.gradle.internal.time.Clock)1