use of org.gradle.api.internal.tasks.OriginTaskExecutionMetadata 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.OriginTaskExecutionMetadata in project gradle by gradle.
the class TaskOutputOriginFactory method createReader.
public TaskOutputOriginReader createReader(final TaskInternal task) {
return new TaskOutputOriginReader() {
@Override
public OriginTaskExecutionMetadata execute(InputStream inputStream) {
// TODO: Replace this with something better
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
if (!properties.stringPropertyNames().containsAll(METADATA_KEYS)) {
throw new IllegalStateException("Cached result format error, corrupted origin metadata.");
}
LOGGER.info("Origin for {}: {}", task, properties);
UniqueId originBuildInvocationId = UniqueId.from(properties.getProperty(BUILD_INVOCATION_ID_KEY));
long originalExecutionTime = Long.parseLong(properties.getProperty(EXECUTION_TIME_KEY));
return new OriginTaskExecutionMetadata(originBuildInvocationId, originalExecutionTime);
}
};
}
use of org.gradle.api.internal.tasks.OriginTaskExecutionMetadata in project gradle by gradle.
the class ExecuteTaskBuildOperationResult method getOriginBuildInvocationId.
@Nullable
@Override
public String getOriginBuildInvocationId() {
OriginTaskExecutionMetadata originExecutionMetadata = ctx.getOriginExecutionMetadata();
UniqueId originBuildInvocationId = originExecutionMetadata == null ? null : originExecutionMetadata.getBuildInvocationId();
return originBuildInvocationId == null ? null : originBuildInvocationId.asString();
}
use of org.gradle.api.internal.tasks.OriginTaskExecutionMetadata 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());
}
use of org.gradle.api.internal.tasks.OriginTaskExecutionMetadata in project gradle by gradle.
the class TaskExecutionSnapshotSerializer method read.
public HistoricalTaskExecution read(Decoder decoder) throws Exception {
boolean successful = decoder.readBoolean();
OriginTaskExecutionMetadata originExecutionMetadata = new OriginTaskExecutionMetadata(UniqueId.from(decoder.readString()), decoder.readLong());
ImmutableSortedMap<String, FileCollectionSnapshot> inputFilesSnapshots = readSnapshots(decoder);
ImmutableSortedMap<String, FileCollectionSnapshot> outputFilesSnapshots = readSnapshots(decoder);
FileCollectionSnapshot discoveredFilesSnapshot = fileCollectionSnapshotSerializer.read(decoder);
ImplementationSnapshot taskImplementation = readImplementation(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 = readImplementation(decoder);
taskActionImplementationsBuilder.add(actionImpl);
}
ImmutableList<ImplementationSnapshot> taskActionImplementations = taskActionImplementationsBuilder.build();
int cacheableOutputPropertiesCount = decoder.readSmallInt();
ImmutableSortedSet.Builder<String> cacheableOutputPropertiesBuilder = ImmutableSortedSet.naturalOrder();
for (int j = 0; j < cacheableOutputPropertiesCount; j++) {
cacheableOutputPropertiesBuilder.add(decoder.readString());
}
ImmutableSortedSet<String> cacheableOutputProperties = cacheableOutputPropertiesBuilder.build();
ImmutableSortedMap<String, ValueSnapshot> inputProperties = inputPropertiesSerializer.read(decoder);
return new HistoricalTaskExecution(taskImplementation, taskActionImplementations, inputProperties, cacheableOutputProperties, inputFilesSnapshots, discoveredFilesSnapshot, outputFilesSnapshots, successful, originExecutionMetadata);
}
Aggregations