use of org.gradle.api.internal.tasks.properties.FilePropertySpec in project gradle by gradle.
the class CleanupStaleOutputsExecuter method cleanupStaleOutputs.
private void cleanupStaleOutputs(TaskExecutionContext context) {
Set<File> filesToDelete = new HashSet<>();
TaskProperties properties = context.getTaskProperties();
for (FilePropertySpec outputFileSpec : properties.getOutputFileProperties()) {
FileCollection files = outputFileSpec.getPropertyFiles();
for (File file : files) {
if (cleanupRegistry.isOutputOwnedByBuild(file) && !outputFilesRepository.isGeneratedByGradle(file) && file.exists()) {
filesToDelete.add(file);
}
}
}
if (!filesToDelete.isEmpty()) {
outputChangeListener.beforeOutputChange(filesToDelete.stream().map(File::getAbsolutePath).collect(Collectors.toList()));
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) throws IOException {
for (File file : filesToDelete) {
if (file.exists()) {
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");
}
});
}
}
Aggregations