use of org.gradle.internal.execution.UnitOfWork 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.execution.UnitOfWork in project gradle by gradle.
the class RemovePreviousOutputsStep method cleanupOverlappingOutputs.
private void cleanupOverlappingOutputs(BeforeExecutionContext context, UnitOfWork work) {
context.getPreviousExecutionState().ifPresent(previousOutputs -> {
Set<File> outputDirectoriesToPreserve = new HashSet<>();
work.visitOutputs(context.getWorkspace(), new UnitOfWork.OutputVisitor() {
@Override
public void visitOutputProperty(String propertyName, TreeType type, File root, FileCollection contents) {
switch(type) {
case FILE:
File parentFile = root.getParentFile();
if (parentFile != null) {
outputDirectoriesToPreserve.add(parentFile);
}
break;
case DIRECTORY:
outputDirectoriesToPreserve.add(root);
break;
default:
throw new AssertionError();
}
}
});
OutputsCleaner cleaner = new OutputsCleaner(deleter, file -> true, dir -> !outputDirectoriesToPreserve.contains(dir));
for (FileSystemSnapshot snapshot : previousOutputs.getOutputFilesProducedByWork().values()) {
try {
// Previous outputs can be in a different place than the current outputs
outputChangeListener.beforeOutputChange(SnapshotUtil.rootIndex(snapshot).keySet());
cleaner.cleanupOutputs(snapshot);
} catch (IOException e) {
throw new UncheckedIOException("Failed to clean up output files for " + work.getDisplayName(), e);
}
}
});
}
use of org.gradle.internal.execution.UnitOfWork 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();
}
};
}
use of org.gradle.internal.execution.UnitOfWork in project gradle by gradle.
the class ValidateStep method validateImplementations.
private void validateImplementations(UnitOfWork work, BeforeExecutionState beforeExecutionState, WorkValidationContext validationContext) {
MutableReference<Class<?>> workClass = MutableReference.empty();
work.visitImplementations(new UnitOfWork.ImplementationVisitor() {
@Override
public void visitImplementation(Class<?> implementation) {
workClass.set(GeneratedSubclasses.unpack(implementation));
}
@Override
public void visitImplementation(ImplementationSnapshot implementation) {
}
});
// It doesn't matter whether we use cacheable true or false, since none of the warnings depends on the cacheability of the task.
Class<?> workType = workClass.get();
TypeValidationContext workValidationContext = validationContext.forType(workType, true);
validateImplementation(workValidationContext, beforeExecutionState.getImplementation(), "Implementation of ", work);
beforeExecutionState.getAdditionalImplementations().forEach(additionalImplementation -> validateImplementation(workValidationContext, additionalImplementation, "Additional action of ", work));
beforeExecutionState.getInputProperties().forEach((propertyName, valueSnapshot) -> {
if (valueSnapshot instanceof ImplementationSnapshot) {
ImplementationSnapshot implementationSnapshot = (ImplementationSnapshot) valueSnapshot;
validateNestedInput(workValidationContext, propertyName, implementationSnapshot);
}
});
}
use of org.gradle.internal.execution.UnitOfWork in project gradle by gradle.
the class ValidateStep method execute.
@Override
public R execute(UnitOfWork work, C context) {
WorkValidationContext validationContext = context.getValidationContext();
work.validate(validationContext);
context.getBeforeExecutionState().ifPresent(beforeExecutionState -> validateImplementations(work, beforeExecutionState, validationContext));
Map<Severity, List<String>> problems = validationContext.getProblems().stream().collect(groupingBy(BaseProblem::getSeverity, mapping(ValidateStep::renderedMessage, toList())));
ImmutableCollection<String> warnings = ImmutableList.copyOf(problems.getOrDefault(Severity.WARNING, ImmutableList.of()));
ImmutableCollection<String> errors = ImmutableList.copyOf(problems.getOrDefault(Severity.ERROR, ImmutableList.of()));
if (!warnings.isEmpty()) {
warningReporter.recordValidationWarnings(work, warnings);
}
if (!errors.isEmpty()) {
int maxErrCount = Integer.getInteger(MAX_NB_OF_ERRORS, 5);
ImmutableSortedSet<String> uniqueSortedErrors = ImmutableSortedSet.copyOf(errors);
throw WorkValidationException.forProblems(uniqueSortedErrors).limitTo(maxErrCount).withSummary(helper -> String.format("%s found with the configuration of %s (%s).", helper.size() == 1 ? "A problem was" : "Some problems were", work.getDisplayName(), describeTypesChecked(validationContext.getValidatedTypes()))).get();
}
if (!warnings.isEmpty()) {
LOGGER.info("Invalidating VFS because {} failed validation", work.getDisplayName());
virtualFileSystem.invalidateAll();
}
return delegate.execute(work, new ValidationFinishedContext() {
@Override
public Optional<BeforeExecutionState> getBeforeExecutionState() {
return context.getBeforeExecutionState();
}
@Override
public Optional<ValidationResult> getValidationProblems() {
return warnings.isEmpty() ? Optional.empty() : Optional.of(() -> warnings);
}
@Override
public Optional<PreviousExecutionState> getPreviousExecutionState() {
return context.getPreviousExecutionState();
}
@Override
public File getWorkspace() {
return context.getWorkspace();
}
@Override
public Optional<ExecutionHistoryStore> getHistory() {
return context.getHistory();
}
@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 Optional<String> getNonIncrementalReason() {
return context.getNonIncrementalReason();
}
@Override
public WorkValidationContext getValidationContext() {
return context.getValidationContext();
}
});
}
Aggregations