Search in sources :

Example 1 with MultiCauseException

use of org.gradle.internal.exceptions.MultiCauseException 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)1 MultiCauseException (org.gradle.internal.exceptions.MultiCauseException)1 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)1 BuildOperationRef (org.gradle.internal.operations.BuildOperationRef)1 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)1