Search in sources :

Example 1 with ImplementationSnapshot

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);
}
Also used : ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) DefaultBeforeExecutionState(org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot)

Example 2 with ImplementationSnapshot

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());
}
Also used : ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata)

Example 3 with ImplementationSnapshot

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);
}
Also used : ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) ImmutableList(com.google.common.collect.ImmutableList) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileCollectionFingerprint(org.gradle.internal.fingerprint.FileCollectionFingerprint) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) FileCollectionFingerprint(org.gradle.internal.fingerprint.FileCollectionFingerprint) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot)

Example 4 with ImplementationSnapshot

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);
        }
    });
}
Also used : UnitOfWork(org.gradle.internal.execution.UnitOfWork) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot) TypeValidationContext(org.gradle.internal.reflect.validation.TypeValidationContext)

Aggregations

ImplementationSnapshot (org.gradle.internal.snapshot.impl.ImplementationSnapshot)4 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)2 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)2 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)2 ImmutableList (com.google.common.collect.ImmutableList)1 UnitOfWork (org.gradle.internal.execution.UnitOfWork)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1 OverlappingOutputs (org.gradle.internal.execution.history.OverlappingOutputs)1 PreviousExecutionState (org.gradle.internal.execution.history.PreviousExecutionState)1 DefaultBeforeExecutionState (org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState)1 FileCollectionFingerprint (org.gradle.internal.fingerprint.FileCollectionFingerprint)1 TypeValidationContext (org.gradle.internal.reflect.validation.TypeValidationContext)1