Skip to content

Commit

Permalink
Merge pull request #589 from diffplug/feat/removedDir
Browse files Browse the repository at this point in the history
Help SpotlessTask to handle a removed directory.
  • Loading branch information
nedtwigg authored Jun 1, 2020
2 parents cee4960 + a2157cf commit 294b602
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -240,7 +241,14 @@ private void processInputFile(Formatter formatter, File input) throws IOExceptio

private void deletePreviousResult(File input) throws IOException {
File output = getOutputFile(input);
Files.deleteIfExists(output.toPath());
if (output.isDirectory()) {
Files.walk(output.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} else {
Files.deleteIfExists(output.toPath());
}
}

private File getOutputFile(File input) {
Expand Down

0 comments on commit 294b602

Please sign in to comment.