Search in sources :

Example 1 with OverlappingOutputs

use of org.gradle.internal.execution.history.OverlappingOutputs in project gradle by gradle.

the class DefaultOverlappingOutputDetector method detect.

@Override
@Nullable
public OverlappingOutputs detect(ImmutableSortedMap<String, FileSystemSnapshot> previous, ImmutableSortedMap<String, FileSystemSnapshot> current) {
    for (Map.Entry<String, FileSystemSnapshot> entry : current.entrySet()) {
        String propertyName = entry.getKey();
        FileSystemSnapshot currentSnapshot = entry.getValue();
        FileSystemSnapshot previousSnapshot = previous.getOrDefault(propertyName, FileSystemSnapshot.EMPTY);
        // If the root hashes are the same there are no overlapping outputs
        if (getRootHashes(previousSnapshot).equals(getRootHashes(currentSnapshot))) {
            continue;
        }
        OverlappingOutputs overlappingOutputs = detect(propertyName, previousSnapshot, currentSnapshot);
        if (overlappingOutputs != null) {
            return overlappingOutputs;
        }
    }
    return null;
}
Also used : OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) Nullable(javax.annotation.Nullable)

Example 2 with OverlappingOutputs

use of org.gradle.internal.execution.history.OverlappingOutputs in project gradle by gradle.

the class DefaultOverlappingOutputDetector method detect.

@Nullable
private static OverlappingOutputs detect(String propertyName, FileSystemSnapshot previous, FileSystemSnapshot before) {
    Map<String, FileSystemLocationSnapshot> previousIndex = SnapshotUtil.index(previous);
    OverlappingOutputsDetectingVisitor outputsDetectingVisitor = new OverlappingOutputsDetectingVisitor(previousIndex);
    before.accept(outputsDetectingVisitor);
    String overlappingPath = outputsDetectingVisitor.getOverlappingPath();
    return overlappingPath == null ? null : new OverlappingOutputs(propertyName, overlappingPath);
}
Also used : OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Nullable(javax.annotation.Nullable)

Example 3 with OverlappingOutputs

use of org.gradle.internal.execution.history.OverlappingOutputs 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 4 with OverlappingOutputs

use of org.gradle.internal.execution.history.OverlappingOutputs in project gradle by gradle.

the class ResolveCachingStateStep method calculateCachingState.

private CachingState calculateCachingState(UnitOfWork work, BeforeExecutionState beforeExecutionState) {
    Logger logger = buildCache.isEmitDebugLogging() ? LOGGER : NOPLogger.NOP_LOGGER;
    CachingStateFactory cachingStateFactory = new DefaultCachingStateFactory(logger);
    ImmutableList.Builder<CachingDisabledReason> cachingDisabledReasonsBuilder = ImmutableList.builder();
    if (!buildCache.isEnabled()) {
        cachingDisabledReasonsBuilder.add(BUILD_CACHE_DISABLED_REASON);
    }
    OverlappingOutputs detectedOverlappingOutputs = beforeExecutionState.getDetectedOverlappingOutputs().orElse(null);
    work.shouldDisableCaching(detectedOverlappingOutputs).ifPresent(cachingDisabledReasonsBuilder::add);
    return cachingStateFactory.createCachingState(beforeExecutionState, cachingDisabledReasonsBuilder.build());
}
Also used : CachingDisabledReason(org.gradle.internal.execution.caching.CachingDisabledReason) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) CachingStateFactory(org.gradle.internal.execution.caching.CachingStateFactory) DefaultCachingStateFactory(org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory) ImmutableList(com.google.common.collect.ImmutableList) Logger(org.slf4j.Logger) NOPLogger(org.slf4j.helpers.NOPLogger) DefaultCachingStateFactory(org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory)

Aggregations

OverlappingOutputs (org.gradle.internal.execution.history.OverlappingOutputs)4 Nullable (javax.annotation.Nullable)2 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Map (java.util.Map)1 CachingDisabledReason (org.gradle.internal.execution.caching.CachingDisabledReason)1 CachingStateFactory (org.gradle.internal.execution.caching.CachingStateFactory)1 DefaultCachingStateFactory (org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1 PreviousExecutionState (org.gradle.internal.execution.history.PreviousExecutionState)1 DefaultBeforeExecutionState (org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState)1 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)1 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)1 ImplementationSnapshot (org.gradle.internal.snapshot.impl.ImplementationSnapshot)1 Logger (org.slf4j.Logger)1 NOPLogger (org.slf4j.helpers.NOPLogger)1