use of org.gradle.internal.snapshot.ValueSnapshot 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.snapshot.ValueSnapshot 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();
}
});
}
use of org.gradle.internal.snapshot.ValueSnapshot in project gradle by gradle.
the class IdentifyStep method createIdentityContext.
@Nonnull
private IdentityContext createIdentityContext(UnitOfWork work, C context) {
InputFingerprinter.Result inputs = work.getInputFingerprinter().fingerprintInputProperties(ImmutableSortedMap.of(), ImmutableSortedMap.of(), ImmutableSortedMap.of(), ImmutableSortedMap.of(), work::visitIdentityInputs);
ImmutableSortedMap<String, ValueSnapshot> identityInputProperties = inputs.getValueSnapshots();
ImmutableSortedMap<String, CurrentFileCollectionFingerprint> identityInputFileProperties = inputs.getFileFingerprints();
Identity identity = work.identify(identityInputProperties, identityInputFileProperties);
return new IdentityContext() {
@Override
public Optional<String> getNonIncrementalReason() {
return context.getNonIncrementalReason();
}
@Override
public WorkValidationContext getValidationContext() {
return context.getValidationContext();
}
@Override
public ImmutableSortedMap<String, ValueSnapshot> getInputProperties() {
return identityInputProperties;
}
@Override
public ImmutableSortedMap<String, CurrentFileCollectionFingerprint> getInputFileProperties() {
return identityInputFileProperties;
}
@Override
public Identity getIdentity() {
return identity;
}
};
}
use of org.gradle.internal.snapshot.ValueSnapshot in project gradle by gradle.
the class DefaultPreviousExecutionStateSerializer method readInputProperties.
public ImmutableSortedMap<String, ValueSnapshot> readInputProperties(Decoder decoder) throws Exception {
int size = decoder.readSmallInt();
if (size == 0) {
return ImmutableSortedMap.of();
}
if (size == 1) {
return ImmutableSortedMap.of(decoder.readString(), readValueSnapshot(decoder));
}
ImmutableSortedMap.Builder<String, ValueSnapshot> builder = ImmutableSortedMap.naturalOrder();
for (int i = 0; i < size; i++) {
builder.put(decoder.readString(), readValueSnapshot(decoder));
}
return builder.build();
}
use of org.gradle.internal.snapshot.ValueSnapshot in project gradle by gradle.
the class DefaultPreviousExecutionStateSerializer method read.
@Override
public PreviousExecutionState read(Decoder decoder) throws Exception {
OriginMetadata originMetadata = new OriginMetadata(decoder.readString(), Duration.ofMillis(decoder.readLong()));
ImplementationSnapshot taskImplementation = implementationSnapshotSerializer.read(decoder);
// We can't use an immutable list here because some hashes can be null
int taskActionsCount = decoder.readSmallInt();
ImmutableList.Builder<ImplementationSnapshot> taskActionImplementationsBuilder = ImmutableList.builder();
for (int j = 0; j < taskActionsCount; j++) {
ImplementationSnapshot actionImpl = implementationSnapshotSerializer.read(decoder);
taskActionImplementationsBuilder.add(actionImpl);
}
ImmutableList<ImplementationSnapshot> taskActionImplementations = taskActionImplementationsBuilder.build();
ImmutableSortedMap<String, ValueSnapshot> inputProperties = readInputProperties(decoder);
ImmutableSortedMap<String, FileCollectionFingerprint> inputFilesFingerprints = readFingerprints(decoder);
ImmutableSortedMap<String, FileSystemSnapshot> outputFilesSnapshots = readSnapshots(decoder);
boolean successful = decoder.readBoolean();
return new DefaultPreviousExecutionState(originMetadata, taskImplementation, taskActionImplementations, inputProperties, inputFilesFingerprints, outputFilesSnapshots, successful);
}
Aggregations