import static org.argeo.slc.ManifestConstants.BUNDLE_LICENSE;
import static org.argeo.slc.ManifestConstants.BUNDLE_SYMBOLICNAME;
import static org.argeo.slc.ManifestConstants.BUNDLE_VERSION;
+import static org.argeo.slc.ManifestConstants.EXPORT_PACKAGE;
import static org.argeo.slc.ManifestConstants.SLC_ORIGIN_M2;
import java.io.FileNotFoundException;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import org.argeo.slc.DefaultNameVersion;
URL url = MavenConventionsUtils.mavenCentralUrl(artifact);
Path downloaded = download(url, originBase, artifact.toM2Coordinates() + ".jar");
- Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps);
+ Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact);
downloadAndProcessM2Sources(artifact, targetBundleDir);
+
+ createJar(targetBundleDir);
} catch (Exception e) {
throw new RuntimeException("Cannot process " + bndFile, e);
}
}
}
mergeProps.put(ManifestConstants.SLC_ORIGIN_M2.toString(), artifact.toM2Coordinates());
- Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, mergeProps);
+ Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, mergeProps, artifact);
// logger.log(Level.DEBUG, () -> "Processed " + downloaded);
// sources
downloadAndProcessM2Sources(artifact, targetBundleDir);
+
+ createJar(targetBundleDir);
}
} catch (IOException e) {
throw new RuntimeException("Cannot process " + duDir, e);
URL sourcesUrl = MavenConventionsUtils.mavenCentralUrl(sourcesArtifact);
Path sourcesDownloaded = download(sourcesUrl, originBase, artifact.toM2Coordinates() + ".sources.jar");
processM2SourceJar(sourcesDownloaded, targetBundleDir);
- logger.log(Level.DEBUG, () -> "Processed " + sourcesDownloaded);
+ logger.log(Level.DEBUG, () -> "Processed source " + sourcesDownloaded);
}
- protected Path processBndJar(Path downloaded, Path targetCategoryBase, Properties fileProps) {
+ protected Path processBndJar(Path downloaded, Path targetCategoryBase, Properties fileProps,
+ DefaultArtifact artifact) {
try {
Map<String, String> additionalEntries = new TreeMap<>();
additionalEntries.put(key.toString(), value);
}
} else {
+ if (artifact != null) {
+ if (!fileProps.containsKey(BUNDLE_SYMBOLICNAME.toString())) {
+ fileProps.put(BUNDLE_SYMBOLICNAME.toString(), artifact.getName());
+ }
+ if (!fileProps.containsKey(BUNDLE_VERSION.toString())) {
+ fileProps.put(BUNDLE_VERSION.toString(), artifact.getVersion());
+ }
+ }
+
+ if (!fileProps.containsKey(EXPORT_PACKAGE.toString())) {
+ fileProps.put(EXPORT_PACKAGE.toString(),
+ "*;version=\"" + fileProps.getProperty(BUNDLE_VERSION.toString()) + "\"");
+ }
+// if (!fileProps.contains(IMPORT_PACKAGE.toString())) {
+// fileProps.put(IMPORT_PACKAGE.toString(), "*");
+// }
try (Analyzer bndAnalyzer = new Analyzer()) {
bndAnalyzer.setProperties(fileProps);
case "Created-By":
continue keys;
}
+ if("Require-Capability".equals(key.toString()) && value.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
+ continue keys;// hack for very old classes
additionalEntries.put(key.toString(), value.toString());
- // logger.log(DEBUG, () -> key + "=" + value);
+ logger.log(DEBUG, () -> key + "=" + value);
}
}
+
+// try (Builder bndBuilder = new Builder()) {
+// Jar jar = new Jar(downloaded.toFile());
+// bndBuilder.addClasspath(jar);
+// Path targetBundleDir = targetCategoryBase.resolve(artifact.getName() + "." + artifact.getBranch());
+//
+// Jar target = new Jar(targetBundleDir.toFile());
+// bndBuilder.setJar(target);
+// return targetBundleDir;
+// }
}
Path targetBundleDir = processBundleJar(downloaded, targetCategoryBase, additionalEntries);
logger.log(Level.DEBUG, () -> "Processed " + downloaded);
return super.visitFile(file, attrs);
}
});
+
+ DirectoryStream<Path> dirs = Files.newDirectoryStream(targetCategoryBase, (p) -> Files.isDirectory(p));
+ for (Path dir : dirs) {
+ createJar(dir);
+ }
} catch (IOException e) {
throw new RuntimeException("Cannot process " + duDir, e);
}
NameVersion nameVersion;
Path targetBundleDir;
try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(file), false)) {
- Manifest manifest = jarIn.getManifest();
+ Manifest manifest = new Manifest(jarIn.getManifest());
+
+ // remove problematic entries in MANIFEST
+ manifest.getEntries().clear();
+// Set<String> entriesToDelete = new HashSet<>();
+// for (String key : manifest.getEntries().keySet()) {
+//// logger.log(DEBUG, "## " + key);
+// Attributes attrs = manifest.getAttributes(key);
+// for (Object attrName : attrs.keySet()) {
+//// logger.log(DEBUG, attrName + "=" + attrs.get(attrName));
+// if ("Specification-Version".equals(attrName.toString())
+// || "Implementation-Version".equals(attrName.toString())) {
+// entriesToDelete.add(key);
+//
+// }
+// }
+// }
+// for (String key : entriesToDelete) {
+// manifest.getEntries().remove(key);
+// }
String symbolicNameFromEntries = entries.get(BUNDLE_SYMBOLICNAME.toString());
String versionFromEntries = entries.get(BUNDLE_VERSION.toString());
entries: while ((entry = jarIn.getNextJarEntry()) != null) {
if (entry.isDirectory())
continue entries;
+ if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".SF"))
+ continue entries;
Path target = targetBundleDir.resolve(entry.getName());
Files.createDirectories(target.getParent());
Files.copy(jarIn, target);
// copy MANIFEST
Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
Files.createDirectories(manifestPath.getParent());
- for (String key : entries.keySet()) {
+ for (String key : entries.keySet()) {
String value = entries.get(key);
Object previousValue = manifest.getMainAttributes().putValue(key, value);
if (previousValue != null && !previousValue.equals(value)) {
return dest;
}
+ protected Path createJar(Path bundleDir) throws IOException {
+ Path jarPath = bundleDir.getParent().resolve(bundleDir.getFileName() + ".jar");
+ Path manifestPath = bundleDir.resolve("META-INF/MANIFEST.MF");
+ Manifest manifest;
+ try (InputStream in = Files.newInputStream(manifestPath)) {
+ manifest = new Manifest(in);
+ }
+ try (JarOutputStream jarOut = new JarOutputStream(Files.newOutputStream(jarPath), manifest)) {
+ Files.walkFileTree(bundleDir, 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(bundleDir.relativize(file).toString());
+ jarOut.putNextEntry(entry);
+ Files.copy(file, jarOut);
+ return super.visitFile(file, attrs);
+ }
+
+ });
+ }
+ deleteDirectory(bundleDir);
+ return jarPath;
+ }
+
public static void main(String[] args) {
Path originBase = Paths.get("../output/origin").toAbsolutePath().normalize();
Path factoryBase = Paths.get("../output/a2").toAbsolutePath().normalize();
Path descriptorsBase = Paths.get("../tp").toAbsolutePath().normalize();
+// factory.processSingleM2ArtifactDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache").resolve("org.apache.xml.resolver.bnd"));
+// factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp/slf4j"));
+// System.exit(0);
+
+ // Eclipse
factory.processEclipseArchive(
descriptorsBase.resolve("org.argeo.tp.eclipse.equinox").resolve("eclipse-equinox"));
factory.processEclipseArchive(descriptorsBase.resolve("org.argeo.tp.eclipse.rap").resolve("eclipse-rap"));
factory.processEclipseArchive(descriptorsBase.resolve("org.argeo.tp.eclipse.rcp").resolve("eclipse-rcp"));
+ // Maven
+ factory.processCategory(descriptorsBase.resolve("org.argeo.tp.sdk"));
factory.processCategory(descriptorsBase.resolve("org.argeo.tp"));
factory.processCategory(descriptorsBase.resolve("org.argeo.tp.apache"));
factory.processCategory(descriptorsBase.resolve("org.argeo.tp.jetty"));
- factory.processCategory(descriptorsBase.resolve("org.argeo.tp.sdk"));
+ factory.processCategory(descriptorsBase.resolve("org.argeo.tp.jcr"));
}
}