Search in sources :

Example 1 with FileSystemChangeWaiter

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

the class ContinuousBuildActionExecuter method executeMultipleBuilds.

private Object executeMultipleBuilds(BuildAction action, BuildRequestContext requestContext, final BuildActionParameters actionParameters, ServiceRegistry buildSessionScopeServices) {
    SingleMessageLogger.incubatingFeatureUsed("Continuous build");
    BuildCancellationToken cancellationToken = requestContext.getCancellationToken();
    final CancellableOperationManager cancellableOperationManager;
    if (actionParameters.isInteractive()) {
        if (!(System.in instanceof DisconnectableInputStream)) {
            System.setIn(new DisconnectableInputStream(System.in));
        }
        DisconnectableInputStream inputStream = (DisconnectableInputStream) System.in;
        cancellableOperationManager = new DefaultCancellableOperationManager(executorFactory.create("cancel signal monitor"), inputStream, cancellationToken);
    } else {
        cancellableOperationManager = new PassThruCancellableOperationManager(cancellationToken);
    }
    Object lastResult = null;
    int counter = 0;
    while (!cancellationToken.isCancellationRequested()) {
        if (++counter != 1) {
            // reset the time the build started so the total time makes sense
            requestContext.getBuildTimeClock().reset();
            logger.println("Change detected, executing build...").println();
        }
        final FileSystemChangeWaiter waiter = changeWaiterFactory.createChangeWaiter(cancellationToken);
        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) {
                        ChangeReporter reporter = new ChangeReporter();
                        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();
        }
    }
    logger.println("Build cancelled.");
    if (lastResult instanceof ReportedException) {
        throw (ReportedException) lastResult;
    }
    return lastResult;
}
Also used : DisconnectableInputStream(org.gradle.util.DisconnectableInputStream) DefaultCancellableOperationManager(org.gradle.execution.DefaultCancellableOperationManager) PassThruCancellableOperationManager(org.gradle.execution.PassThruCancellableOperationManager) FileSystemChangeWaiter(org.gradle.internal.filewatch.FileSystemChangeWaiter) DefaultCancellableOperationManager(org.gradle.execution.DefaultCancellableOperationManager) PassThruCancellableOperationManager(org.gradle.execution.PassThruCancellableOperationManager) CancellableOperationManager(org.gradle.execution.CancellableOperationManager) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) ChangeReporter(org.gradle.internal.filewatch.ChangeReporter) ReportedException(org.gradle.initialization.ReportedException)

Example 2 with FileSystemChangeWaiter

use of org.gradle.internal.filewatch.FileSystemChangeWaiter 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)2 ReportedException (org.gradle.initialization.ReportedException)2 FileSystemChangeWaiter (org.gradle.internal.filewatch.FileSystemChangeWaiter)2 CancellableOperationManager (org.gradle.execution.CancellableOperationManager)1 DefaultCancellableOperationManager (org.gradle.execution.DefaultCancellableOperationManager)1 PassThruCancellableOperationManager (org.gradle.execution.PassThruCancellableOperationManager)1 BuildStartedTime (org.gradle.internal.buildevents.BuildStartedTime)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 ChangeReporter (org.gradle.internal.filewatch.ChangeReporter)1 DefaultFileWatcherEventListener (org.gradle.internal.filewatch.DefaultFileWatcherEventListener)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 DisconnectableInputStream (org.gradle.util.DisconnectableInputStream)1