Search in sources :

Example 1 with BuildSessionContext

use of org.gradle.internal.session.BuildSessionContext in project gradle by gradle.

the class BuildTreeLifecycleBuildActionExecutor method execute.

@Override
public BuildActionRunner.Result execute(BuildAction action, BuildSessionContext buildSession) {
    BuildActionRunner.Result result = null;
    try {
        buildLayoutValidator.validate(action.getStartParameter());
        BuildActionModelRequirements actionRequirements;
        if (action instanceof BuildModelAction && action.isCreateModel()) {
            BuildModelAction buildModelAction = (BuildModelAction) action;
            actionRequirements = new QueryModelRequirements(action.getStartParameter(), action.isRunTasks(), buildModelAction.getModelName());
        } else if (action instanceof ClientProvidedBuildAction) {
            actionRequirements = new RunActionRequirements(action.getStartParameter(), action.isRunTasks());
        } else if (action instanceof ClientProvidedPhasedAction) {
            actionRequirements = new RunPhasedActionRequirements(action.getStartParameter(), action.isRunTasks());
        } else {
            actionRequirements = new RunTasksRequirements(action.getStartParameter());
        }
        BuildTreeModelControllerServices.Supplier modelServices = buildTreeModelControllerServices.servicesForBuildTree(actionRequirements);
        BuildTreeState buildTree = new BuildTreeState(buildSession.getServices(), modelServices);
        try {
            result = buildTree.run(context -> context.execute(action));
        } finally {
            buildTree.close();
        }
    } catch (Throwable t) {
        if (result == null) {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(t);
        } else {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(result.addFailure(t).getBuildFailure());
        }
    }
    return result;
}
Also used : BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) BuildActionModelRequirements(org.gradle.internal.buildtree.BuildActionModelRequirements) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) ClientProvidedPhasedAction(org.gradle.tooling.internal.provider.action.ClientProvidedPhasedAction) BuildSessionActionExecutor(org.gradle.internal.session.BuildSessionActionExecutor) UncheckedException(org.gradle.internal.UncheckedException) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) BuildAction(org.gradle.internal.invocation.BuildAction) BuildSessionContext(org.gradle.internal.session.BuildSessionContext) BuildModelAction(org.gradle.tooling.internal.provider.action.BuildModelAction) BuildLayoutValidator(org.gradle.internal.build.BuildLayoutValidator) ClientProvidedPhasedAction(org.gradle.tooling.internal.provider.action.ClientProvidedPhasedAction) BuildActionModelRequirements(org.gradle.internal.buildtree.BuildActionModelRequirements) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) BuildActionRunner(org.gradle.internal.buildtree.BuildActionRunner) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) BuildModelAction(org.gradle.tooling.internal.provider.action.BuildModelAction)

Example 2 with BuildSessionContext

use of org.gradle.internal.session.BuildSessionContext 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)

Aggregations

BuildActionRunner (org.gradle.internal.buildtree.BuildActionRunner)2 BuildAction (org.gradle.internal.invocation.BuildAction)2 BuildSessionActionExecutor (org.gradle.internal.session.BuildSessionActionExecutor)2 BuildSessionContext (org.gradle.internal.session.BuildSessionContext)2 Supplier (java.util.function.Supplier)1 LogLevel (org.gradle.api.logging.LogLevel)1 ContinuousExecutionGate (org.gradle.deployment.internal.ContinuousExecutionGate)1 DefaultContinuousExecutionGate (org.gradle.deployment.internal.DefaultContinuousExecutionGate)1 Deployment (org.gradle.deployment.internal.Deployment)1 DeploymentInternal (org.gradle.deployment.internal.DeploymentInternal)1 DeploymentRegistryInternal (org.gradle.deployment.internal.DeploymentRegistryInternal)1 PendingChangesListener (org.gradle.deployment.internal.PendingChangesListener)1 CancellableOperationManager (org.gradle.execution.CancellableOperationManager)1 DefaultCancellableOperationManager (org.gradle.execution.DefaultCancellableOperationManager)1 PassThruCancellableOperationManager (org.gradle.execution.PassThruCancellableOperationManager)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 BuildRequestMetaData (org.gradle.initialization.BuildRequestMetaData)1 UncheckedException (org.gradle.internal.UncheckedException)1 BuildLayoutValidator (org.gradle.internal.build.BuildLayoutValidator)1 BuildStartedTime (org.gradle.internal.buildevents.BuildStartedTime)1