Search in sources :

Example 1 with BuildOperationRef

use of org.gradle.internal.operations.BuildOperationRef in project gradle by gradle.

the class DefaultWorkerExecutor method submit.

private void submit(final ActionExecutionSpec spec, final IsolationMode isolationMode, final DaemonForkOptions daemonForkOptions) {
    final WorkerLease currentWorkerWorkerLease = getCurrentWorkerLease();
    final BuildOperationRef currentBuildOperation = buildOperationExecutor.getCurrentOperation();
    ListenableFuture<DefaultWorkResult> workerDaemonResult = executor.submit(new Callable<DefaultWorkResult>() {

        @Override
        public DefaultWorkResult call() throws Exception {
            try {
                WorkerFactory workerFactory = getWorkerFactory(isolationMode);
                Worker worker = workerFactory.getWorker(daemonForkOptions);
                return worker.execute(spec, currentWorkerWorkerLease, currentBuildOperation);
            } catch (Throwable t) {
                throw new WorkExecutionException(spec.getDisplayName(), t);
            }
        }
    });
    registerAsyncWork(spec.getDisplayName(), workerDaemonResult);
}
Also used : BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) WorkerLease(org.gradle.internal.work.WorkerLeaseRegistry.WorkerLease) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) WorkerExecutionException(org.gradle.workers.WorkerExecutionException) UncheckedException(org.gradle.internal.UncheckedException) NoAvailableWorkerLeaseException(org.gradle.internal.work.NoAvailableWorkerLeaseException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BuildOperationRef

use of org.gradle.internal.operations.BuildOperationRef in project gradle by gradle.

the class ExecuteActionsTaskExecuter method executeAction.

private void executeAction(final String actionDisplayName, final TaskInternal task, final ContextAwareTaskAction action, TaskExecutionContext context) {
    action.contextualise(context);
    buildOperationExecutor.run(new RunnableBuildOperation() {

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName(actionDisplayName + " for " + task.getPath()).name(actionDisplayName);
        }

        @Override
        public void run(BuildOperationContext context) {
            BuildOperationRef currentOperation = buildOperationExecutor.getCurrentOperation();
            Throwable actionFailure = null;
            try {
                action.execute(task);
            } catch (Throwable t) {
                actionFailure = t;
            } finally {
                action.releaseContext();
            }
            try {
                asyncWorkTracker.waitForCompletion(currentOperation, true);
            } catch (Throwable t) {
                List<Throwable> failures = Lists.newArrayList();
                if (actionFailure != null) {
                    failures.add(actionFailure);
                }
                if (t instanceof MultiCauseException) {
                    failures.addAll(((MultiCauseException) t).getCauses());
                } else {
                    failures.add(t);
                }
                if (failures.size() > 1) {
                    throw new MultipleTaskActionFailures("Multiple task action failures occurred:", failures);
                } else {
                    throw UncheckedException.throwAsUncheckedException(failures.get(0));
                }
            }
            if (actionFailure != null) {
                throw UncheckedException.throwAsUncheckedException(actionFailure);
            }
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) MultiCauseException(org.gradle.internal.exceptions.MultiCauseException) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Aggregations

DefaultMultiCauseException (org.gradle.internal.exceptions.DefaultMultiCauseException)2 BuildOperationRef (org.gradle.internal.operations.BuildOperationRef)2 ExecutionException (java.util.concurrent.ExecutionException)1 UncheckedException (org.gradle.internal.UncheckedException)1 MultiCauseException (org.gradle.internal.exceptions.MultiCauseException)1 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)1 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)1 NoAvailableWorkerLeaseException (org.gradle.internal.work.NoAvailableWorkerLeaseException)1 WorkerLease (org.gradle.internal.work.WorkerLeaseRegistry.WorkerLease)1 WorkerExecutionException (org.gradle.workers.WorkerExecutionException)1