Search in sources :

Example 1 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class ResolveBuildCacheKeyExecuter method execute.

@Override
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    TaskArtifactState taskState = context.getTaskArtifactState();
    TaskOutputCachingBuildCacheKey cacheKey = taskState.calculateCacheKey();
    context.setBuildCacheKey(cacheKey);
    if (task.getOutputs().getHasOutput()) {
        // A task with no outputs an no cache key.
        listener.cacheKeyEvaluated(task, cacheKey);
        if (cacheKey.isValid()) {
            LOGGER.info("Cache key for {} is {}", task, cacheKey.getHashCode());
        }
    }
    delegate.execute(task, state, context);
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) TaskOutputCachingBuildCacheKey(org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey)

Example 2 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class ResolveBuildCacheKeyExecuter method doResolve.

private TaskOutputCachingBuildCacheKey doResolve(TaskInternal task, TaskExecutionContext context) {
    TaskArtifactState taskState = context.getTaskArtifactState();
    TaskOutputCachingBuildCacheKey cacheKey = taskState.calculateCacheKey();
    if (context.getTaskProperties().hasDeclaredOutputs()) {
        // A task with no outputs and no cache key.
        if (cacheKey.isValid()) {
            LogLevel logLevel = buildCacheDebugLogging ? LogLevel.LIFECYCLE : LogLevel.INFO;
            LOGGER.log(logLevel, "Build cache key for {} is {}", task, cacheKey.getHashCode());
        }
    }
    return cacheKey;
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) TaskOutputCachingBuildCacheKey(org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey) LogLevel(org.gradle.api.logging.LogLevel)

Example 3 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class ResolveTaskArtifactStateTaskExecuter method execute.

@Override
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    Timer clock = Time.startTimer();
    TaskProperties taskProperties = DefaultTaskProperties.resolve(propertyWalker, resolver, task);
    context.setTaskProperties(taskProperties);
    TaskArtifactState taskArtifactState = repository.getStateFor(task, taskProperties);
    TaskOutputsInternal outputs = task.getOutputs();
    context.setTaskArtifactState(taskArtifactState);
    outputs.setHistory(taskArtifactState.getExecutionHistory());
    LOGGER.debug("Putting task artifact state for {} into context took {}.", task, clock.getElapsed());
    try {
        executer.execute(task, state, context);
    } finally {
        outputs.setHistory(null);
        context.setTaskArtifactState(null);
        context.setTaskProperties(null);
        LOGGER.debug("Removed task artifact state for {} from context.");
    }
}
Also used : Timer(org.gradle.internal.time.Timer) TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) TaskOutputsInternal(org.gradle.api.internal.TaskOutputsInternal)

Example 4 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class SkipCachedTaskExecuter method execute.

@Override
public void execute(final TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    LOGGER.debug("Determining if {} is cached already", task);
    TaskProperties taskProperties = context.getTaskProperties();
    TaskOutputCachingBuildCacheKey cacheKey = context.getBuildCacheKey();
    boolean taskOutputCachingEnabled = state.getTaskOutputCaching().isEnabled();
    SortedSet<ResolvedTaskOutputFilePropertySpec> outputProperties = null;
    if (taskOutputCachingEnabled) {
        if (task.isHasCustomActions()) {
            LOGGER.info("Custom actions are attached to {}.", task);
        }
        if (cacheKey.isValid()) {
            TaskArtifactState taskState = context.getTaskArtifactState();
            // TODO: This is really something we should do at an earlier/higher level so that the input and output
            // property values are locked in at this point.
            outputProperties = resolveProperties(taskProperties.getOutputFileProperties());
            if (taskState.isAllowedToUseCachedResults()) {
                try {
                    OriginTaskExecutionMetadata originMetadata = buildCache.load(buildCacheCommandFactory.createLoad(cacheKey, outputProperties, task, taskProperties, taskOutputChangesListener, taskState));
                    if (originMetadata != null) {
                        state.setOutcome(TaskExecutionOutcome.FROM_CACHE);
                        context.setOriginExecutionMetadata(originMetadata);
                        return;
                    }
                } catch (UnrecoverableTaskOutputUnpackingException e) {
                    // garbage among the task's outputs, thus we must fail the build
                    throw e;
                } catch (Exception e) {
                    // There was a failure during downloading, previous task outputs should bu unaffected
                    LOGGER.warn("Failed to load cache entry for {}, falling back to executing task", task, e);
                }
            } else {
                LOGGER.info("Not loading {} from cache because pulling from cache is disabled for this task", task);
            }
        } else {
            LOGGER.info("Not caching {} because no valid cache key was generated", task);
        }
    }
    delegate.execute(task, state, context);
    if (taskOutputCachingEnabled) {
        if (cacheKey.isValid()) {
            if (state.getFailure() == null) {
                try {
                    TaskArtifactState taskState = context.getTaskArtifactState();
                    Map<String, Map<String, FileContentSnapshot>> outputSnapshots = taskState.getOutputContentSnapshots();
                    buildCache.store(buildCacheCommandFactory.createStore(cacheKey, outputProperties, outputSnapshots, task, context.getExecutionTime()));
                } catch (Exception e) {
                    LOGGER.warn("Failed to store cache entry {}", cacheKey.getDisplayName(), task, e);
                }
            } else {
                LOGGER.debug("Not pushing result from {} to cache because the task failed", task);
            }
        } else {
            LOGGER.info("Not pushing results from {} to cache because no valid cache key was generated", task);
        }
    }
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) OriginTaskExecutionMetadata(org.gradle.api.internal.tasks.OriginTaskExecutionMetadata) TaskOutputCachingBuildCacheKey(org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey) ResolvedTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec) Map(java.util.Map) UnrecoverableTaskOutputUnpackingException(org.gradle.caching.internal.tasks.UnrecoverableTaskOutputUnpackingException) UnrecoverableTaskOutputUnpackingException(org.gradle.caching.internal.tasks.UnrecoverableTaskOutputUnpackingException)

Example 5 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class SkipUpToDateTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    LOGGER.debug("Determining if {} is up-to-date", task);
    TaskArtifactState taskArtifactState = context.getTaskArtifactState();
    List<String> messages = new ArrayList<String>(TaskUpToDateState.MAX_OUT_OF_DATE_MESSAGES);
    if (taskArtifactState.isUpToDate(messages)) {
        LOGGER.info("Skipping {} as it is up-to-date.", task);
        state.setOutcome(TaskExecutionOutcome.UP_TO_DATE);
        context.setOriginExecutionMetadata(taskArtifactState.getExecutionHistory().getOriginExecutionMetadata());
        return;
    }
    context.setUpToDateMessages(ImmutableList.copyOf(messages));
    logOutOfDateMessages(messages, task);
    executer.execute(task, state, context);
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) ArrayList(java.util.ArrayList)

Aggregations

TaskArtifactState (org.gradle.api.internal.changedetection.TaskArtifactState)7 TaskOutputCachingBuildCacheKey (org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FileCollection (org.gradle.api.file.FileCollection)1 TaskExecutionHistory (org.gradle.api.internal.TaskExecutionHistory)1 TaskOutputsInternal (org.gradle.api.internal.TaskOutputsInternal)1 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)1 OriginTaskExecutionMetadata (org.gradle.api.internal.tasks.OriginTaskExecutionMetadata)1 ResolvedTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec)1 LogLevel (org.gradle.api.logging.LogLevel)1 UnrecoverableTaskOutputUnpackingException (org.gradle.caching.internal.tasks.UnrecoverableTaskOutputUnpackingException)1 Timer (org.gradle.internal.time.Timer)1