Search in sources :

Example 1 with BuildOperationContext

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

the class InProcessWorkerFactory method getWorker.

@Override
public Worker getWorker(Class<? extends WorkerProtocol> workerImplementationClass, File workingDir, final DaemonForkOptions forkOptions) {
    return new Worker() {

        @Override
        public <T extends WorkSpec> DefaultWorkResult execute(WorkerAction<T> action, T spec) {
            return execute(action, spec, buildOperationWorkerRegistry.getCurrent(), buildOperationExecutor.getCurrentOperation());
        }

        @Override
        public <T extends WorkSpec> DefaultWorkResult execute(final WorkerAction<T> action, final T spec, Operation parentWorkerOperation, BuildOperationExecutor.Operation parentBuildOperation) {
            BuildOperationWorkerRegistry.Completion workerLease = parentWorkerOperation.operationStart();
            BuildOperationDetails buildOperation = BuildOperationDetails.displayName(action.getDisplayName()).parent(parentBuildOperation).build();
            try {
                return buildOperationExecutor.run(buildOperation, new Transformer<DefaultWorkResult, BuildOperationContext>() {

                    @Override
                    public DefaultWorkResult transform(BuildOperationContext buildOperationContext) {
                        return executeInWorkerClassLoader(action, spec, forkOptions);
                    }
                });
            } finally {
                workerLease.operationFinish();
            }
        }
    };
}
Also used : BuildOperationDetails(org.gradle.internal.progress.BuildOperationDetails) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) BuildOperationWorkerRegistry(org.gradle.internal.operations.BuildOperationWorkerRegistry) Operation(org.gradle.internal.operations.BuildOperationWorkerRegistry.Operation)

Example 2 with BuildOperationContext

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

the class WorkerDaemonClient method execute.

@Override
public <T extends WorkSpec> DefaultWorkResult execute(final WorkerAction<T> action, final T spec, Operation parentWorkerOperation, BuildOperationExecutor.Operation parentBuildOperation) {
    Completion workerLease = parentWorkerOperation.operationStart();
    BuildOperationDetails buildOperation = BuildOperationDetails.displayName(action.getDisplayName()).parent(parentBuildOperation).build();
    try {
        return buildOperationExecutor.run(buildOperation, new Transformer<DefaultWorkResult, BuildOperationContext>() {

            @Override
            public DefaultWorkResult transform(BuildOperationContext buildOperationContext) {
                uses++;
                return workerDaemonProcess.execute(action, spec);
            }
        });
    } finally {
        workerLease.operationFinish();
    }
}
Also used : BuildOperationDetails(org.gradle.internal.progress.BuildOperationDetails) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Completion(org.gradle.internal.operations.BuildOperationWorkerRegistry.Completion)

Example 3 with BuildOperationContext

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

the class CleanupStaleOutputsExecuter method execute.

@Override
public void execute(final TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    final Set<File> filesToDelete = new HashSet<File>();
    TaskProperties taskProperties = context.getTaskProperties();
    for (TaskOutputFilePropertySpec outputFileSpec : taskProperties.getOutputFileProperties()) {
        FileCollection files = outputFileSpec.getPropertyFiles();
        for (File file : files) {
            if (cleanupRegistry.isOutputOwnedByBuild(file) && !taskOutputFilesRepository.isGeneratedByGradle(file) && file.exists()) {
                filesToDelete.add(file);
            }
        }
    }
    if (!filesToDelete.isEmpty()) {
        taskOutputChangesListener.beforeTaskOutputChanged();
        buildOperationExecutor.run(new RunnableBuildOperation() {

            @Override
            public void run(BuildOperationContext context) {
                for (File file : filesToDelete) {
                    if (file.exists()) {
                        logger.info("Deleting stale output file: {}", file.getAbsolutePath());
                        GFileUtils.forceDelete(file);
                    }
                }
            }

            @Override
            public BuildOperationDescriptor.Builder description() {
                return BuildOperationDescriptor.displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME).progressDisplayName("Cleaning stale outputs");
            }
        });
    }
    executer.execute(task, state, context);
}
Also used : TaskOutputFilePropertySpec(org.gradle.api.internal.tasks.TaskOutputFilePropertySpec) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) HashSet(java.util.HashSet)

Example 4 with BuildOperationContext

use of org.gradle.internal.operations.BuildOperationContext 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)

Example 5 with BuildOperationContext

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

the class RunAsBuildOperationBuildActionRunner method run.

@Override
public void run(final BuildAction action, final BuildController buildController) {
    BuildOperationExecutor buildOperationExecutor = buildController.getGradle().getServices().get(BuildOperationExecutor.class);
    buildOperationExecutor.run(new RunnableBuildOperation() {

        @Override
        public void run(BuildOperationContext context) {
            delegate.run(action, buildController);
            context.setResult(RESULT);
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName("Run build").details(DETAILS);
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor)

Aggregations

BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)20 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)12 File (java.io.File)8 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)5 Action (org.gradle.api.Action)3 BuildOperationExecutor (org.gradle.internal.operations.BuildOperationExecutor)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FileCollection (org.gradle.api.file.FileCollection)2 BuildOperationDetails (org.gradle.internal.progress.BuildOperationDetails)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Queues (com.google.common.collect.Queues)1 Sets (com.google.common.collect.Sets)1 Closure (groovy.lang.Closure)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1