Search in sources :

Example 1 with Operation

use of org.gradle.internal.operations.BuildOperationWorkerRegistry.Operation in project gradle by gradle.

the class DefaultWorkerExecutor method submit.

private void submit(final WorkerAction action, final Serializable[] params, final File workingDir, final ForkMode fork, final DaemonForkOptions daemonForkOptions) {
    final Operation currentWorkerOperation = buildOperationWorkerRegistry.getCurrent();
    final BuildOperationExecutor.Operation currentBuildOperation = buildOperationExecutor.getCurrentOperation();
    ListenableFuture<DefaultWorkResult> workerDaemonResult = executor.submit(new Callable<DefaultWorkResult>() {

        @Override
        public DefaultWorkResult call() throws Exception {
            try {
                WorkSpec spec = new ParamSpec(params);
                WorkerFactory workerFactory = fork == ForkMode.ALWAYS ? workerDaemonFactory : workerInProcessFactory;
                Worker worker = workerFactory.getWorker(workerProtocolImplementationClass, workingDir, daemonForkOptions);
                return worker.execute(action, spec, currentWorkerOperation, currentBuildOperation);
            } catch (Throwable t) {
                throw new WorkExecutionException(action.getDisplayName(), t);
            }
        }
    });
    registerAsyncWork(action.getDisplayName(), workerDaemonResult);
}
Also used : Operation(org.gradle.internal.operations.BuildOperationWorkerRegistry.Operation) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) WorkerExecutionException(org.gradle.workers.WorkerExecutionException) UncheckedException(org.gradle.internal.UncheckedException) ExecutionException(java.util.concurrent.ExecutionException) BuildOperationExecutor(org.gradle.internal.progress.BuildOperationExecutor)

Example 2 with Operation

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

Aggregations

Operation (org.gradle.internal.operations.BuildOperationWorkerRegistry.Operation)2 ExecutionException (java.util.concurrent.ExecutionException)1 UncheckedException (org.gradle.internal.UncheckedException)1 DefaultMultiCauseException (org.gradle.internal.exceptions.DefaultMultiCauseException)1 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)1 BuildOperationWorkerRegistry (org.gradle.internal.operations.BuildOperationWorkerRegistry)1 BuildOperationDetails (org.gradle.internal.progress.BuildOperationDetails)1 BuildOperationExecutor (org.gradle.internal.progress.BuildOperationExecutor)1 WorkerExecutionException (org.gradle.workers.WorkerExecutionException)1