Search in sources :

Example 6 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class ContinuousBuildActionExecutor method executeMultipleBuilds.

private BuildActionRunner.Result executeMultipleBuilds(BuildAction action, BuildRequestMetaData requestContext, BuildSessionContext buildSession, BuildCancellationToken cancellationToken, CancellableOperationManager cancellableOperationManager, ContinuousExecutionGate continuousExecutionGate) {
    BuildActionRunner.Result lastResult;
    PendingChangesListener pendingChangesListener = listenerManager.getBroadcaster(PendingChangesListener.class);
    while (true) {
        BuildInputHierarchy buildInputs = new BuildInputHierarchy(caseSensitivity, stat);
        ContinuousBuildTriggerHandler continuousBuildTriggerHandler = new ContinuousBuildTriggerHandler(cancellationToken, continuousExecutionGate, action.getStartParameter().getContinuousBuildQuietPeriod());
        SingleFirePendingChangesListener singleFirePendingChangesListener = new SingleFirePendingChangesListener(pendingChangesListener);
        FileEventCollector fileEventCollector = new FileEventCollector(buildInputs, () -> {
            continuousBuildTriggerHandler.notifyFileChangeArrived();
            singleFirePendingChangesListener.onPendingChanges();
        });
        try {
            fileChangeListeners.addListener(fileEventCollector);
            lastResult = executeBuildAndAccumulateInputs(action, new AccumulateBuildInputsListener(buildInputs), buildSession);
            if (buildInputs.isEmpty()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as Gradle did not detect any file system inputs.");
                return lastResult;
            } else if (!continuousBuildTriggerHandler.hasBeenTriggered() && !fileSystemWatchingInformation.isWatchingAnyLocations()) {
                logger.println().withStyle(StyledTextOutput.Style.Failure).println("Exiting continuous build as Gradle does not watch any file system locations.");
                return lastResult;
            } else {
                cancellableOperationManager.monitorInput(operationToken -> {
                    continuousBuildTriggerHandler.wait(() -> logger.println().println("Waiting for changes to input files..." + determineExitHint(requestContext)));
                    if (!operationToken.isCancellationRequested()) {
                        fileEventCollector.reportChanges(logger);
                    }
                });
            }
        } finally {
            fileChangeListeners.removeListener(fileEventCollector);
        }
        if (cancellationToken.isCancellationRequested()) {
            break;
        } else {
            logger.println("Change detected, executing build...").println();
            resetBuildStartedTime();
        }
    }
    logger.println("Build cancelled.");
    return lastResult;
}
Also used : DefaultCancellableOperationManager(org.gradle.execution.DefaultCancellableOperationManager) BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) ExecutorFactory(org.gradle.internal.concurrent.ExecutorFactory) Supplier(java.util.function.Supplier) DeploymentRegistryInternal(org.gradle.deployment.internal.DeploymentRegistryInternal) BuildSessionActionExecutor(org.gradle.internal.session.BuildSessionActionExecutor) WorkInputListeners(org.gradle.internal.execution.WorkInputListeners) ContinuousExecutionGate(org.gradle.deployment.internal.ContinuousExecutionGate) Clock(org.gradle.internal.time.Clock) WorkInputListener(org.gradle.internal.execution.WorkInputListener) DisconnectableInputStream(org.gradle.util.internal.DisconnectableInputStream) PassThruCancellableOperationManager(org.gradle.execution.PassThruCancellableOperationManager) Deployment(org.gradle.deployment.internal.Deployment) CancellableOperationManager(org.gradle.execution.CancellableOperationManager) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) LogLevel(org.gradle.api.logging.LogLevel) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) ListenerManager(org.gradle.internal.event.ListenerManager) CaseSensitivity(org.gradle.internal.snapshot.CaseSensitivity) Stat(org.gradle.internal.file.Stat) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) FileSystemWatchingInformation(org.gradle.internal.watch.vfs.FileSystemWatchingInformation) DeploymentInternal(org.gradle.deployment.internal.DeploymentInternal) OperatingSystem(org.gradle.internal.os.OperatingSystem) DefaultContinuousExecutionGate(org.gradle.deployment.internal.DefaultContinuousExecutionGate) FileChangeListeners(org.gradle.internal.watch.vfs.FileChangeListeners) PendingChangesListener(org.gradle.deployment.internal.PendingChangesListener) BuildAction(org.gradle.internal.invocation.BuildAction) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) BuildSessionContext(org.gradle.internal.session.BuildSessionContext) StyledTextOutputFactory(org.gradle.internal.logging.text.StyledTextOutputFactory) PendingChangesListener(org.gradle.deployment.internal.PendingChangesListener) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner)

