From dad5dc6750114c10eb314b15c0a05b1e49695e21 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 20 Oct 2023 10:56:08 +0100 Subject: [PATCH] Try to fix NestedFileSystemProviderTests on Windows See gh-7161 --- .../file/NestedFileSystemProviderTests.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/NestedFileSystemProviderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/NestedFileSystemProviderTests.java index dd357cb28d77..2a52f5e436d1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/NestedFileSystemProviderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/NestedFileSystemProviderTests.java @@ -30,9 +30,12 @@ import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.spi.FileSystemProvider; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -69,6 +72,11 @@ void setup() throws Exception { this.uriPrefix = "nested:" + this.file.toURI().getPath() + "/!"; } + @AfterEach + void cleanUp() { + this.provider.cleanUp(); + } + @Test void getSchemeReturnsScheme() { assertThat(this.provider.getScheme()).isEqualTo("nested"); @@ -259,6 +267,8 @@ static class TestNestedFileSystemProvider extends NestedFileSystemProvider { private Path mockJarPath; + private List paths = new ArrayList<>(); + @Override protected Path getJarPath(Path path) { return (this.mockJarPath != null) ? this.mockJarPath : super.getJarPath(path); @@ -268,6 +278,24 @@ void setMockJarPath(Path mockJarPath) { this.mockJarPath = mockJarPath; } + @Override + public Path getPath(URI uri) { + Path path = super.getPath(uri); + this.paths.add(path); + return path; + } + + private void cleanUp() { + this.paths.forEach((path) -> { + try { + Path.of(path.toUri()).getFileSystem().close(); + } + catch (Exception ex) { + // Ignore + } + }); + } + } }