Skip to content

Instantly share code, notes, and snippets.

@lptr
Created November 20, 2023 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lptr/38c2ee67039bcc4d44fdff5aa6fe0879 to your computer and use it in GitHub Desktop.
Save lptr/38c2ee67039bcc4d44fdff5aa6fe0879 to your computer and use it in GitHub Desktop.
diff --git a/platforms/core-execution/execution/src/integTest/groovy/org/gradle/internal/execution/IncrementalExecutionIntegrationTest.groovy b/platforms/core-execution/execution/src/integTest/groovy/org/gradle/internal/execution/IncrementalExecutionIntegrationTest.groovy
index a7a098a1e23..d67adc4f6a3 100644
--- a/platforms/core-execution/execution/src/integTest/groovy/org/gradle/internal/execution/IncrementalExecutionIntegrationTest.groovy
+++ b/platforms/core-execution/execution/src/integTest/groovy/org/gradle/internal/execution/IncrementalExecutionIntegrationTest.groovy
@@ -64,13 +64,6 @@ class IncrementalExecutionIntegrationTest extends Specification implements Valid
def snapshotter = new DefaultFileCollectionSnapshotter(fileSystemAccess, TestFiles.fileSystem())
def fingerprinter = new AbsolutePathFileCollectionFingerprinter(DirectorySensitivity.DEFAULT, snapshotter, FileSystemLocationSnapshotHasher.DEFAULT)
def executionHistoryStore = new TestExecutionHistoryStore()
- def outputChangeListener = new OutputChangeListener() {
-
- @Override
- void invalidateCachesFor(Iterable<String> affectedOutputPaths) {
- fileSystemAccess.write(affectedOutputPaths) {}
- }
- }
def buildId = UniqueId.generate()
def classloaderHierarchyHasher = new ClassLoaderHierarchyHasher() {
@Override
@@ -117,7 +110,7 @@ class IncrementalExecutionIntegrationTest extends Specification implements Valid
classloaderHierarchyHasher,
deleter,
changeDetector,
- outputChangeListener,
+ fileSystemAccess,
outputSnapshotter,
overlappingOutputDetector,
problems,
diff --git a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BroadcastChangingOutputsStep.java b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BroadcastChangingOutputsStep.java
index 7356892d068..8f39af1b8f9 100644
--- a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BroadcastChangingOutputsStep.java
+++ b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BroadcastChangingOutputsStep.java
@@ -17,22 +17,22 @@
package org.gradle.internal.execution.steps;
import com.google.common.collect.ImmutableList;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.file.TreeType;
+import org.gradle.internal.vfs.FileSystemAccess;
import java.io.File;
public class BroadcastChangingOutputsStep<C extends InputChangesContext> implements Step<C, Result> {
- private final OutputChangeListener outputChangeListener;
+ private final FileSystemAccess fileSystemAccess;
private final Step<? super ChangingOutputsContext, ? extends Result> delegate;
public BroadcastChangingOutputsStep(
- OutputChangeListener outputChangeListener,
+ FileSystemAccess fileSystemAccess,
Step<? super ChangingOutputsContext, ? extends Result> delegate
) {
- this.outputChangeListener = outputChangeListener;
+ this.fileSystemAccess = fileSystemAccess;
this.delegate = delegate;
}
@@ -56,11 +56,11 @@ public void visitDestroyable(File destroyableRoot) {
}
});
ImmutableList<String> outputsToBeChanged = builder.build();
- outputChangeListener.invalidateCachesFor(outputsToBeChanged);
+ fileSystemAccess.write(outputsToBeChanged, () -> {});
try {
return delegate.execute(work, new ChangingOutputsContext(context));
} finally {
- outputChangeListener.invalidateCachesFor(outputsToBeChanged);
+ fileSystemAccess.write(outputsToBeChanged, () -> {});
}
}
}
diff --git a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BuildCacheStep.java b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BuildCacheStep.java
index fbe0833f2ed..4dbf80e5b41 100644
--- a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BuildCacheStep.java
+++ b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/BuildCacheStep.java
@@ -26,7 +26,6 @@
import org.gradle.internal.Try;
import org.gradle.internal.execution.ExecutionEngine.Execution;
import org.gradle.internal.execution.MutableUnitOfWork;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.history.BeforeExecutionState;
import org.gradle.internal.execution.history.ExecutionOutputState;
@@ -52,20 +51,17 @@ public class BuildCacheStep implements Step<IncrementalChangesContext, AfterExec
private final BuildCacheController buildCache;
private final Deleter deleter;
private final FileSystemAccess fileSystemAccess;
- private final OutputChangeListener outputChangeListener;
private final Step<? super IncrementalChangesContext, ? extends AfterExecutionResult> delegate;
public BuildCacheStep(
BuildCacheController buildCache,
Deleter deleter,
FileSystemAccess fileSystemAccess,
- OutputChangeListener outputChangeListener,
Step<? super IncrementalChangesContext, ? extends AfterExecutionResult> delegate
) {
this.buildCache = buildCache;
this.deleter = deleter;
this.fileSystemAccess = fileSystemAccess;
- this.outputChangeListener = outputChangeListener;
this.delegate = delegate;
}
@@ -126,12 +122,13 @@ private void cleanLocalState(File workspace, UnitOfWork work) {
work.visitOutputs(workspace, new UnitOfWork.OutputVisitor() {
@Override
public void visitLocalState(File localStateRoot) {
- try {
- outputChangeListener.invalidateCachesFor(ImmutableList.of(localStateRoot.getAbsolutePath()));
- deleter.deleteRecursively(localStateRoot);
- } catch (IOException ex) {
- throw new UncheckedIOException(String.format("Failed to clean up local state files for %s: %s", work.getDisplayName(), localStateRoot), ex);
- }
+ fileSystemAccess.write(ImmutableList.of(localStateRoot.getAbsolutePath()), () -> {
+ try {
+ deleter.deleteRecursively(localStateRoot);
+ } catch (IOException ex) {
+ throw new UncheckedIOException(String.format("Failed to clean up local state files for %s: %s", work.getDisplayName(), localStateRoot), ex);
+ }
+ });
}
});
}
diff --git a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/HandleStaleOutputsStep.java b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/HandleStaleOutputsStep.java
index 625c8e41570..d1cc1a58fc5 100644
--- a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/HandleStaleOutputsStep.java
+++ b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/HandleStaleOutputsStep.java
@@ -19,7 +19,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Streams;
import org.gradle.internal.execution.BuildOutputCleanupRegistry;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.history.OutputFilesRepository;
import org.gradle.internal.file.Deleter;
@@ -28,6 +27,7 @@
import org.gradle.internal.operations.BuildOperationDescriptor;
import org.gradle.internal.operations.BuildOperationExecutor;
import org.gradle.internal.operations.RunnableBuildOperation;
+import org.gradle.internal.vfs.FileSystemAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,7 +47,7 @@ public class HandleStaleOutputsStep<C extends WorkspaceContext, R extends AfterE
private final BuildOperationExecutor buildOperationExecutor;
private final BuildOutputCleanupRegistry cleanupRegistry;
private final Deleter deleter;
- private final OutputChangeListener outputChangeListener;
+ private final FileSystemAccess fileSystemAccess;
private final OutputFilesRepository outputFilesRepository;
private final Step<? super C, ? extends R> delegate;
@@ -55,14 +55,14 @@ public HandleStaleOutputsStep(
BuildOperationExecutor buildOperationExecutor,
BuildOutputCleanupRegistry cleanupRegistry,
Deleter deleter,
- OutputChangeListener outputChangeListener,
+ FileSystemAccess fileSystemAccess,
OutputFilesRepository outputFilesRepository,
Step<? super C, ? extends R> delegate
) {
this.buildOperationExecutor = buildOperationExecutor;
this.cleanupRegistry = cleanupRegistry;
this.deleter = deleter;
- this.outputChangeListener = outputChangeListener;
+ this.fileSystemAccess = fileSystemAccess;
this.outputFilesRepository = outputFilesRepository;
this.delegate = delegate;
}
@@ -91,27 +91,27 @@ public void visitOutputProperty(String propertyName, TreeType type, UnitOfWork.O
}
});
if (!filesToDelete.isEmpty()) {
- outputChangeListener.invalidateCachesFor(
+ fileSystemAccess.write(
filesToDelete.stream()
.map(File::getAbsolutePath)
- .collect(Collectors.toList())
- );
- buildOperationExecutor.run(new RunnableBuildOperation() {
- @Override
- public void run(BuildOperationContext context) throws IOException {
- for (File file : filesToDelete) {
- LOGGER.info("Deleting stale output file: {}", file.getAbsolutePath());
- deleter.deleteRecursively(file);
+ .collect(Collectors.toList()),
+ () -> buildOperationExecutor.run(new RunnableBuildOperation() {
+ @Override
+ public void run(BuildOperationContext context) throws IOException {
+ for (File file : filesToDelete) {
+ LOGGER.info("Deleting stale output file: {}", file.getAbsolutePath());
+ deleter.deleteRecursively(file);
+ }
}
- }
- @Override
- public BuildOperationDescriptor.Builder description() {
- return BuildOperationDescriptor
- .displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME)
- .progressDisplayName("Cleaning stale outputs");
- }
- });
+ @Override
+ public BuildOperationDescriptor.Builder description() {
+ return BuildOperationDescriptor
+ .displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME)
+ .progressDisplayName("Cleaning stale outputs");
+ }
+ })
+ );
}
}
}
diff --git a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/RemovePreviousOutputsStep.java b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/RemovePreviousOutputsStep.java
index 02af7321f4b..9c14beae31f 100644
--- a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/RemovePreviousOutputsStep.java
+++ b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/RemovePreviousOutputsStep.java
@@ -16,7 +16,6 @@
package org.gradle.internal.execution.steps;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.history.BeforeExecutionState;
import org.gradle.internal.execution.history.OutputsCleaner;
@@ -24,6 +23,7 @@
import org.gradle.internal.file.TreeType;
import org.gradle.internal.snapshot.FileSystemSnapshot;
import org.gradle.internal.snapshot.SnapshotUtil;
+import org.gradle.internal.vfs.FileSystemAccess;
import java.io.File;
import java.io.IOException;
@@ -37,16 +37,16 @@
public class RemovePreviousOutputsStep<C extends ChangingOutputsContext, R extends Result> implements Step<C, R> {
private final Deleter deleter;
- private final OutputChangeListener outputChangeListener;
+ private final FileSystemAccess fileSystemAccess;
private final Step<? super C, ? extends R> delegate;
public RemovePreviousOutputsStep(
Deleter deleter,
- OutputChangeListener outputChangeListener,
+ FileSystemAccess fileSystemAccess,
Step<? super C, ? extends R> delegate
) {
this.deleter = deleter;
- this.outputChangeListener = outputChangeListener;
+ this.fileSystemAccess = fileSystemAccess;
this.delegate = delegate;
}
@@ -94,14 +94,16 @@ public void visitOutputProperty(String propertyName, TreeType type, UnitOfWork.O
file -> true,
dir -> !outputDirectoriesToPreserve.contains(dir)
);
+ // TODO Use FileSystemSnapshot.roots() for faster processing
for (FileSystemSnapshot snapshot : previousOutputs.getOutputFilesProducedByWork().values()) {
- try {
- // Previous outputs can be in a different place than the current outputs
- outputChangeListener.invalidateCachesFor(SnapshotUtil.rootIndex(snapshot).keySet());
- cleaner.cleanupOutputs(snapshot);
- } catch (IOException e) {
- throw new UncheckedIOException("Failed to clean up output files for " + work.getDisplayName(), e);
- }
+ fileSystemAccess.write(SnapshotUtil.rootIndex(snapshot).keySet(), () -> {
+ try {
+ // Previous outputs can be in a different place than the current outputs
+ cleaner.cleanupOutputs(snapshot);
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to clean up output files for " + work.getDisplayName(), e);
+ }
+ });
}
});
}
diff --git a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStep.java b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStep.java
index d92669a3bcf..7d292d1024a 100644
--- a/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStep.java
+++ b/platforms/core-execution/execution/src/main/java/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStep.java
@@ -19,7 +19,6 @@
import com.google.common.collect.ImmutableSortedMap;
import org.gradle.internal.execution.ExecutionEngine.Execution;
import org.gradle.internal.execution.ExecutionEngine.ExecutionOutcome;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.WorkInputListeners;
import org.gradle.internal.execution.history.ExecutionInputState;
@@ -32,6 +31,7 @@
import org.gradle.internal.snapshot.ValueSnapshot;
import org.gradle.internal.time.Time;
import org.gradle.internal.time.Timer;
+import org.gradle.internal.vfs.FileSystemAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,22 +39,23 @@
import java.io.UncheckedIOException;
import java.time.Duration;
import java.util.Map;
+import java.util.Set;
import java.util.function.Supplier;
public class SkipEmptyIncrementalWorkStep extends AbstractSkipEmptyWorkStep<PreviousExecutionContext> {
private static final Logger LOGGER = LoggerFactory.getLogger(SkipEmptyIncrementalWorkStep.class);
- private final OutputChangeListener outputChangeListener;
+ private final FileSystemAccess fileSystemAccess;
private final Supplier<OutputsCleaner> outputsCleanerSupplier;
public SkipEmptyIncrementalWorkStep(
- OutputChangeListener outputChangeListener,
+ FileSystemAccess fileSystemAccess,
WorkInputListeners workInputListeners,
Supplier<OutputsCleaner> outputsCleanerSupplier,
Step<? super PreviousExecutionContext, ? extends CachingResult> delegate
) {
super(workInputListeners, delegate);
- this.outputChangeListener = outputChangeListener;
+ this.fileSystemAccess = fileSystemAccess;
this.outputsCleanerSupplier = outputsCleanerSupplier;
}
@@ -111,12 +112,14 @@ protected CachingResult performSkip(UnitOfWork work, PreviousExecutionContext co
private boolean cleanPreviousOutputs(Map<String, FileSystemSnapshot> outputFileSnapshots) {
OutputsCleaner outputsCleaner = outputsCleanerSupplier.get();
for (FileSystemSnapshot outputFileSnapshot : outputFileSnapshots.values()) {
- try {
- outputChangeListener.invalidateCachesFor(SnapshotUtil.rootIndex(outputFileSnapshot).keySet());
- outputsCleaner.cleanupOutputs(outputFileSnapshot);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
+ Set<String> rootsToBeDeleted = SnapshotUtil.rootIndex(outputFileSnapshot).keySet();
+ fileSystemAccess.write(rootsToBeDeleted, () -> {
+ try {
+ outputsCleaner.cleanupOutputs(outputFileSnapshot);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ });
}
return outputsCleaner.getDidWork();
}
diff --git a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BroadcastChangingOutputsStepTest.groovy b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BroadcastChangingOutputsStepTest.groovy
index b81ecfa5c8b..e92de49a42a 100644
--- a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BroadcastChangingOutputsStepTest.groovy
+++ b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BroadcastChangingOutputsStepTest.groovy
@@ -17,15 +17,15 @@
package org.gradle.internal.execution.steps
import org.gradle.api.file.FileCollection
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.UnitOfWork
import org.gradle.internal.file.TreeType
+import org.gradle.internal.vfs.FileSystemAccess
class BroadcastChangingOutputsStepTest extends StepSpec<InputChangesContext> {
- def outputChangeListener = Mock(OutputChangeListener)
+ def fileSystemAccess = Mock(FileSystemAccess)
def delegateResult = Stub(Result)
- def step = new BroadcastChangingOutputsStep<>(outputChangeListener, delegate)
+ def step = new BroadcastChangingOutputsStep<>(fileSystemAccess, delegate)
def "notifies listener about specific outputs changing"() {
def outputDir = file("output-dir")
@@ -48,12 +48,12 @@ class BroadcastChangingOutputsStepTest extends StepSpec<InputChangesContext> {
}
then:
- 1 * outputChangeListener.invalidateCachesFor(changingOutputs)
+ 1 * fileSystemAccess.write(changingOutputs, _ as Runnable)
then:
1 * delegate.execute(work, _ as ChangingOutputsContext) >> delegateResult
then:
- 1 * outputChangeListener.invalidateCachesFor(changingOutputs)
+ 1 * fileSystemAccess.write(changingOutputs, _ as Runnable)
then:
0 * _
}
diff --git a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BuildCacheStepTest.groovy b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BuildCacheStepTest.groovy
index 16f96f35a8d..de9133939cf 100644
--- a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BuildCacheStepTest.groovy
+++ b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/BuildCacheStepTest.groovy
@@ -22,7 +22,6 @@ import org.gradle.caching.internal.controller.BuildCacheController
import org.gradle.caching.internal.controller.service.BuildCacheLoadResult
import org.gradle.caching.internal.origin.OriginMetadata
import org.gradle.internal.Try
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.UnitOfWork
import org.gradle.internal.execution.caching.CachingDisabledReason
import org.gradle.internal.execution.caching.CachingDisabledReasonCategory
@@ -49,9 +48,8 @@ class BuildCacheStepTest extends StepSpec<IncrementalChangesContext> implements
def loadMetadata = Mock(BuildCacheLoadResult)
def deleter = Mock(Deleter)
def fileSystemAccess = Mock(FileSystemAccess)
- def outputChangeListener = Mock(OutputChangeListener)
- def step = new BuildCacheStep(buildCacheController, deleter, fileSystemAccess, outputChangeListener, delegate)
+ def step = new BuildCacheStep(buildCacheController, deleter, fileSystemAccess, delegate)
def delegateResult = Mock(AfterExecutionResult)
def "loads from cache"() {
@@ -79,7 +77,9 @@ class BuildCacheStepTest extends StepSpec<IncrementalChangesContext> implements
_ * work.visitOutputs(_ as File, _ as UnitOfWork.OutputVisitor) >> { File workspace, UnitOfWork.OutputVisitor visitor ->
visitor.visitLocalState(localStateFile)
}
- 1 * outputChangeListener.invalidateCachesFor([localStateFile.getAbsolutePath()])
+ 1 * fileSystemAccess.write([localStateFile.getAbsolutePath()], _ as Runnable) >> { Iterable<String> locations, Runnable action -> action.run() }
+
+ then:
1 * deleter.deleteRecursively(_) >> { File root ->
assert root == localStateFile
return true
diff --git a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/HandleStaleOutputsStepTest.groovy b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/HandleStaleOutputsStepTest.groovy
index 6d2992a9511..762cc6a5412 100644
--- a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/HandleStaleOutputsStepTest.groovy
+++ b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/HandleStaleOutputsStepTest.groovy
@@ -18,24 +18,24 @@ package org.gradle.internal.execution.steps
import org.gradle.api.internal.file.TestFiles
import org.gradle.internal.execution.BuildOutputCleanupRegistry
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.UnitOfWork
import org.gradle.internal.execution.history.AfterExecutionState
import org.gradle.internal.execution.history.OutputFilesRepository
import org.gradle.internal.file.Deleter
import org.gradle.internal.file.TreeType
+import org.gradle.internal.vfs.FileSystemAccess
class HandleStaleOutputsStepTest extends StepSpec<WorkspaceContext> implements SnapshotterFixture {
def cleanupRegistry = Mock(BuildOutputCleanupRegistry)
def deleter = Mock(Deleter)
- def outputChangeListener = Mock(OutputChangeListener)
+ def fileSystemAccess = Mock(FileSystemAccess)
def outputFilesRepository = Mock(OutputFilesRepository)
def step = new HandleStaleOutputsStep<>(
buildOperationExecutor,
cleanupRegistry,
deleter,
- outputChangeListener,
+ fileSystemAccess,
outputFilesRepository,
delegate)
@@ -67,9 +67,9 @@ class HandleStaleOutputsStepTest extends StepSpec<WorkspaceContext> implements S
then:
if (cleanedUp) {
- 1 * outputChangeListener.invalidateCachesFor({ Iterable<String> paths ->
- paths ==~ [target.absolutePath]
- })
+ 1 * fileSystemAccess.write([target.absolutePath], _ as Runnable) >> { Iterable<String> locations, Runnable action ->
+ action.run()
+ }
1 * deleter.deleteRecursively(target)
}
diff --git a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/RemovePreviousOutputsStepTest.groovy b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/RemovePreviousOutputsStepTest.groovy
index b5710206e32..a756b9653d5 100644
--- a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/RemovePreviousOutputsStepTest.groovy
+++ b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/RemovePreviousOutputsStepTest.groovy
@@ -18,7 +18,6 @@ package org.gradle.internal.execution.steps
import com.google.common.collect.ImmutableSortedMap
import org.gradle.api.internal.file.TestFiles
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.UnitOfWork
import org.gradle.internal.execution.UnitOfWork.OutputVisitor
import org.gradle.internal.execution.history.BeforeExecutionState
@@ -26,6 +25,7 @@ import org.gradle.internal.execution.history.OverlappingOutputs
import org.gradle.internal.execution.history.PreviousExecutionState
import org.gradle.internal.file.TreeType
import org.gradle.internal.snapshot.FileSystemSnapshot
+import org.gradle.internal.vfs.FileSystemAccess
import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider
import org.junit.Rule
@@ -35,10 +35,10 @@ class RemovePreviousOutputsStepTest extends StepSpec<ChangingOutputsContext> imp
def previousExecutionState = Mock(PreviousExecutionState)
def beforeExecutionState = Mock(BeforeExecutionState)
def delegateResult = Mock(Result)
- def outputChangeListener = Mock(OutputChangeListener)
+ def fileSystemAccess = Mock(FileSystemAccess)
def deleter = TestFiles.deleter()
- def step = new RemovePreviousOutputsStep<>(deleter, outputChangeListener, delegate)
+ def step = new RemovePreviousOutputsStep<>(deleter, fileSystemAccess, delegate)
def "deletes only the previous outputs"() {
@@ -185,8 +185,12 @@ class RemovePreviousOutputsStepTest extends StepSpec<ChangingOutputsContext> imp
}
_ * context.previousExecutionState >> Optional.of(previousExecutionState)
1 * previousExecutionState.outputFilesProducedByWork >> ImmutableSortedMap.of("dir", outputs.dirSnapshot, "file", outputs.fileSnapshot)
- 1 * outputChangeListener.invalidateCachesFor({ Iterable<String> paths -> paths as List == [outputs.dir.absolutePath] })
- 1 * outputChangeListener.invalidateCachesFor({ Iterable<String> paths -> paths as List == [outputs.file.absolutePath] })
+ 1 * fileSystemAccess.write({ Iterable<String> paths -> paths as List == [outputs.dir.absolutePath] }, _ as Runnable) >> { Iterable<String> locations, Runnable action ->
+ action.run()
+ }
+ 1 * fileSystemAccess.write({ Iterable<String> paths -> paths as List == [outputs.file.absolutePath] }, _) >> { Iterable<String> locations, Runnable action ->
+ action.run()
+ }
}
void cleanupExclusiveOutputs(WorkOutputs outputs, boolean incrementalExecution = false) {
diff --git a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStepTest.groovy b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStepTest.groovy
index 2d96cebae3f..868bd8a513d 100644
--- a/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStepTest.groovy
+++ b/platforms/core-execution/execution/src/test/groovy/org/gradle/internal/execution/steps/SkipEmptyIncrementalWorkStepTest.groovy
@@ -18,23 +18,23 @@ package org.gradle.internal.execution.steps
import com.google.common.collect.ImmutableSet
import com.google.common.collect.ImmutableSortedMap
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.history.OutputsCleaner
import org.gradle.internal.execution.history.PreviousExecutionState
import org.gradle.internal.execution.impl.DefaultInputFingerprinter
import org.gradle.internal.snapshot.FileSystemSnapshot
+import org.gradle.internal.vfs.FileSystemAccess
import static org.gradle.internal.execution.ExecutionEngine.ExecutionOutcome.EXECUTED_NON_INCREMENTALLY
import static org.gradle.internal.execution.ExecutionEngine.ExecutionOutcome.SHORT_CIRCUITED
class SkipEmptyIncrementalWorkStepTest extends AbstractSkipEmptyWorkStepTest<PreviousExecutionContext> implements SnapshotterFixture {
- def outputChangeListener = Mock(OutputChangeListener)
+ def fileSystemAccess = Mock(FileSystemAccess)
def outputsCleaner = Mock(OutputsCleaner)
@Override
protected AbstractSkipEmptyWorkStep createStep() {
new SkipEmptyIncrementalWorkStep(
- outputChangeListener,
+ fileSystemAccess,
workInputListeners,
{ -> outputsCleaner },
delegate)
@@ -53,7 +53,9 @@ class SkipEmptyIncrementalWorkStepTest extends AbstractSkipEmptyWorkStepTest<Pre
}
and:
- 1 * outputChangeListener.invalidateCachesFor(rootPaths(previousOutputFile))
+ 1 * fileSystemAccess.write(rootPaths(previousOutputFile), _ as Runnable) >> { Iterable<String> locations, Runnable action ->
+ action.run()
+ }
and:
1 * outputsCleaner.cleanupOutputs(outputFileSnapshot)
@@ -88,7 +90,9 @@ class SkipEmptyIncrementalWorkStepTest extends AbstractSkipEmptyWorkStepTest<Pre
}
and:
- 1 * outputChangeListener.invalidateCachesFor(rootPaths(previousOutputFile))
+ 1 * fileSystemAccess.write(rootPaths(previousOutputFile), _ as Runnable) >> { Iterable<String> locations, Runnable action ->
+ action.run()
+ }
and:
1 * outputsCleaner.cleanupOutputs(outputFileSnapshot) >> { throw ioException }
diff --git a/platforms/core-execution/execution/src/testFixtures/groovy/org/gradle/internal/execution/TestExecutionEngineFactory.java b/platforms/core-execution/execution/src/testFixtures/groovy/org/gradle/internal/execution/TestExecutionEngineFactory.java
index 2b7d854a25e..caade431f8d 100644
--- a/platforms/core-execution/execution/src/testFixtures/groovy/org/gradle/internal/execution/TestExecutionEngineFactory.java
+++ b/platforms/core-execution/execution/src/testFixtures/groovy/org/gradle/internal/execution/TestExecutionEngineFactory.java
@@ -41,6 +41,7 @@
import org.gradle.internal.hash.ClassLoaderHierarchyHasher;
import org.gradle.internal.id.UniqueId;
import org.gradle.internal.operations.BuildOperationExecutor;
+import org.gradle.internal.vfs.FileSystemAccess;
import org.gradle.internal.vfs.VirtualFileSystem;
import static org.gradle.internal.execution.steps.AfterExecutionOutputFilter.NO_FILTER;
@@ -58,7 +59,7 @@ public static ExecutionEngine createExecutionEngine(
ClassLoaderHierarchyHasher classloaderHierarchyHasher,
Deleter deleter,
ExecutionStateChangeDetector changeDetector,
- OutputChangeListener outputChangeListener,
+ FileSystemAccess fileSystemAccess,
OutputSnapshotter outputSnapshotter,
OverlappingOutputDetector overlappingOutputDetector,
Problems problems,
@@ -79,9 +80,9 @@ public static ExecutionEngine createExecutionEngine(
new StoreExecutionStateStep<>(
new ResolveInputChangesStep<>(
new CaptureOutputsAfterExecutionStep<>(buildOperationExecutor, buildId, outputSnapshotter, NO_FILTER,
- new BroadcastChangingOutputsStep<>(outputChangeListener,
+ new BroadcastChangingOutputsStep<>(fileSystemAccess,
new PreCreateOutputParentsStep<>(
- new RemovePreviousOutputsStep<>(deleter, outputChangeListener,
+ new RemovePreviousOutputsStep<>(deleter, fileSystemAccess,
new ExecuteStep<>(buildOperationExecutor
)))))))))))))))));
// @formatter:on
diff --git a/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/DependencyManagementBuildScopeServices.java b/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/DependencyManagementBuildScopeServices.java
index 0d71a109db2..426cfe20ee5 100644
--- a/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/DependencyManagementBuildScopeServices.java
+++ b/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/DependencyManagementBuildScopeServices.java
@@ -108,14 +108,12 @@
import org.gradle.internal.event.ListenerManager;
import org.gradle.internal.execution.ExecutionEngine;
import org.gradle.internal.execution.InputFingerprinter;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.execution.OutputSnapshotter;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.caching.CachingState;
import org.gradle.internal.execution.impl.DefaultExecutionEngine;
import org.gradle.internal.execution.steps.AssignImmutableWorkspaceStep;
import org.gradle.internal.execution.steps.BeforeExecutionContext;
-import org.gradle.internal.execution.steps.BroadcastChangingOutputsStep;
import org.gradle.internal.execution.steps.CachingContext;
import org.gradle.internal.execution.steps.CachingResult;
import org.gradle.internal.execution.steps.CaptureOutputsAfterExecutionStep;
@@ -123,6 +121,7 @@
import org.gradle.internal.execution.steps.IdentifyStep;
import org.gradle.internal.execution.steps.IdentityCacheStep;
import org.gradle.internal.execution.steps.NeverUpToDateStep;
+import org.gradle.internal.execution.steps.NoBroadcastChangingOutputsStep;
import org.gradle.internal.execution.steps.NoInputChangesStep;
import org.gradle.internal.execution.steps.PreCreateOutputParentsStep;
import org.gradle.internal.execution.steps.PreviousExecutionContext;
@@ -477,7 +476,6 @@ ExecutionEngine createExecutionEngine(
BuildOperationExecutor buildOperationExecutor,
CurrentBuildOperationRef currentBuildOperationRef,
FileSystemAccess fileSystemAccess,
- ListenerManager listenerManager,
OriginMetadataFactory originMetadataFactory,
OutputSnapshotter outputSnapshotter,
TimeoutHandler timeoutHandler,
@@ -485,7 +483,6 @@ ExecutionEngine createExecutionEngine(
VirtualFileSystem virtualFileSystem,
Problems problems
) {
- OutputChangeListener outputChangeListener = listenerManager.getBroadcaster(OutputChangeListener.class);
// @formatter:off
return new DefaultExecutionEngine(problems,
new IdentifyStep<>(buildOperationExecutor,
@@ -497,8 +494,8 @@ ExecutionEngine createExecutionEngine(
new NeverUpToDateStep<>(
new NoInputChangesStep<>(
new CaptureOutputsAfterExecutionStep<>(buildOperationExecutor, buildInvocationScopeId.getId(), outputSnapshotter, NO_FILTER,
+ new NoBroadcastChangingOutputsStep<>(
// TODO Use a shared execution pipeline
- new BroadcastChangingOutputsStep<>(outputChangeListener,
new PreCreateOutputParentsStep<>(
new TimeoutStep<>(timeoutHandler, currentBuildOperationRef,
new ExecuteStep<>(buildOperationExecutor
diff --git a/subprojects/core/src/main/java/org/gradle/cache/internal/DefaultFileContentCacheFactory.java b/subprojects/core/src/main/java/org/gradle/cache/internal/DefaultFileContentCacheFactory.java
index f48e385f3e9..99cfad0e3ba 100644
--- a/subprojects/core/src/main/java/org/gradle/cache/internal/DefaultFileContentCacheFactory.java
+++ b/subprojects/core/src/main/java/org/gradle/cache/internal/DefaultFileContentCacheFactory.java
@@ -17,13 +17,12 @@
package org.gradle.cache.internal;
import org.gradle.cache.FileLockManager;
-import org.gradle.cache.PersistentCache;
import org.gradle.cache.IndexedCache;
import org.gradle.cache.IndexedCacheParameters;
+import org.gradle.cache.PersistentCache;
import org.gradle.cache.scopes.ScopedCacheBuilderFactory;
import org.gradle.internal.Cast;
import org.gradle.internal.event.ListenerManager;
-import org.gradle.internal.execution.OutputChangeListener;
import org.gradle.internal.hash.HashCode;
import org.gradle.internal.serialize.HashCodeSerializer;
import org.gradle.internal.serialize.Serializer;
@@ -88,7 +87,7 @@ public <V> FileContentCache<V> newCache(String name, int normalizedCacheSize, fi
*
* The second level indexes on the hash of file content and contains the value that was calculated from a file with the given hash.
*/
- private static class DefaultFileContentCache<V> implements FileContentCache<V>, OutputChangeListener {
+ private static class DefaultFileContentCache<V> implements FileContentCache<V>, FileSystemAccess.WriteListener {
private final Map<File, V> locationCache = new ConcurrentHashMap<>();
private final String name;
private final FileSystemAccess fileSystemAccess;
@@ -103,7 +102,7 @@ private static class DefaultFileContentCache<V> implements FileContentCache<V>,
}
@Override
- public void invalidateCachesFor(Iterable<String> affectedOutputPaths) {
+ public void locationsWritten(Iterable<String> locations) {
// A very dumb strategy for invalidating cache
locationCache.clear();
}
diff --git a/subprojects/core/src/main/java/org/gradle/internal/service/scopes/ExecutionGradleServices.java b/subprojects/core/src/main/java/org/gradle/internal/service/scopes/ExecutionGradleServices.java
index b6b26d6a226..b1acaaa0b1c 100644
--- a/subprojects/core/src/main/java/org/gradle/internal/service/scopes/ExecutionGradleServices.java
+++ b/subprojects/core/src/main/java/org/gradle/internal/service/scopes/ExecutionGradleServices.java
@@ -59,6 +59,7 @@
import org.gradle.internal.execution.steps.IdentityContext;
import org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep;
import org.gradle.internal.execution.steps.NeverUpToDateStep;
+import org.gradle.internal.execution.steps.NoBroadcastChangingOutputsStep;
import org.gradle.internal.execution.steps.NoInputChangesStep;
import org.gradle.internal.execution.steps.OverlappingOutputsFilter;
import org.gradle.internal.execution.steps.PreCreateOutputParentsStep;
@@ -140,7 +141,6 @@ public ExecutionEngine createExecutionEngine(
ExecutionStateChangeDetector changeDetector,
FileSystemAccess fileSystemAccess,
OriginMetadataFactory originMetadataFactory,
- OutputChangeListener outputChangeListener,
WorkInputListeners workInputListeners, OutputFilesRepository outputFilesRepository,
OutputSnapshotter outputSnapshotter,
OverlappingOutputDetector overlappingOutputDetector,
@@ -171,19 +171,19 @@ public ExecutionEngine createExecutionEngine(
new ResolveCachingStateStep<>(buildCacheController, gradleEnterprisePluginManager.isPresent(),
new MarkSnapshottingInputsFinishedStep<>(
new NeverUpToDateStep<>(
- new BuildCacheStep(buildCacheController, deleter, fileSystemAccess, outputChangeListener,
+ new BuildCacheStep(buildCacheController, deleter, fileSystemAccess,
new CaptureOutputsAfterExecutionStep<>(buildOperationExecutor, buildInvocationScopeId.getId(), outputSnapshotter, NO_FILTER,
new NoInputChangesStep<>(
- new BroadcastChangingOutputsStep<>(outputChangeListener,
+ new NoBroadcastChangingOutputsStep<>(
sharedExecutionPipeline
)))))))))))));
Step<IdentityContext,WorkspaceResult> mutablePipeline =
new AssignMutableWorkspaceStep<>(
- new HandleStaleOutputsStep<>(buildOperationExecutor, buildOutputCleanupRegistry, deleter, outputChangeListener, outputFilesRepository,
+ new HandleStaleOutputsStep<>(buildOperationExecutor, buildOutputCleanupRegistry, deleter, fileSystemAccess, outputFilesRepository,
new LoadPreviousExecutionStateStep<>(
new MarkSnapshottingInputsStartedStep<>(
- new SkipEmptyIncrementalWorkStep(outputChangeListener, workInputListeners, skipEmptyWorkOutputsCleanerSupplier,
+ new SkipEmptyIncrementalWorkStep(fileSystemAccess, workInputListeners, skipEmptyWorkOutputsCleanerSupplier,
new CaptureStateBeforeExecutionStep<>(buildOperationExecutor, classLoaderHierarchyHasher, outputSnapshotter, overlappingOutputDetector,
new ValidateStep<>(virtualFileSystem, validationWarningRecorder,
new ResolveCachingStateStep<>(buildCacheController, gradleEnterprisePluginManager.isPresent(),
@@ -191,11 +191,11 @@ public ExecutionEngine createExecutionEngine(
new ResolveChangesStep<>(changeDetector,
new SkipUpToDateStep<>(
new StoreExecutionStateStep<>(
- new BuildCacheStep(buildCacheController, deleter, fileSystemAccess, outputChangeListener,
+ new BuildCacheStep(buildCacheController, deleter, fileSystemAccess,
new ResolveInputChangesStep<>(
new CaptureOutputsAfterExecutionStep<>(buildOperationExecutor, buildInvocationScopeId.getId(), outputSnapshotter, new OverlappingOutputsFilter(),
- new BroadcastChangingOutputsStep<>(outputChangeListener,
- new RemovePreviousOutputsStep<>(deleter, outputChangeListener,
+ new BroadcastChangingOutputsStep<>(fileSystemAccess,
+ new RemovePreviousOutputsStep<>(deleter, fileSystemAccess,
sharedExecutionPipeline
)))))))))))))))));
diff --git a/subprojects/core/src/main/java/org/gradle/internal/service/scopes/VirtualFileSystemServices.java b/subprojects/core/src/main/java/org/gradle/internal/service/scopes/VirtualFileSystemServices.java
index e1ee06d0c76..f8abce0177b 100644
--- a/subprojects/core/src/main/java/org/gradle/internal/service/scopes/VirtualFileSystemServices.java
+++ b/subprojects/core/src/main/java/org/gradle/internal/service/scopes/VirtualFileSystemServices.java
@@ -340,8 +340,7 @@ FileSystemAccess createFileSystemAccess(
);
listenerManager.addListener(buildSessionsScopedVirtualFileSystem);
- listenerManager.addListener((OutputChangeListener) affectedOutputPaths -> buildSessionsScopedVirtualFileSystem.write(affectedOutputPaths, () -> {
- }));
+ listenerManager.addListener((OutputChangeListener) locations -> buildSessionsScopedVirtualFileSystem.write(locations, () -> {}));
return buildSessionsScopedVirtualFileSystem;
}
diff --git a/subprojects/core/src/test/groovy/org/gradle/api/internal/tasks/execution/ExecuteActionsTaskExecuterTest.groovy b/subprojects/core/src/test/groovy/org/gradle/api/internal/tasks/execution/ExecuteActionsTaskExecuterTest.groovy
index 2b4618758d1..865e3f6490b 100644
--- a/subprojects/core/src/test/groovy/org/gradle/api/internal/tasks/execution/ExecuteActionsTaskExecuterTest.groovy
+++ b/subprojects/core/src/test/groovy/org/gradle/api/internal/tasks/execution/ExecuteActionsTaskExecuterTest.groovy
@@ -39,7 +39,6 @@ import org.gradle.internal.event.ListenerManager
import org.gradle.internal.exceptions.DefaultMultiCauseException
import org.gradle.internal.exceptions.MultiCauseException
import org.gradle.internal.execution.FileCollectionFingerprinterRegistry
-import org.gradle.internal.execution.OutputChangeListener
import org.gradle.internal.execution.TestExecutionEngineFactory
import org.gradle.internal.execution.WorkValidationContext
import org.gradle.internal.execution.history.ExecutionHistoryStore
@@ -121,7 +120,6 @@ class ExecuteActionsTaskExecuterTest extends Specification {
def buildId = UniqueId.generate()
def actionListener = Stub(TaskActionListener)
- def outputChangeListener = Stub(OutputChangeListener)
def changeDetector = new DefaultExecutionStateChangeDetector()
def taskCacheabilityResolver = Mock(TaskCacheabilityResolver)
def buildCacheController = Stub(BuildCacheController)
@@ -149,7 +147,7 @@ class ExecuteActionsTaskExecuterTest extends Specification {
classloaderHierarchyHasher,
deleter,
changeDetector,
- outputChangeListener,
+ fileSystemAccess,
outputSnapshotter,
overlappingOutputDetector,
problems,
diff --git a/subprojects/core/src/testFixtures/groovy/org/gradle/api/internal/file/TestFiles.java b/subprojects/core/src/testFixtures/groovy/org/gradle/api/internal/file/TestFiles.java
index ecd75d2888e..0899cbd7cee 100644
--- a/subprojects/core/src/testFixtures/groovy/org/gradle/api/internal/file/TestFiles.java
+++ b/subprojects/core/src/testFixtures/groovy/org/gradle/api/internal/file/TestFiles.java
@@ -280,5 +280,4 @@ public static String systemSpecificAbsolutePath(String path) {
public static TemporaryFileProvider tmpDirTemporaryFileProvider(File baseDir) {
return new DefaultTemporaryFileProvider(() -> baseDir);
}
-
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment