in jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java [78:135]
public static void transformToOSGiBundle(File jbiArtifact, File osgiBundle, Properties properties) throws Exception {
JarFile jar = new JarFile(jbiArtifact);
Manifest m = jar.getManifest();
if (m == null) {
m = new Manifest();
m.getMainAttributes().putValue("Manifest-Version", "1.0");
}
JarEntry jarEntry = jar.getJarEntry(DescriptorFactory.DESCRIPTOR_FILE);
InputStream is = jar.getInputStream(jarEntry);
Descriptor desc = DescriptorFactory.buildDescriptor(is);
String version = m.getMainAttributes().getValue("Implementation-Version");
if (version != null) {
version = Builder.cleanupVersion(version);
} else {
version = "0.0.0";
}
String name = m.getMainAttributes().getValue("Implementation-Title");
if (desc.getComponent() != null) {
name = desc.getComponent().getIdentification().getName();
} else if (desc.getSharedLibrary() != null) {
name = desc.getSharedLibrary().getIdentification().getName();
} else if (desc.getServiceAssembly() != null) {
name = desc.getServiceAssembly().getIdentification().getName();
}
m.getMainAttributes().putValue("Bundle-SymbolicName", name);
m.getMainAttributes().putValue("Bundle-Version", version);
m.getMainAttributes().putValue("DynamicImport-Package", "javax.*,org.xml.*,org.w3c.*");
if (properties != null) {
Enumeration en = properties.propertyNames();
while (en.hasMoreElements()) {
String k = (String) en.nextElement();
String v = properties.getProperty(k);
m.getMainAttributes().putValue(k, v);
}
}
osgiBundle.getParentFile().mkdirs();
JarInputStream jis = new JarInputStream(new BufferedInputStream(new FileInputStream(jbiArtifact)));
JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(osgiBundle)), m);
JarEntry entry = jis.getNextJarEntry();
while (entry != null) {
if (!"META-INF/MANIFEST.MF".equals(entry.getName())) {
JarEntry newEntry = new JarEntry(entry.getName());
jos.putNextEntry(newEntry);
FileUtil.copyInputStream(jis, jos);
jos.closeEntry();
}
entry = jis.getNextJarEntry();
}
jos.close();
jis.close();
}