Search in sources :

Example 6 with ReportedException

use of org.gradle.initialization.ReportedException 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)

Example 7 with ReportedException

use of org.gradle.initialization.ReportedException in project gradle by gradle.

the class DaemonBuildActionExecuter method execute.

public Object execute(BuildAction action, BuildRequestContext buildRequestContext, ProviderOperationParameters parameters, ServiceRegistry contextServices) {
    boolean continuous = action.getStartParameter() != null && action.getStartParameter().isContinuous() && isNotBuildingModel(action);
    if (continuous && !doesConsumerSupportCancellation(buildRequestContext)) {
        throw new UnsupportedVersionException("Continuous build requires Tooling API client version 2.1 or later.");
    }
    ClassPath classPath = DefaultClassPath.of(parameters.getInjectedPluginClasspath(Collections.<File>emptyList()));
    BuildActionParameters actionParameters = new DefaultBuildActionParameters(daemonParameters.getEffectiveSystemProperties(), daemonParameters.getEnvironmentVariables(), SystemProperties.getInstance().getCurrentDir(), parameters.getBuildLogLevel(), daemonParameters.isEnabled(), continuous, false, classPath);
    try {
        return executer.execute(action, buildRequestContext, actionParameters, contextServices);
    } catch (ReportedException e) {
        Throwable t = e.getCause();
        // Unpack tunnelled test request failure
        if (t instanceof InternalTestExecutionException) {
            throw (InternalTestExecutionException) t;
        }
        while (t != null) {
            if (t instanceof BuildCancelledException) {
                throw new InternalBuildCancelledException(e.getCause());
            }
            t = t.getCause();
        }
        throw new BuildExceptionVersion1(e.getCause());
    }
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) BuildExceptionVersion1(org.gradle.tooling.internal.protocol.BuildExceptionVersion1) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException) File(java.io.File) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException) BuildCancelledException(org.gradle.api.BuildCancelledException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) ReportedException(org.gradle.initialization.ReportedException) InternalBuildCancelledException(org.gradle.tooling.internal.protocol.InternalBuildCancelledException)

Aggregations

ReportedException (org.gradle.initialization.ReportedException)7 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)3 BuildRequestContext (org.gradle.initialization.BuildRequestContext)2 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)2 ListenerManager (org.gradle.internal.event.ListenerManager)2 FileSystemChangeWaiter (org.gradle.internal.filewatch.FileSystemChangeWaiter)2 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)2 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)2 InternalTestExecutionException (org.gradle.tooling.internal.protocol.test.InternalTestExecutionException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildResult (org.gradle.BuildResult)1 BuildCancelledException (org.gradle.api.BuildCancelledException)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)1 TestExecutionException (org.gradle.api.tasks.testing.TestExecutionException)1 CommandLineParser (org.gradle.cli.CommandLineParser)1 CancellableOperationManager (org.gradle.execution.CancellableOperationManager)1 DefaultCancellableOperationManager (org.gradle.execution.DefaultCancellableOperationManager)1