use of org.gradle.internal.snapshot.impl.ImplementationSnapshot in project gradle by gradle.
the class CaptureStateBeforeExecutionStep method captureExecutionStateWithOutputs.
private BeforeExecutionState captureExecutionStateWithOutputs(UnitOfWork work, PreviousExecutionContext context, ImmutableSortedMap<String, FileSystemSnapshot> unfilteredOutputSnapshots) {
Optional<PreviousExecutionState> previousExecutionState = context.getPreviousExecutionState();
ImplementationsBuilder implementationsBuilder = new ImplementationsBuilder(classLoaderHierarchyHasher);
work.visitImplementations(implementationsBuilder);
ImplementationSnapshot implementation = implementationsBuilder.getImplementation();
ImmutableList<ImplementationSnapshot> additionalImplementations = implementationsBuilder.getAdditionalImplementations();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Implementation for {}: {}", work.getDisplayName(), implementation);
LOGGER.debug("Additional implementations for {}: {}", work.getDisplayName(), additionalImplementations);
}
ImmutableSortedMap<String, ValueSnapshot> previousInputProperties = previousExecutionState.map(InputExecutionState::getInputProperties).orElse(ImmutableSortedMap.of());
ImmutableSortedMap<String, ? extends FileCollectionFingerprint> previousInputFileFingerprints = previousExecutionState.map(InputExecutionState::getInputFileProperties).orElse(ImmutableSortedMap.of());
ImmutableSortedMap<String, FileSystemSnapshot> previousOutputSnapshots = previousExecutionState.map(PreviousExecutionState::getOutputFilesProducedByWork).orElse(ImmutableSortedMap.of());
OverlappingOutputs overlappingOutputs;
switch(work.getOverlappingOutputHandling()) {
case DETECT_OVERLAPS:
overlappingOutputs = overlappingOutputDetector.detect(previousOutputSnapshots, unfilteredOutputSnapshots);
break;
case IGNORE_OVERLAPS:
overlappingOutputs = null;
break;
default:
throw new AssertionError();
}
InputFingerprinter.Result newInputs = work.getInputFingerprinter().fingerprintInputProperties(previousInputProperties, previousInputFileFingerprints, context.getInputProperties(), context.getInputFileProperties(), work::visitRegularInputs);
return new DefaultBeforeExecutionState(implementation, additionalImplementations, newInputs.getAllValueSnapshots(), newInputs.getAllFileFingerprints(), unfilteredOutputSnapshots, overlappingOutputs);
}
use of org.gradle.internal.snapshot.impl.ImplementationSnapshot in project gradle by gradle.
the class DefaultPreviousExecutionStateSerializer method write.
@Override
public void write(Encoder encoder, PreviousExecutionState execution) throws Exception {
OriginMetadata originMetadata = execution.getOriginMetadata();
encoder.writeString(originMetadata.getBuildInvocationId());
encoder.writeLong(originMetadata.getExecutionTime().toMillis());
implementationSnapshotSerializer.write(encoder, execution.getImplementation());
ImmutableList<ImplementationSnapshot> additionalImplementations = execution.getAdditionalImplementations();
encoder.writeSmallInt(additionalImplementations.size());
for (ImplementationSnapshot actionImpl : additionalImplementations) {
implementationSnapshotSerializer.write(encoder, actionImpl);
}
writeInputProperties(encoder, execution.getInputProperties());
writeFingerprints(encoder, execution.getInputFileProperties());
writeSnapshots(encoder, execution.getOutputFilesProducedByWork());
encoder.writeBoolean(execution.isSuccessful());
}
use of org.gradle.internal.snapshot.impl.ImplementationSnapshot 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);
}
use of org.gradle.internal.snapshot.impl.ImplementationSnapshot 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);
}
});
}
Aggregations