Search in sources :

Example 1 with OriginMetadata

use of org.gradle.caching.internal.origin.OriginMetadata in project gradle by gradle.

the class SkipUpToDateStep method skipExecution.

private UpToDateResult skipExecution(UnitOfWork work, BeforeExecutionState beforeExecutionState, C context) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Skipping {} as it is up-to-date.", work.getDisplayName());
    }
    @SuppressWarnings("OptionalGetWithoutIsPresent") PreviousExecutionState previousExecutionState = context.getPreviousExecutionState().get();
    AfterExecutionState afterExecutionState = new DefaultAfterExecutionState(beforeExecutionState, previousExecutionState.getOutputFilesProducedByWork(), previousExecutionState.getOriginMetadata(), true);
    return new UpToDateResult() {

        @Override
        public ImmutableList<String> getExecutionReasons() {
            return ImmutableList.of();
        }

        @Override
        public Optional<AfterExecutionState> getAfterExecutionState() {
            return Optional.of(afterExecutionState);
        }

        @Override
        public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
            return Optional.of(previousExecutionState.getOriginMetadata());
        }

        @Override
        public Try<ExecutionResult> getExecutionResult() {
            return Try.successful(new ExecutionResult() {

                @Override
                public ExecutionOutcome getOutcome() {
                    return ExecutionOutcome.UP_TO_DATE;
                }

                @Override
                public Object getOutput() {
                    return work.loadRestoredOutput(context.getWorkspace());
                }
            });
        }

        @Override
        public Duration getDuration() {
            return previousExecutionState.getOriginMetadata().getExecutionTime();
        }
    };
}
Also used : DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) ExecutionResult(org.gradle.internal.execution.ExecutionResult) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata)

Example 2 with OriginMetadata

use of org.gradle.caching.internal.origin.OriginMetadata 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();
        }
    };
}
Also used : BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) LoggerFactory(org.slf4j.LoggerFactory) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) Formatter(java.util.Formatter) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext) CachingStateFactory(org.gradle.internal.execution.caching.CachingStateFactory) ExecutionResult(org.gradle.internal.execution.ExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) Duration(java.time.Duration) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) UnitOfWork(org.gradle.internal.execution.UnitOfWork) Logger(org.slf4j.Logger) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) File(java.io.File) BuildCacheKey(org.gradle.caching.BuildCacheKey) CachingDisabledReason(org.gradle.internal.execution.caching.CachingDisabledReason) List(java.util.List) BuildCacheController(org.gradle.caching.internal.controller.BuildCacheController) NOPLogger(org.slf4j.helpers.NOPLogger) Try(org.gradle.internal.Try) CachingDisabledReasonCategory(org.gradle.internal.execution.caching.CachingDisabledReasonCategory) Optional(java.util.Optional) DefaultCachingStateFactory(org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) CachingState(org.gradle.internal.execution.caching.CachingState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ExecutionResult(org.gradle.internal.execution.ExecutionResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) File(java.io.File) CachingState(org.gradle.internal.execution.caching.CachingState) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext)

Example 3 with OriginMetadata

use of org.gradle.caching.internal.origin.OriginMetadata in project gradle by gradle.

the class SkipEmptyWorkStep method skipExecutionWithEmptySources.

@Nonnull
private CachingResult skipExecutionWithEmptySources(UnitOfWork work, PreviousExecutionContext context) {
    ImmutableSortedMap<String, FileSystemSnapshot> outputFilesAfterPreviousExecution = context.getPreviousExecutionState().map(PreviousExecutionState::getOutputFilesProducedByWork).orElse(ImmutableSortedMap.of());
    ExecutionOutcome skipOutcome;
    Timer timer = Time.startTimer();
    if (outputFilesAfterPreviousExecution.isEmpty()) {
        LOGGER.info("Skipping {} as it has no source files and no previous output files.", work.getDisplayName());
        skipOutcome = ExecutionOutcome.SHORT_CIRCUITED;
    } else {
        boolean didWork = cleanPreviousTaskOutputs(outputFilesAfterPreviousExecution);
        if (didWork) {
            LOGGER.info("Cleaned previous output of {} as it has no source files.", work.getDisplayName());
            skipOutcome = ExecutionOutcome.EXECUTED_NON_INCREMENTALLY;
        } else {
            skipOutcome = ExecutionOutcome.SHORT_CIRCUITED;
        }
    }
    Duration duration = skipOutcome == ExecutionOutcome.SHORT_CIRCUITED ? Duration.ZERO : Duration.ofMillis(timer.getElapsedMillis());
    broadcastWorkInputs(work, true);
    return new CachingResult() {

        @Override
        public Duration getDuration() {
            return duration;
        }

        @Override
        public Try<ExecutionResult> getExecutionResult() {
            return Try.successful(new ExecutionResult() {

                @Override
                public ExecutionOutcome getOutcome() {
                    return skipOutcome;
                }

                @Override
                public Object getOutput() {
                    return work.loadRestoredOutput(context.getWorkspace());
                }
            });
        }

        @Override
        public CachingState getCachingState() {
            return CachingState.NOT_DETERMINED;
        }

        @Override
        public ImmutableList<String> getExecutionReasons() {
            return ImmutableList.of();
        }

        @Override
        public Optional<AfterExecutionState> getAfterExecutionState() {
            return Optional.empty();
        }

        @Override
        public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
            return Optional.empty();
        }
    };
}
Also used : ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Duration(java.time.Duration) ExecutionResult(org.gradle.internal.execution.ExecutionResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) Timer(org.gradle.internal.time.Timer) Nonnull(javax.annotation.Nonnull)

Example 4 with OriginMetadata

use of org.gradle.caching.internal.origin.OriginMetadata 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 5 with OriginMetadata

use of org.gradle.caching.internal.origin.OriginMetadata 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)

Aggregations

OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)8 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)4 Duration (java.time.Duration)3 ExecutionOutcome (org.gradle.internal.execution.ExecutionOutcome)3 ExecutionResult (org.gradle.internal.execution.ExecutionResult)3 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Optional (java.util.Optional)2 CachingState (org.gradle.internal.execution.caching.CachingState)2 ExecutionHistoryStore (org.gradle.internal.execution.history.ExecutionHistoryStore)2 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)2 ImplementationSnapshot (org.gradle.internal.snapshot.impl.ImplementationSnapshot)2 Timer (org.gradle.internal.time.Timer)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 File (java.io.File)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1