From 52303abc644415e3f1d44546a0aa7f48865ed299 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Wed, 20 Mar 2024 17:07:33 +0100 Subject: [PATCH] Inject MANIFEST.MF also for source jar files For Quarkus productization source jars are expected to have META-INF/MANIFEST.MF files in them. Inject them when they're not already there like we do for the actual jar artefact. --- build.java | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/build.java b/build.java index a8e5c16..be805b8 100644 --- a/build.java +++ b/build.java @@ -657,24 +657,29 @@ private BiConsumer amendOrCreateManifest(Options options, Tasks. { return (artifact, paths) -> { - final Path jarPath = PathFinder.getFirstExisting(fs.mandrelRepo().resolve(paths[0]).toString(), artifact); - try (java.nio.file.FileSystem jarfs = FileSystems.newFileSystem(jarPath, this.getClass().getClassLoader())) + final String jarF = PathFinder.getFirstExisting(fs.mandrelRepo().resolve(paths[0]).toString(), artifact).toString(); + final Path jarPath = Path.of(jarF); + final Path sourceJarPath = Path.of(jarF.replace(".jar", ".src.zip")); + for (Path jar: List.of( jarPath, sourceJarPath )) { - Path metaInfPath = jarfs.getPath("/META-INF"); - Path manifestPath = metaInfPath.resolve("MANIFEST.MF"); - if (!Files.exists(manifestPath)) + try (java.nio.file.FileSystem jarfs = FileSystems.newFileSystem(jar, this.getClass().getClassLoader())) { - if (!Files.exists(metaInfPath)) + Path metaInfPath = jarfs.getPath("/META-INF"); + Path manifestPath = metaInfPath.resolve("MANIFEST.MF"); + if (!Files.exists(manifestPath)) { - Files.createDirectory(metaInfPath); + if (!Files.exists(metaInfPath)) + { + Files.createDirectory(metaInfPath); + } + Files.createFile(manifestPath); } - Files.createFile(manifestPath); + Tasks.FileReplace.replace(new Tasks.FileReplace(manifestPath, amendManifest(options)), replace); + } + catch (IOException e) + { + throw new RuntimeException(e); } - Tasks.FileReplace.replace(new Tasks.FileReplace(manifestPath, amendManifest(options)), replace); - } - catch (IOException e) - { - throw new RuntimeException(e); } }; }