use of org.gradle.execution.CancellableOperationManager 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;
}
Aggregations