use of org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec in project gradle by gradle.
the class SkipCachedTaskExecuter method resolveProperties.
private static SortedSet<ResolvedTaskOutputFilePropertySpec> resolveProperties(ImmutableSortedSet<? extends TaskOutputFilePropertySpec> properties) {
ImmutableSortedSet.Builder<ResolvedTaskOutputFilePropertySpec> builder = ImmutableSortedSet.naturalOrder();
for (TaskOutputFilePropertySpec property : properties) {
// At this point we assume that the task only has cacheable properties,
// otherwise caching would have been disabled by now
CacheableTaskOutputFilePropertySpec cacheableProperty = (CacheableTaskOutputFilePropertySpec) property;
builder.add(new ResolvedTaskOutputFilePropertySpec(cacheableProperty.getPropertyName(), cacheableProperty.getOutputType(), cacheableProperty.getOutputFile()));
}
return builder.build();
}
use of org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec 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);
}
}
}
use of org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec in project gradle by gradle.
the class TarTaskOutputPacker method pack.
private long pack(Collection<ResolvedTaskOutputFilePropertySpec> propertySpecs, Map<String, Map<String, FileContentSnapshot>> outputSnapshots, TarArchiveOutputStream tarOutput) {
long entries = 0;
for (ResolvedTaskOutputFilePropertySpec propertySpec : propertySpecs) {
String propertyName = propertySpec.getPropertyName();
Map<String, FileContentSnapshot> outputs = outputSnapshots.get(propertyName);
try {
entries += packProperty(propertySpec, outputs, tarOutput);
} catch (Exception ex) {
throw new GradleException(String.format("Could not pack property '%s': %s", propertyName, ex.getMessage()), ex);
}
}
return entries;
}
use of org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec in project gradle by gradle.
the class TarTaskOutputPacker method unpack.
private UnpackResult unpack(SortedSet<ResolvedTaskOutputFilePropertySpec> propertySpecs, TarArchiveInputStream tarInput, TaskOutputOriginReader readOriginAction) throws IOException {
Map<String, ResolvedTaskOutputFilePropertySpec> propertySpecsMap = Maps.uniqueIndex(propertySpecs, new Function<TaskFilePropertySpec, String>() {
@Override
public String apply(TaskFilePropertySpec propertySpec) {
return propertySpec.getPropertyName();
}
});
TarArchiveEntry tarEntry;
OriginTaskExecutionMetadata originMetadata = null;
ImmutableListMultimap.Builder<String, FileSnapshot> propertyFileSnapshots = ImmutableListMultimap.builder();
long entries = 0;
while ((tarEntry = tarInput.getNextTarEntry()) != null) {
++entries;
String path = tarEntry.getName();
if (path.equals(METADATA_PATH)) {
// handle origin metadata
originMetadata = readOriginAction.execute(new CloseShieldInputStream(tarInput));
} else {
// handle output property
Matcher matcher = PROPERTY_PATH.matcher(path);
if (!matcher.matches()) {
throw new IllegalStateException("Cached result format error, invalid contents: " + path);
}
String propertyName = unescape(matcher.group(2));
ResolvedTaskOutputFilePropertySpec propertySpec = propertySpecsMap.get(propertyName);
if (propertySpec == null) {
throw new IllegalStateException(String.format("No output property '%s' registered", propertyName));
}
boolean outputMissing = matcher.group(1) != null;
String childPath = matcher.group(3);
unpackPropertyEntry(propertySpec, tarInput, tarEntry, childPath, outputMissing, propertyFileSnapshots);
}
}
if (originMetadata == null) {
throw new IllegalStateException("Cached result format error, no origin metadata was found.");
}
return new UnpackResult(originMetadata, entries, propertyFileSnapshots.build());
}
Aggregations