use of org.gradle.internal.file.Deleter in project gradle by gradle.
the class SyncCopyActionDecorator method execute.
@Override
public WorkResult execute(final CopyActionProcessingStream stream) {
final Set<RelativePath> visited = new HashSet<>();
WorkResult didWork = delegate.execute(action -> stream.process(details -> {
visited.add(details.getRelativePath());
action.processFile(details);
}));
SyncCopyActionDecoratorFileVisitor fileVisitor = new SyncCopyActionDecoratorFileVisitor(visited, preserveSpec, deleter);
MinimalFileTree walker = directoryFileTreeFactory.create(baseDestDir).postfix();
walker.visit(fileVisitor);
visited.clear();
return WorkResults.didWork(didWork.getDidWork() || fileVisitor.didWork);
}
use of org.gradle.internal.file.Deleter 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.file.Deleter in project gradle by gradle.
the class DefaultFileOperations method createSimple.
public static DefaultFileOperations createSimple(FileResolver fileResolver, FileCollectionFactory fileTreeFactory, ServiceRegistry services) {
Instantiator instantiator = services.get(Instantiator.class);
ObjectFactory objectFactory = services.get(ObjectFactory.class);
FileSystem fileSystem = services.get(FileSystem.class);
DirectoryFileTreeFactory directoryFileTreeFactory = services.get(DirectoryFileTreeFactory.class);
StreamHasher streamHasher = services.get(StreamHasher.class);
FileHasher fileHasher = services.get(FileHasher.class);
ApiTextResourceAdapter.Factory textResourceAdapterFactory = services.get(ApiTextResourceAdapter.Factory.class);
Factory<PatternSet> patternSetFactory = services.getFactory(PatternSet.class);
Deleter deleter = services.get(Deleter.class);
DocumentationRegistry documentationRegistry = services.get(DocumentationRegistry.class);
ProviderFactory providers = services.get(ProviderFactory.class);
DefaultResourceHandler.Factory resourceHandlerFactory = DefaultResourceHandler.Factory.from(fileResolver, fileSystem, null, textResourceAdapterFactory);
return new DefaultFileOperations(fileResolver, null, instantiator, directoryFileTreeFactory, streamHasher, fileHasher, resourceHandlerFactory, fileTreeFactory, objectFactory, fileSystem, patternSetFactory, deleter, documentationRegistry, providers);
}
Aggregations