* @param bsn
* @param version
* @throws Exception
*/
private void wrap(String bsn, Version version) throws Exception {
Revision r = library.getRevision(Library.OSGI_GROUP + ":" + bsn + "@" + version.toString());
if (r == null)
return;
Jar jar = new Jar(get(bsn, version, null));
Formatter f = new Formatter();
Analyzer an = new Analyzer();
try {
an.setJar(jar);
an.analyze();
f.format("# Generated bnd wrapper for %s:%s@%s\n", r.groupId, r.artifactId, r.version);
f.format("# Recipe by ${global;name}\n\n");
if (an.getBundleSymbolicName() != null) {
f.format("#\n# ALREADY AN OSGI BUNDLE!!!\n#\n");
}
Manifest m = jar.getManifest();
if (m != null) {
String del = "# From original manifest\n";
boolean yes = false;
for (Entry<Object,Object> e : m.getMainAttributes().entrySet()) {
yes = true;
String key = e.getKey().toString();
if ("Manifest-Version".equalsIgnoreCase(key) || "Bundle-ManifestVersion".equalsIgnoreCase(key)
|| key.startsWith("Bnd") || key.startsWith("Created"))
continue;
f.format("%s%-40s: %s", del, key, e.getValue());
del = "\n";
}
if (yes)
f.format("\n\n# End of original manifest");
f.format("\n\n");
}
if (r.description != null)
f.format("Bundle-Description: %s %s\\\n ${disclaimer}\n", r.title == null ? ""
: r.title, r.description);
else
f.format("Bundle-Description: ##########################################################");
String v = r.baseline;
if (r.qualifier != null)
v += "." + r.qualifier;
f.format("Bundle-Version: %s\n", v);
if (r.icon != null)
f.format("Bundle-Icon: %s\n", r.icon);
f.format("\n#\n# Coordinates\n#\n");
f.format("JPM-From: sha:%s@0.0.0;coordinates=%s;bsn=%s\n",
Hex.toHexString(r._id), getCoordinates(r), r.bsn);
f.format("JPM-URL: https://jpm4j.org/#/p/%s/%s/%s/%s\n", r.groupId,
r.artifactId, r.classifier == null ? "" : r.classifier, r.version);
f.format("Include-Resource: @${repo;%s;0.0.0}\n", Hex.toHexString(r._id));
if (r.docUrl != null)
f.format("Bundle-DocURL: %s\n", r.docUrl);
if (r.organization != null && r.organization.name != null) {
f.format("Bundle-Vendor: %s\n", r.organization.name);
}
if (r.organization != null && r.organization.url != null) {
f.format("Bundle-ContactAddress: %s\n", r.organization.url);
}
String del = "Bundle-License: ";
for (License license : r.licenses) {
f.format("%s %s", del, license.name);
if (license.url != null)
f.format(";url='%s'", license.url);
if (license.comments != null)
f.format(";description='%s'", license.comments);
del = ", \\\n ";
}
f.format("\n\n");
del = "Bundle-Developers: \\\n ";
for (Developer dev : r.developers) {
f.format("%s '%s'", del, dev.name);
if (dev.email != null)
f.format(";email='%s'", dev.email);
if (dev.roles != null) {
ExtList<String> el = new ExtList<String>(dev.roles);
if (!el.isEmpty())
f.format(";roles='%s'", el.join());
}
del = ", \\\n ";
}
f.format("\n\n");
del = "Bundle-Contributors: \\\n ";
for (Contributor dev : r.contributors) {
f.format("%s %s", del, dev.name);
if (dev.email != null)
f.format(";email='%s'", dev.email);
if (dev.roles != null) {
ExtList<String> el = new ExtList<String>(dev.roles);
if (!el.isEmpty())
f.format(";roles='%s'", el.join());
}
del = ", \\\n ";
}
f.format("\n\n");
f.format("Export-Package: ");
del = "";
for (Entry<PackageRef,Attrs> pr : an.getContained().entrySet()) {
f.format("%s\\\n %s", del, pr.getKey().getFQN());
if (pr.getValue().containsKey("version")) {
f.format(";version=%s", pr.getValue().get("version"));
} else {
f.format(";version=100.0.0;provide:=true");
}
del = ",";
}
f.format("\n\n");
f.format("#\n# Remove after inspection:\n\nImport-Package: ");
del = "";
for (Entry<PackageRef,Attrs> pr : an.getReferred().entrySet()) {
if (pr.getKey().isJava() || pr.getKey().isMetaData())
continue;
f.format("%s\\\n %s", del, pr.getKey().getFQN());
if (pr.getValue().containsKey("version")) {
f.format(";version='%s'", pr.getValue().get("version"));
}
del = ",";
}
f.format("\n\n");
f.format("-buildpath:");
del = " \\\n ";
for (Requirement req : r.requirements) {
String name = req.name == null ? (String) req.ps.get("name:") : req.name;
if ("x-maven".equals(req.ns) && name != null) {
Matcher matcher = COORDINATE_P.matcher(name);
if (matcher.matches()) {
String g = matcher.group(1);
String a = matcher.group(2);
String vv = matcher.group(3);
Revision dep = library.getRevision(g + ":" + a + "@" + vv);
if (dep == null) {
f.format("%s%s.%s;version=%s", del, g, a, vv);
} else {
f.format("%s%s;version=%s", del, r.bsn, vv);
}