X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FRepackage.java;h=909e2f456ba80510ae9cc867bacd56597d4dc7d7;hb=c76ee2fffc591cbd3c0deb0aec9f2b1add5a1bca;hp=6bca9c4e486d9338a17c9773fe49c8af651d5f2a;hpb=fac60d5aa22745b00a08ade1a6f6f29c53135f32;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Repackage.java b/src/org/argeo/build/Repackage.java index 6bca9c4..909e2f4 100644 --- a/src/org/argeo/build/Repackage.java +++ b/src/org/argeo/build/Repackage.java @@ -246,21 +246,29 @@ public class Repackage { Path downloaded = downloadMaven(url, artifact); // some proprietary artifacts do not allow any modification + // when releasing (with separate sources) we just copy it boolean doNotModify = Boolean.parseBoolean( fileProps.getOrDefault(ManifestConstants.ARGEO_DO_NOT_MODIFY.toString(), "false").toString()); - if (doNotModify) { + if (doNotModify && sourceBundles) { Path unmodifiedTarget = targetCategoryBase.resolve( fileProps.getProperty(BUNDLE_SYMBOLICNAME.toString()) + "." + artifact.getBranch() + ".jar"); Files.copy(downloaded, unmodifiedTarget, StandardCopyOption.REPLACE_EXISTING); + Path bundleDir = targetCategoryBase + .resolve(fileProps.getProperty(BUNDLE_SYMBOLICNAME.toString()) + "." + artifact.getBranch()); + downloadAndProcessM2Sources(repoStr, artifact, bundleDir, false); + Manifest manifest; + try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(unmodifiedTarget))) { + manifest = jarIn.getManifest(); + } + createSourceJar(bundleDir, manifest); return; } + // regular processing A2Origin origin = new A2Origin(); - Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact, origin); - - downloadAndProcessM2Sources(repoStr, artifact, targetBundleDir, false); - - createJar(targetBundleDir, origin); + Path bundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact, origin); + downloadAndProcessM2Sources(repoStr, artifact, bundleDir, false); + createJar(bundleDir, origin); } catch (Exception e) { throw new RuntimeException("Cannot process " + bndFile, e); } @@ -404,7 +412,8 @@ public class Repackage { entries: while ((entry = jarIn.getNextJarEntry()) != null) { if (entry.isDirectory()) continue entries; - if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".SF")) { + if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".DSA") + || entry.getName().endsWith(".SF")) { origin.deleted.add("cryptographic signatures from " + artifact); continue entries; } @@ -892,7 +901,8 @@ public class Repackage { entries: while ((entry = jarIn.getNextJarEntry()) != null) { if (entry.isDirectory()) continue entries; - if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".SF")) { + if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".DSA") + || entry.getName().endsWith(".SF")) { origin.deleted.add("cryptographic signatures"); continue entries; } @@ -1000,24 +1010,26 @@ public class Repackage { file.getFileName() + ": " + key + " was " + previousValue + ", overridden with " + value); } - // de-pollute MANIFEST - switch (key) { + // !! hack to remove unresolvable + if (key.equals("Provide-Capability") || key.equals("Require-Capability")) + if (nameVersion.getName().equals("osgi.core") || nameVersion.getName().equals("osgi.cmpn")) { + manifest.getMainAttributes().remove(key); + } + } + + // de-pollute MANIFEST + for (Object header : manifest.getMainAttributes().keySet()) { + switch (header.toString()) { case "Archiver-Version": case "Build-By": case "Created-By": case "Originally-Created-By": case "Tool": case "Bnd-LastModified": - manifest.getMainAttributes().remove(key); + manifest.getMainAttributes().remove(header); break; default: // do nothing } - - // !! hack to remove unresolvable - if (key.equals("Provide-Capability") || key.equals("Require-Capability")) - if (nameVersion.getName().equals("osgi.core") || nameVersion.getName().equals("osgi.cmpn")) { - manifest.getMainAttributes().remove(key); - } } // license checks @@ -1176,52 +1188,55 @@ public class Repackage { } deleteDirectory(bundleDir); - if (sourceBundles) { - Path bundleCategoryDir = bundleDir.getParent(); - Path sourceDir = bundleCategoryDir.resolve(bundleDir.toString() + ".src"); - if (!Files.exists(sourceDir)) { - logger.log(WARNING, sourceDir + " does not exist, skipping..."); - return jarPath; + if (sourceBundles) + createSourceJar(bundleDir, manifest); - } + return jarPath; + } - Path relPath = a2Base.relativize(bundleCategoryDir); - Path srcCategoryDir = a2SrcBase.resolve(relPath); - Path srcJarP = srcCategoryDir.resolve(sourceDir.getFileName() + ".jar"); - Files.createDirectories(srcJarP.getParent()); - - String bundleSymbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName").toString(); - // in case there are additional directives - bundleSymbolicName = bundleSymbolicName.split(";")[0]; - Manifest srcManifest = new Manifest(); - srcManifest.getMainAttributes().put(MANIFEST_VERSION, "1.0"); - srcManifest.getMainAttributes().putValue(BUNDLE_SYMBOLICNAME.toString(), bundleSymbolicName + ".src"); - srcManifest.getMainAttributes().putValue(BUNDLE_VERSION.toString(), - manifest.getMainAttributes().getValue(BUNDLE_VERSION.toString()).toString()); - srcManifest.getMainAttributes().putValue(ECLIPSE_SOURCE_BUNDLE.toString(), bundleSymbolicName - + ";version=\"" + manifest.getMainAttributes().getValue(BUNDLE_VERSION.toString())); - - try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) { - srcJarOut.setLevel(Deflater.BEST_COMPRESSION); - Files.walkFileTree(sourceDir, new SimpleFileVisitor() { - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (file.getFileName().toString().equals("MANIFEST.MF")) - return super.visitFile(file, attrs); - JarEntry entry = new JarEntry( - sourceDir.relativize(file).toString().replace(File.separatorChar, '/')); - srcJarOut.putNextEntry(entry); - Files.copy(file, srcJarOut); - return super.visitFile(file, attrs); - } + void createSourceJar(Path bundleDir, Manifest manifest) throws IOException { + Path bundleCategoryDir = bundleDir.getParent(); + Path sourceDir = bundleCategoryDir.resolve(bundleDir.toString() + ".src"); + if (!Files.exists(sourceDir)) { + logger.log(WARNING, sourceDir + " does not exist, skipping..."); + return; - }); - } - deleteDirectory(sourceDir); } - return jarPath; + Path relPath = a2Base.relativize(bundleCategoryDir); + Path srcCategoryDir = a2SrcBase.resolve(relPath); + Path srcJarP = srcCategoryDir.resolve(sourceDir.getFileName() + ".jar"); + Files.createDirectories(srcJarP.getParent()); + + String bundleSymbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName").toString(); + // in case there are additional directives + bundleSymbolicName = bundleSymbolicName.split(";")[0]; + Manifest srcManifest = new Manifest(); + srcManifest.getMainAttributes().put(MANIFEST_VERSION, "1.0"); + srcManifest.getMainAttributes().putValue(BUNDLE_SYMBOLICNAME.toString(), bundleSymbolicName + ".src"); + srcManifest.getMainAttributes().putValue(BUNDLE_VERSION.toString(), + manifest.getMainAttributes().getValue(BUNDLE_VERSION.toString()).toString()); + srcManifest.getMainAttributes().putValue(ECLIPSE_SOURCE_BUNDLE.toString(), + bundleSymbolicName + ";version=\"" + manifest.getMainAttributes().getValue(BUNDLE_VERSION.toString())); + + try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) { + srcJarOut.setLevel(Deflater.BEST_COMPRESSION); + Files.walkFileTree(sourceDir, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().equals("MANIFEST.MF")) + return super.visitFile(file, attrs); + JarEntry entry = new JarEntry( + sourceDir.relativize(file).toString().replace(File.separatorChar, '/')); + srcJarOut.putNextEntry(entry); + Files.copy(file, srcJarOut); + return super.visitFile(file, attrs); + } + + }); + } + deleteDirectory(sourceDir); } /** MANIFEST headers. */