Search in sources :

Example 1 with PassThruCancellableOperationManager

use of org.gradle.execution.PassThruCancellableOperationManager 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)

Aggregations

CancellableOperationManager (org.gradle.execution.CancellableOperationManager)1 DefaultCancellableOperationManager (org.gradle.execution.DefaultCancellableOperationManager)1 PassThruCancellableOperationManager (org.gradle.execution.PassThruCancellableOperationManager)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 ReportedException (org.gradle.initialization.ReportedException)1 ChangeReporter (org.gradle.internal.filewatch.ChangeReporter)1 FileSystemChangeWaiter (org.gradle.internal.filewatch.FileSystemChangeWaiter)1 DisconnectableInputStream (org.gradle.util.DisconnectableInputStream)1