Example 7 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class ProviderConnection method runPhasedAction.

public Object runPhasedAction(InternalPhasedAction clientPhasedAction, PhasedActionResultListener resultListener, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    SerializedPayload serializedAction = payloadSerializer.serialize(clientPhasedAction);
    Parameters params = initParams(providerParameters);
    StartParameterInternal startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.buildLayout, params.properties);
    FailsafePhasedActionResultListener failsafePhasedActionResultListener = new FailsafePhasedActionResultListener(resultListener);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters, consumerVersion);
    BuildAction action = new ClientProvidedPhasedAction(startParameter, serializedAction, tasks != null, listenerConfig.clientSubscriptions);
    try {
        return run(action, cancellationToken, listenerConfig, new PhasedActionEventConsumer(failsafePhasedActionResultListener, payloadSerializer, listenerConfig.buildEventConsumer), providerParameters, params);
    } finally {
        failsafePhasedActionResultListener.rethrowErrors();
    }
}
Also used : SerializedPayload(org.gradle.tooling.internal.provider.serialization.SerializedPayload) ClientProvidedPhasedAction(org.gradle.tooling.internal.provider.action.ClientProvidedPhasedAction) ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction)

Example 8 with BuildAction

use of org.gradle.internal.invocation.BuildAction in project gradle by gradle.

the class ProviderConnection method run.

public Object run(String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) {
        throw new IllegalArgumentException("No model type or tasks specified.");
    }
    Parameters params = initParams(providerParameters);
    if (BuildEnvironment.class.getName().equals(modelName)) {
        // we don't really need to launch the daemon to acquire information needed for BuildEnvironment
        if (tasks != null) {
            throw new IllegalArgumentException("Cannot run tasks and fetch the build environment model.");
        }
        return new DefaultBuildEnvironment(new DefaultBuildIdentifier(providerParameters.getProjectDir()), params.buildLayout.getGradleUserHomeDir(), GradleVersion.current().getVersion(), params.daemonParams.getEffectiveJvm().getJavaHome(), params.daemonParams.getEffectiveJvmArgs());
    }
    StartParameterInternal startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.buildLayout, params.properties);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters, consumerVersion);
    BuildAction action = new BuildModelAction(startParameter, modelName, tasks != null, listenerConfig.clientSubscriptions);
    return run(action, cancellationToken, listenerConfig, listenerConfig.buildEventConsumer, providerParameters, params);
}
Also used : DefaultBuildEnvironment(org.gradle.tooling.internal.build.DefaultBuildEnvironment) ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DefaultBuildIdentifier(org.gradle.tooling.internal.gradle.DefaultBuildIdentifier) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) DefaultBuildEnvironment(org.gradle.tooling.internal.build.DefaultBuildEnvironment) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) BuildModelAction(org.gradle.tooling.internal.provider.action.BuildModelAction)

Aggregations

BuildAction (org.gradle.internal.invocation.BuildAction)8 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)6 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)5 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)4 ClientProvidedBuildAction (org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction)4 ProviderConnectionParameters (org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters)4 ProviderOperationParameters (org.gradle.tooling.internal.provider.connection.ProviderOperationParameters)4 ListenerManager (org.gradle.internal.event.ListenerManager)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BuildResult (org.gradle.BuildResult)2 CommandLineParser (org.gradle.cli.CommandLineParser)2 BuildRequestContext (org.gradle.initialization.BuildRequestContext)2 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)2 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)2 BuildActionRunner (org.gradle.internal.buildtree.BuildActionRunner)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 BuildSessionActionExecutor (org.gradle.internal.session.BuildSessionActionExecutor)2 SerializedPayload (org.gradle.tooling.internal.provider.serialization.SerializedPayload)2 Supplier (java.util.function.Supplier)1