|
private boolean isCachedOrUpToDate(Task task) { |
|
TaskExecutionGraphInternal graph = (TaskExecutionGraphInternal) getProject().getGradle().getTaskGraph(); |
|
for (Node node : graph.getScheduledWork()) { |
|
if (node instanceof LocalTaskNode) { |
|
LocalTaskNode localTaskNode = (LocalTaskNode) node; |
|
if (localTaskNode.getTask() == horizonTask) { |
|
return isCachedOrUpToDate(localTaskNode); |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
private boolean isCachedOrUpToDate(LocalTaskNode localTaskNode) { |
|
ServiceRegistry registry = ((ProjectInternal) getProject()).getServices(); |
|
|
|
BuildOperationExecutor buildOperationExecutor = registry.get(BuildOperationExecutor.class); |
|
ClassLoaderHierarchyHasher classLoaderHierarchyHasher = registry.get(ClassLoaderHierarchyHasher.class); |
|
ValueSnapshotter valueSnapshotter = registry.get(ValueSnapshotter.class); |
|
OverlappingOutputDetector overlappingOutputDetector = registry.get(OverlappingOutputDetector.class); |
|
BuildCacheController buildCacheController = registry.get(BuildCacheController.class); |
|
boolean buildScansEnabled = false; |
|
DefaultWorkExecutor<ExecutionRequestContext, CachingResult> executor = new DefaultWorkExecutor<>( |
|
new LoadExecutionStateStep<>( |
|
new CaptureStateBeforeExecutionStep(buildOperationExecutor, classLoaderHierarchyHasher, valueSnapshotter, overlappingOutputDetector, |
|
new ResolveCachingStateStep(buildCacheController, buildScansEnabled, new Step<CachingContext, UpToDateResult>() { |
|
@Override |
|
public UpToDateResult execute(CachingContext context) { |
|
return new UpToDateResult() { |
|
@Override |
|
public ImmutableSortedMap<String, ? extends FileCollectionFingerprint> getFinalOutputs() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
|
|
@Override |
|
public Try<ExecutionOutcome> getOutcome() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
|
|
@Override |
|
public ImmutableList<String> getExecutionReasons() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
|
|
@Override |
|
public Optional<OriginMetadata> getReusedOutputOriginMetadata() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
}; |
|
} |
|
})))); |
|
CachingResult caching = executor.execute(new ExecutionRequestContext() { |
|
@Override |
|
public Optional<String> getRebuildReason() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
|
|
@Override |
|
public UnitOfWork getWork() { |
|
throw new UnsupportedOperationException(); |
|
} |
|
}); |
|
ExecutionOutcome outcome = caching.getOutcome().get(); |
|
return outcome == ExecutionOutcome.FROM_CACHE || outcome == ExecutionOutcome.UP_TO_DATE; |
|
} |