use of org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey 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);
}
use of org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey in project gradle by gradle.
the class SkipCachedTaskExecuter method execute.
@Override
public void execute(final TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
final Timer clock = Timers.startTimer();
LOGGER.debug("Determining if {} is cached already", task);
final TaskOutputsInternal taskOutputs = task.getOutputs();
TaskOutputCachingBuildCacheKey cacheKey = context.getBuildCacheKey();
boolean taskOutputCachingEnabled = state.getTaskOutputCaching().isEnabled();
if (taskOutputCachingEnabled) {
if (cacheKey.isValid()) {
TaskArtifactState taskState = context.getTaskArtifactState();
if (taskState.isAllowedToUseCachedResults()) {
boolean found = buildCache.load(cacheKey, new BuildCacheEntryReader() {
@Override
public void readFrom(final InputStream input) {
taskOutputsGenerationListener.beforeTaskOutputsGenerated();
packer.unpack(taskOutputs, input, taskOutputOriginFactory.createReader(task));
LOGGER.info("Unpacked output for {} from cache (took {}).", task, clock.getElapsed());
}
});
if (found) {
state.setOutcome(TaskExecutionOutcome.FROM_CACHE);
return;
}
} 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) {
buildCache.store(cacheKey, new BuildCacheEntryWriter() {
@Override
public void writeTo(OutputStream output) {
LOGGER.info("Packing {}", task.getPath());
packer.pack(taskOutputs, output, taskOutputOriginFactory.createWriter(task, clock.getElapsedMillis()));
}
});
} 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);
}
}
}
use of org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey in project gradle by gradle.
the class VerifyNoInputChangesTaskExecuter method execute.
@Override
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
TaskOutputCachingBuildCacheKey beforeExecution = context.getBuildCacheKey();
delegate.execute(task, state, context);
if (beforeExecution.isValid()) {
TaskOutputCachingBuildCacheKey afterExecution = repository.getStateFor(task).calculateCacheKey();
if (!afterExecution.isValid()) {
throw new TaskExecutionException(task, new GradleException("The build cache key became invalid after the task has been executed!"));
}
if (!beforeExecution.getHashCode().equals(afterExecution.getHashCode())) {
throw new TaskExecutionException(task, new GradleException("The inputs for the task changed during the execution! Check if you have a `doFirst` changing the inputs."));
}
}
}
Aggregations