Skip to content

Commit 2bc6976

Browse files
kohlschuetterfniephaus
authored andcommitted
Fix compile-no-fork with existing jar FileSystems (#547)
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.
1 parent 0db3e00 commit 2bc6976

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.nio.charset.StandardCharsets;
6565
import java.nio.file.FileSystem;
6666
import java.nio.file.FileSystems;
67+
import java.nio.file.FileSystemAlreadyExistsException;
6768
import java.nio.file.Path;
6869
import java.nio.file.Paths;
6970
import java.nio.file.Files;
@@ -293,13 +294,23 @@ protected void addArtifactToClasspath(Artifact artifact) throws MojoExecutionExc
293294
Optional.ofNullable(processSupportedArtifacts(artifact)).ifPresent(imageClasspath::add);
294295
}
295296

297+
private static FileSystem openFileSystem(URI uri) throws IOException {
298+
FileSystem fs;
299+
try {
300+
fs = FileSystems.newFileSystem(uri, Collections.emptyMap());
301+
} catch (FileSystemAlreadyExistsException e) {
302+
fs = FileSystems.getFileSystem(uri);
303+
}
304+
return fs;
305+
}
306+
296307
protected void warnIfWrongMetaInfLayout(Path jarFilePath, Artifact artifact) throws MojoExecutionException {
297308
if (jarFilePath.toFile().isDirectory()) {
298309
logger.debug("Artifact `" + jarFilePath + "` is a directory.");
299310
return;
300311
}
301312
URI jarFileURI = URI.create("jar:" + jarFilePath.toUri());
302-
try (FileSystem jarFS = FileSystems.newFileSystem(jarFileURI, Collections.emptyMap())) {
313+
try (FileSystem jarFS = openFileSystem(jarFileURI)) {
303314
Path nativeImageMetaInfBase = jarFS.getPath("/" + NATIVE_IMAGE_META_INF);
304315
if (Files.isDirectory(nativeImageMetaInfBase)) {
305316
try (Stream<Path> stream = Files.walk(nativeImageMetaInfBase)) {

0 commit comments

Comments
 (0)