Search in sources :

Example 1 with TreeType

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);
            }
        }
    });
}
Also used : OutputsCleaner(org.gradle.internal.execution.history.OutputsCleaner) UnitOfWork(org.gradle.internal.execution.UnitOfWork) TreeType(org.gradle.internal.file.TreeType) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileCollection(org.gradle.api.file.FileCollection) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 HashSet (java.util.HashSet)1 FileCollection (org.gradle.api.file.FileCollection)1 UnitOfWork (org.gradle.internal.execution.UnitOfWork)1 OutputsCleaner (org.gradle.internal.execution.history.OutputsCleaner)1 TreeType (org.gradle.internal.file.TreeType)1 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)1