use of org.gradle.internal.execution.DeferredExecutionHandler in project gradle by gradle.
the class DefaultTransformerInvocationFactory method createInvocation.
@Override
public CacheableInvocation<ImmutableList<File>> createInvocation(Transformer transformer, File inputArtifact, ArtifactTransformDependencies dependencies, TransformationSubject subject, InputFingerprinter inputFingerprinter) {
ProjectInternal producerProject = determineProducerProject(subject);
TransformationWorkspaceServices workspaceServices = determineWorkspaceServices(producerProject);
UnitOfWork execution;
if (producerProject == null) {
execution = new ImmutableTransformerExecution(transformer, inputArtifact, dependencies, buildOperationExecutor, fileCollectionFactory, inputFingerprinter, fileSystemAccess, workspaceServices);
} else {
execution = new MutableTransformerExecution(transformer, inputArtifact, dependencies, buildOperationExecutor, fileCollectionFactory, inputFingerprinter, workspaceServices);
}
return executionEngine.createRequest(execution).withIdentityCache(workspaceServices.getIdentityCache()).getOrDeferExecution(new DeferredExecutionHandler<TransformationResult, CacheableInvocation<ImmutableList<File>>>() {
@Override
public CacheableInvocation<ImmutableList<File>> processCachedOutput(Try<TransformationResult> cachedOutput) {
return CacheableInvocation.cached(mapResult(cachedOutput));
}
@Override
public CacheableInvocation<ImmutableList<File>> processDeferredOutput(Supplier<Try<TransformationResult>> deferredExecution) {
return CacheableInvocation.nonCached(() -> fireTransformListeners(transformer, subject, () -> mapResult(deferredExecution.get())));
}
@Nonnull
private Try<ImmutableList<File>> mapResult(Try<TransformationResult> cachedOutput) {
return cachedOutput.map(result -> result.resolveOutputsForInputArtifact(inputArtifact)).mapFailure(failure -> new TransformException(String.format("Execution failed for %s.", execution.getDisplayName()), failure));
}
});
}
Aggregations