use of org.gradle.internal.file.TreeType 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);
}
}
});
}
Aggregations