use of org.gradle.internal.Try 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));
}
});
}
use of org.gradle.internal.Try in project gradle by gradle.
the class TransformationStep method createInvocation.
public CacheableInvocation<TransformationSubject> createInvocation(TransformationSubject subjectToTransform, TransformUpstreamDependencies upstreamDependencies, @Nullable NodeExecutionContext context) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Transforming {} with {}", subjectToTransform.getDisplayName(), transformer.getDisplayName());
}
InputFingerprinter inputFingerprinter = context != null ? context.getService(InputFingerprinter.class) : globalInputFingerprinter;
Try<ArtifactTransformDependencies> resolvedDependencies = upstreamDependencies.computeArtifacts();
return resolvedDependencies.map(dependencies -> {
ImmutableList<File> inputArtifacts = subjectToTransform.getFiles();
if (inputArtifacts.isEmpty()) {
return CacheableInvocation.cached(Try.successful(subjectToTransform.createSubjectFromResult(ImmutableList.of())));
} else if (inputArtifacts.size() > 1) {
return CacheableInvocation.nonCached(() -> doTransform(subjectToTransform, inputFingerprinter, dependencies, inputArtifacts));
} else {
File inputArtifact = inputArtifacts.get(0);
return transformerInvocationFactory.createInvocation(transformer, inputArtifact, dependencies, subjectToTransform, inputFingerprinter).map(subjectToTransform::createSubjectFromResult);
}
}).getOrMapFailure(failure -> CacheableInvocation.cached(Try.failure(failure)));
}
use of org.gradle.internal.Try in project gradle by gradle.
the class ResolveCachingStateStep method execute.
@Override
public CachingResult execute(UnitOfWork work, C context) {
CachingState cachingState;
if (!buildCache.isEnabled() && !buildScansEnabled) {
cachingState = BUILD_CACHE_DISABLED_STATE;
} else if (context.getValidationProblems().isPresent()) {
cachingState = VALIDATION_FAILED_STATE;
} else {
cachingState = context.getBeforeExecutionState().map(beforeExecutionState -> calculateCachingState(work, beforeExecutionState)).orElseGet(() -> calculateCachingStateWithNoCapturedInputs(work));
}
cachingState.apply(enabled -> logCacheKey(enabled.getKey(), work), disabled -> logDisabledReasons(disabled.getDisabledReasons(), work));
UpToDateResult result = delegate.execute(work, new CachingContext() {
@Override
public CachingState getCachingState() {
return cachingState;
}
@Override
public Optional<String> getNonIncrementalReason() {
return context.getNonIncrementalReason();
}
@Override
public WorkValidationContext getValidationContext() {
return context.getValidationContext();
}
@Override
public ImmutableSortedMap<String, ValueSnapshot> getInputProperties() {
return context.getInputProperties();
}
@Override
public ImmutableSortedMap<String, CurrentFileCollectionFingerprint> getInputFileProperties() {
return context.getInputFileProperties();
}
@Override
public UnitOfWork.Identity getIdentity() {
return context.getIdentity();
}
@Override
public File getWorkspace() {
return context.getWorkspace();
}
@Override
public Optional<ExecutionHistoryStore> getHistory() {
return context.getHistory();
}
@Override
public Optional<PreviousExecutionState> getPreviousExecutionState() {
return context.getPreviousExecutionState();
}
@Override
public Optional<ValidationResult> getValidationProblems() {
return context.getValidationProblems();
}
@Override
public Optional<BeforeExecutionState> getBeforeExecutionState() {
return context.getBeforeExecutionState();
}
});
return new CachingResult() {
@Override
public CachingState getCachingState() {
return cachingState;
}
@Override
public ImmutableList<String> getExecutionReasons() {
return result.getExecutionReasons();
}
@Override
public Optional<AfterExecutionState> getAfterExecutionState() {
return result.getAfterExecutionState();
}
@Override
public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
return result.getReusedOutputOriginMetadata();
}
@Override
public Try<ExecutionResult> getExecutionResult() {
return result.getExecutionResult();
}
@Override
public Duration getDuration() {
return result.getDuration();
}
};
}
Aggregations