Skip to content

Commit c3bc32d

Browse files
committed
Polish and reinstate usage of FileSystemUtils.deleteRecursively
Closes gh-9942
1 parent c4aba91 commit c3bc32d

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/JarFileRemoteApplicationLauncher.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ public class JarFileRemoteApplicationLauncher extends RemoteApplicationLauncher
4242
@Override
4343
protected String createApplicationClassPath() throws Exception {
4444
File appDirectory = new File("target/app");
45-
if (appDirectory.isDirectory()) {
46-
FileSystemUtils.deleteRecursively(appDirectory.toPath());
47-
if (appDirectory.isDirectory()) {
48-
throw new IllegalStateException(
49-
"Failed to delete '" + appDirectory.getAbsolutePath() + "'");
50-
}
45+
if (appDirectory.isDirectory()
46+
&& !FileSystemUtils.deleteRecursively(appDirectory.toPath())) {
47+
throw new IllegalStateException(
48+
"Failed to delete '" + appDirectory.getAbsolutePath() + "'");
5149
}
5250
appDirectory.mkdirs();
5351
Manifest manifest = new Manifest();

spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.io.InputStream;
22-
import java.nio.file.FileVisitOption;
23-
import java.nio.file.Files;
24-
import java.nio.file.Path;
25-
import java.util.Comparator;
2622
import java.util.concurrent.Callable;
2723
import java.util.concurrent.Executors;
2824
import java.util.concurrent.Future;
@@ -39,6 +35,7 @@
3935
import org.springframework.core.io.DefaultResourceLoader;
4036
import org.springframework.core.io.Resource;
4137
import org.springframework.core.io.support.ResourcePatternUtils;
38+
import org.springframework.util.FileSystemUtils;
4239
import org.springframework.util.StreamUtils;
4340

4441
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,16 +51,14 @@ public class SampleIntegrationApplicationTests {
5451
private ConfigurableApplicationContext context;
5552

5653
@Before
57-
public void deleteInputAndOutput() throws InterruptedException, IOException {
54+
public void deleteInputAndOutput() throws InterruptedException {
5855
deleteIfExists(new File("target/input"));
5956
deleteIfExists(new File("target/output"));
6057
}
6158

62-
private void deleteIfExists(File directory) throws InterruptedException, IOException {
59+
private void deleteIfExists(File directory) throws InterruptedException {
6360
if (directory.exists()) {
64-
Files.walk(directory.toPath(), FileVisitOption.FOLLOW_LINKS)
65-
.sorted(Comparator.reverseOrder()).map(Path::toFile)
66-
.forEach(File::delete);
61+
assertThat(FileSystemUtils.deleteRecursively(directory)).isTrue();
6762
}
6863
}
6964

0 commit comments

Comments
 (0)