use of org.gradle.internal.filewatch.FileWatcherEventListener 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;
}
Aggregations