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();
}
}
};
}
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();
}
}
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);
}
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);
}
}
});
}
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);
}
});
}
Aggregations