Skip to content

Commit dad5dc6

Browse files
committed
Try to fix NestedFileSystemProviderTests on Windows
See gh-7161
1 parent d22969a commit dad5dc6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/NestedFileSystemProviderTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
import java.nio.file.attribute.BasicFileAttributeView;
3131
import java.nio.file.attribute.BasicFileAttributes;
3232
import java.nio.file.spi.FileSystemProvider;
33+
import java.util.ArrayList;
3334
import java.util.Collections;
35+
import java.util.List;
3436
import java.util.Set;
3537

38+
import org.junit.jupiter.api.AfterEach;
3639
import org.junit.jupiter.api.BeforeEach;
3740
import org.junit.jupiter.api.Test;
3841
import org.junit.jupiter.api.io.TempDir;
@@ -69,6 +72,11 @@ void setup() throws Exception {
6972
this.uriPrefix = "nested:" + this.file.toURI().getPath() + "/!";
7073
}
7174

75+
@AfterEach
76+
void cleanUp() {
77+
this.provider.cleanUp();
78+
}
79+
7280
@Test
7381
void getSchemeReturnsScheme() {
7482
assertThat(this.provider.getScheme()).isEqualTo("nested");
@@ -259,6 +267,8 @@ static class TestNestedFileSystemProvider extends NestedFileSystemProvider {
259267

260268
private Path mockJarPath;
261269

270+
private List<Path> paths = new ArrayList<>();
271+
262272
@Override
263273
protected Path getJarPath(Path path) {
264274
return (this.mockJarPath != null) ? this.mockJarPath : super.getJarPath(path);
@@ -268,6 +278,24 @@ void setMockJarPath(Path mockJarPath) {
268278
this.mockJarPath = mockJarPath;
269279
}
270280

281+
@Override
282+
public Path getPath(URI uri) {
283+
Path path = super.getPath(uri);
284+
this.paths.add(path);
285+
return path;
286+
}
287+
288+
private void cleanUp() {
289+
this.paths.forEach((path) -> {
290+
try {
291+
Path.of(path.toUri()).getFileSystem().close();
292+
}
293+
catch (Exception ex) {
294+
// Ignore
295+
}
296+
});
297+
}
298+
271299
}
272300

273301
}

0 commit comments

Comments
 (0)