use of org.gradle.internal.execution.history.OutputsCleaner in project gradle by gradle.
the class RemovePreviousOutputsStep method cleanupOverlappingOutputs.
private void cleanupOverlappingOutputs(BeforeExecutionContext context, UnitOfWork work) {
context.getPreviousExecutionState().ifPresent(previousOutputs -> {
Set<File> outputDirectoriesToPreserve = new HashSet<>();
work.visitOutputs(context.getWorkspace(), new UnitOfWork.OutputVisitor() {
@Override
public void visitOutputProperty(String propertyName, TreeType type, File root, FileCollection contents) {
switch(type) {
case FILE:
File parentFile = root.getParentFile();
if (parentFile != null) {
outputDirectoriesToPreserve.add(parentFile);
}
break;
case DIRECTORY:
outputDirectoriesToPreserve.add(root);
break;
default:
throw new AssertionError();
}
}
});
OutputsCleaner cleaner = new OutputsCleaner(deleter, file -> true, dir -> !outputDirectoriesToPreserve.contains(dir));
for (FileSystemSnapshot snapshot : previousOutputs.getOutputFilesProducedByWork().values()) {
try {
// Previous outputs can be in a different place than the current outputs
outputChangeListener.beforeOutputChange(SnapshotUtil.rootIndex(snapshot).keySet());
cleaner.cleanupOutputs(snapshot);
} catch (IOException e) {
throw new UncheckedIOException("Failed to clean up output files for " + work.getDisplayName(), e);
}
}
});
}
use of org.gradle.internal.execution.history.OutputsCleaner in project gradle by gradle.
the class StaleOutputCleaner method cleanOutputs.
/**
* Clean up the given stale output files under the given directories.
*
* Any files and directories are removed that are descendants of any of the {@code directoriesToClean}.
* Files and directories outside {@code directoriesToClean} and {@code directoriesToClean} themselves are not deleted.
*
* Returns {code true} if any file or directory was deleted, {@code false} otherwise.
*/
@CheckReturnValue
public static boolean cleanOutputs(Deleter deleter, Iterable<File> filesToDelete, ImmutableSet<File> directoriesToClean) {
Set<String> prefixes = directoriesToClean.stream().map(directoryToClean -> directoryToClean.getAbsolutePath() + File.separator).collect(Collectors.toSet());
OutputsCleaner outputsCleaner = new OutputsCleaner(deleter, file -> {
String absolutePath = file.getAbsolutePath();
return prefixes.stream().anyMatch(absolutePath::startsWith);
}, dir -> !directoriesToClean.contains(dir));
try {
for (File f : filesToDelete) {
if (f.isFile()) {
outputsCleaner.cleanupOutput(f, FileType.RegularFile);
}
}
outputsCleaner.cleanupDirectories();
} catch (IOException e) {
throw new UncheckedIOException("Failed to clean up stale outputs", e);
}
return outputsCleaner.getDidWork();
}
use of org.gradle.internal.execution.history.OutputsCleaner in project gradle by gradle.
the class SkipEmptyWorkStep method cleanPreviousTaskOutputs.
private boolean cleanPreviousTaskOutputs(Map<String, FileSystemSnapshot> outputFileSnapshots) {
OutputsCleaner outputsCleaner = outputsCleanerSupplier.get();
for (FileSystemSnapshot outputFileSnapshot : outputFileSnapshots.values()) {
try {
outputChangeListener.beforeOutputChange(SnapshotUtil.rootIndex(outputFileSnapshot).keySet());
outputsCleaner.cleanupOutputs(outputFileSnapshot);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return outputsCleaner.getDidWork();
}
Aggregations