From db89cbf633f301c206628331ea61548ad739eea9 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 14 Sep 2023 07:15:07 +0200 Subject: [PATCH] Package JavaScript source maps separately --- src/org/argeo/build/Make.java | 41 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/org/argeo/build/Make.java b/src/org/argeo/build/Make.java index 88036da..4f22815 100644 --- a/src/org/argeo/build/Make.java +++ b/src/org/argeo/build/Make.java @@ -510,7 +510,7 @@ public class Make { if (exclude.matches(relativeP)) return FileVisitResult.CONTINUE; // skip JavaScript source maps - if (file.getFileName().toString().endsWith(".map")) + if (sourceBundles && file.getFileName().toString().endsWith(".map")) return FileVisitResult.CONTINUE; JarEntry entry = new JarEntry(relativeP.toString()); @@ -569,15 +569,36 @@ public class Make { srcManifest.getMainAttributes().putValue("Bundle-SymbolicName", bundleSymbolicName + ".src"); srcManifest.getMainAttributes().putValue("Bundle-Version", manifest.getMainAttributes().getValue("Bundle-Version").toString()); - srcManifest.getMainAttributes().putValue("Eclipse-SourceBundle", - bundleSymbolicName + ";version=\"" + manifest.getMainAttributes().getValue("Bundle-Version")); - - try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) { - copySourcesToJar(srcP, srcJarOut, ""); - // add legal notices and licenses - for (Path p : listLegalFilesToInclude(source).values()) { - srcJarOut.putNextEntry(new JarEntry(p.getFileName().toString())); - Files.copy(p, srcJarOut); + + boolean isJsBundle = bundleSymbolicName.endsWith(".js"); + if (!isJsBundle) { + srcManifest.getMainAttributes().putValue("Eclipse-SourceBundle", + bundleSymbolicName + ";version=\"" + manifest.getMainAttributes().getValue("Bundle-Version")); + + try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) { + copySourcesToJar(srcP, srcJarOut, ""); + // add legal notices and licenses + for (Path p : listLegalFilesToInclude(source).values()) { + srcJarOut.putNextEntry(new JarEntry(p.getFileName().toString())); + Files.copy(p, srcJarOut); + } + } + } else {// JavaScript source maps + srcManifest.getMainAttributes().putValue("Fragment-Host", + bundleSymbolicName + ";version=\"" + manifest.getMainAttributes().getValue("Bundle-Version")); + try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) { + Files.walkFileTree(source, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Path relativeP = source.relativize(file); + if (!file.getFileName().toString().endsWith(".map")) + return FileVisitResult.CONTINUE; + JarEntry entry = new JarEntry(relativeP.toString()); + srcJarOut.putNextEntry(entry); + Files.copy(file, srcJarOut); + return FileVisitResult.CONTINUE; + } + }); } } } -- 2.30.2