Skip to content

Commit

Permalink
Fix compile-no-fork with existing jar FileSystems (#547)
Browse files Browse the repository at this point in the history
FileSystems.newFileSystem on a dependency jar fails with a
FileSystemAlreadyExistsException if another Maven plugin has already
created it.

Provide a wrapper that handles the exception, trying
FileSystems.getFileSystem in that case.
  • Loading branch information
kohlschuetter authored and fniephaus committed Jan 30, 2024
1 parent 0db3e00 commit 2bc6976
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
Expand Down Expand Up @@ -293,13 +294,23 @@ protected void addArtifactToClasspath(Artifact artifact) throws MojoExecutionExc
Optional.ofNullable(processSupportedArtifacts(artifact)).ifPresent(imageClasspath::add);
}

private static FileSystem openFileSystem(URI uri) throws IOException {
FileSystem fs;
try {
fs = FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (FileSystemAlreadyExistsException e) {
fs = FileSystems.getFileSystem(uri);
}
return fs;
}

protected void warnIfWrongMetaInfLayout(Path jarFilePath, Artifact artifact) throws MojoExecutionException {
if (jarFilePath.toFile().isDirectory()) {
logger.debug("Artifact `" + jarFilePath + "` is a directory.");
return;
}
URI jarFileURI = URI.create("jar:" + jarFilePath.toUri());
try (FileSystem jarFS = FileSystems.newFileSystem(jarFileURI, Collections.emptyMap())) {
try (FileSystem jarFS = openFileSystem(jarFileURI)) {
Path nativeImageMetaInfBase = jarFS.getPath("/" + NATIVE_IMAGE_META_INF);
if (Files.isDirectory(nativeImageMetaInfBase)) {
try (Stream<Path> stream = Files.walk(nativeImageMetaInfBase)) {
Expand Down

0 comments on commit 2bc6976

Please sign in to comment.