+ 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<Path>() {
+
+ @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);