Support java.nio.file Paths and FileSystems with nested jars

Add a `NestedFileSystemProvider` implementation so that the JDK's
`ZipFileSystem` can load content from nested jars and nested
directory entries.

Creating a `ZipFileSystem` may be a relatively expensive operation as
zip structures need to be parsed and in the case of directory entries
a virtual datablock nees to be generated on the fly. As such, we
install the `ZipFileSystem` as late as possible since in a typical
application it may never be needed.

This commit also tweaks Gradle and Maven plugins to ensure that the
service loader file is written to repackaged jars.

Closes gh-7161
This commit is contained in:
Phillip Webb
2023-10-18 14:57:05 -07:00
parent 4b495ca2a9
commit 3c62defb9d
21 changed files with 2115 additions and 5 deletions

View File

@@ -66,8 +66,8 @@ class LoaderZipEntries {
writeDirectory(new ZipArchiveEntry(entry), out);
written.addDirectory(entry);
}
else if (entry.getName().endsWith(".class")) {
writeClass(new ZipArchiveEntry(entry), loaderJar, out);
else if (entry.getName().endsWith(".class") || entry.getName().startsWith("META-INF/services/")) {
writeFile(new ZipArchiveEntry(entry), loaderJar, out);
written.addFile(entry);
}
entry = loaderJar.getNextEntry();
@@ -82,7 +82,7 @@ class LoaderZipEntries {
out.closeArchiveEntry();
}
private void writeClass(ZipArchiveEntry entry, ZipInputStream in, ZipArchiveOutputStream out) throws IOException {
private void writeFile(ZipArchiveEntry entry, ZipInputStream in, ZipArchiveOutputStream out) throws IOException {
prepareEntry(entry, this.fileMode);
out.putArchiveEntry(entry);
copy(in, out);