use of org.gradle.caching.internal.origin.OriginMetadata in project gradle by gradle.
the class CaptureStateAfterExecutionStep method captureStateAfterExecution.
private Optional<AfterExecutionState> captureStateAfterExecution(UnitOfWork work, BeforeExecutionContext context, BeforeExecutionState beforeExecutionState, Duration duration) {
return operation(operationContext -> {
try {
Timer timer = Time.startTimer();
ImmutableSortedMap<String, FileSystemSnapshot> outputsProducedByWork = captureOutputs(work, context, beforeExecutionState);
long snapshotOutputDuration = timer.getElapsedMillis();
// The origin execution time is recorded as “work duration” + “output snapshotting duration”,
// As this is _roughly_ the amount of time that is avoided by reusing the outputs,
// which is currently the _only_ thing this value is used for.
Duration originExecutionTime = duration.plus(Duration.ofMillis(snapshotOutputDuration));
OriginMetadata originMetadata = new OriginMetadata(buildInvocationScopeId.asString(), originExecutionTime);
AfterExecutionState afterExecutionState = new DefaultAfterExecutionState(beforeExecutionState, outputsProducedByWork, originMetadata, false);
operationContext.setResult(Operation.Result.INSTANCE);
return Optional.of(afterExecutionState);
} catch (OutputSnapshotter.OutputFileSnapshottingException e) {
work.handleUnreadableOutputs(e);
operationContext.setResult(Operation.Result.INSTANCE);
return Optional.empty();
}
}, BuildOperationDescriptor.displayName("Snapshot outputs after executing " + work.getDisplayName()).details(Operation.Details.INSTANCE));
}
use of org.gradle.caching.internal.origin.OriginMetadata in project gradle by gradle.
the class TarBuildCacheEntryPacker method unpack.
private UnpackResult unpack(CacheableEntity entity, TarArchiveInputStream tarInput, OriginReader readOriginAction) throws IOException {
ImmutableMap.Builder<String, CacheableTree> treesBuilder = ImmutableMap.builder();
entity.visitOutputTrees((name, type, root) -> treesBuilder.put(name, new CacheableTree(type, root)));
ImmutableMap<String, CacheableTree> treesByName = treesBuilder.build();
TarArchiveEntry tarEntry;
OriginMetadata originMetadata = null;
Map<String, FileSystemLocationSnapshot> snapshots = new HashMap<>();
tarEntry = tarInput.getNextTarEntry();
AtomicLong entries = new AtomicLong();
while (tarEntry != null) {
entries.incrementAndGet();
String path = tarEntry.getName();
if (path.equals(METADATA_PATH)) {
// handle origin metadata
originMetadata = readOriginAction.execute(new CloseShieldInputStream(tarInput));
tarEntry = tarInput.getNextTarEntry();
} else {
// handle tree
Matcher matcher = TREE_PATH.matcher(path);
if (!matcher.matches()) {
throw new IllegalStateException("Cached entry format error, invalid contents: " + path);
}
String treeName = unescape(matcher.group(2));
CacheableTree tree = treesByName.get(treeName);
if (tree == null) {
throw new IllegalStateException(String.format("No tree '%s' registered", treeName));
}
boolean missing = matcher.group(1) != null;
String childPath = matcher.group(3);
tarEntry = unpackTree(treeName, tree.getType(), tree.getRoot(), tarInput, tarEntry, childPath, missing, snapshots, entries);
}
}
if (originMetadata == null) {
throw new IllegalStateException("Cached result format error, no origin metadata was found.");
}
return new UnpackResult(originMetadata, entries.get(), snapshots);
}
use of org.gradle.caching.internal.origin.OriginMetadata in project gradle by gradle.
the class ExecuteActionsTaskExecuter method executeIfValid.
private TaskExecuterResult executeIfValid(TaskInternal task, TaskStateInternal state, TaskExecutionContext context, TaskExecution work) {
ExecutionEngine.Request request = executionEngine.createRequest(work);
context.getTaskExecutionMode().getRebuildReason().ifPresent(request::forceNonIncremental);
request.withValidationContext(context.getValidationContext());
Result result = request.execute();
result.getExecutionResult().ifSuccessfulOrElse(executionResult -> state.setOutcome(TaskExecutionOutcome.valueOf(executionResult.getOutcome())), failure -> state.setOutcome(new TaskExecutionException(task, failure)));
return new TaskExecuterResult() {
@Override
public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
return result.getReusedOutputOriginMetadata();
}
@Override
public boolean executedIncrementally() {
return result.getExecutionResult().map(executionResult -> executionResult.getOutcome() == ExecutionOutcome.EXECUTED_INCREMENTALLY).getOrMapFailure(throwable -> false);
}
@Override
public List<String> getExecutionReasons() {
return result.getExecutionReasons();
}
@Override
public CachingState getCachingState() {
return result.getCachingState();
}
};
}
Aggregations