use of org.gradle.caching.BuildCacheEntryWriter 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.BuildCacheEntryWriter in project gradle by gradle.
the class DispatchingBuildCacheService method pushToLocalAndRemote.
private void pushToLocalAndRemote(BuildCacheKey key, BuildCacheEntryWriter writer) {
File destination = temporaryFileProvider.createTemporaryFile("gradle_cache", "entry");
try {
writeCacheEntryLocally(writer, destination);
BuildCacheEntryWriter copier = new CopyBuildCacheEntryWriter(destination);
local.store(key, copier);
remote.store(key, copier);
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
GFileUtils.deleteQuietly(destination);
}
}
Aggregations