Skip to content

Commit 198266c

Browse files
committed
Temporarily work around marschall/memoryfilesystem/pull/145
1 parent b3bb8b4 commit 198266c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/PackageContainerGroupUrlClassLoader.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
import io.github.ascopes.jct.workspaces.PathRoot;
2121
import java.net.URL;
2222
import java.net.URLClassLoader;
23+
import java.util.Locale;
24+
import java.util.stream.Stream;
2325
import org.apiguardian.api.API;
2426
import org.apiguardian.api.API.Status;
2527

28+
import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
29+
2630
/**
2731
* An extension of the Java {@link URLClassLoader} that wraps around container groups.
2832
*
@@ -50,6 +54,25 @@ private static URL[] extractUrls(PackageContainerGroup group) {
5054
.stream()
5155
.map(Container::getPathRoot)
5256
.map(PathRoot::getUrl)
57+
.map(PackageContainerGroupUrlClassLoader::fixMemoryFileSystemUrls)
5358
.toArray(URL[]::new);
5459
}
60+
61+
// This can be removed once https://github.com/marschall/memoryfilesystem/pull/145/files is
62+
// addressed.
63+
private static URL fixMemoryFileSystemUrls(URL url) {
64+
if (url.getPath().endsWith("/") || isProbablyArchive(url)) {
65+
return url;
66+
}
67+
68+
return uncheckedIo(() -> new URL(
69+
url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "/"
70+
));
71+
}
72+
73+
private static boolean isProbablyArchive(URL url) {
74+
return Stream
75+
.of(".jar", ".war", ".ear", ".zip")
76+
.anyMatch(url.getFile().toLowerCase(Locale.ROOT)::endsWith);
77+
}
5578
}

0 commit comments

Comments
 (0)