use of de.kalpatec.pojosr.framework.launch.BundleDescriptor in project aries by apache.
the class Helper method getBundleDescriptor.
private static BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file, true);
try {
copy(bundle.build(), fos);
} finally {
close(fos);
}
FileInputStream fis = null;
JarInputStream jis = null;
try {
fis = new FileInputStream(file);
jis = new JarInputStream(fis);
Map<String, String> headers = new HashMap<String, String>();
for (Map.Entry<Object, Object> entry : jis.getManifest().getMainAttributes().entrySet()) {
headers.put(entry.getKey().toString(), entry.getValue().toString());
}
return new BundleDescriptor(bundle.getClass().getClassLoader(), new URL("jar:" + file.toURI().toString() + "!/"), headers);
} finally {
close(fis, jis);
}
}
use of de.kalpatec.pojosr.framework.launch.BundleDescriptor in project aries by apache.
the class Helper method createBundleContext.
public static BundleContext createBundleContext(String bundleFilter, TinyBundle[] testBundles) throws Exception {
deleteDirectory("target/bundles");
createDirectory("target/bundles");
// ensure pojosr stores bundles in an unique target directory
System.setProperty("org.osgi.framework.storage", "target/bundles/" + System.currentTimeMillis());
// get the bundles
List<BundleDescriptor> bundles = getBundleDescriptors(bundleFilter);
// with pojosr because it does not support bundle hooks, so events are lost.
if (testBundles != null) {
for (TinyBundle bundle : testBundles) {
File tmp = File.createTempFile("test-", ".jar", new File("target/bundles/"));
tmp.delete();
bundles.add(0, getBundleDescriptor(tmp.getPath(), bundle));
}
}
if (LOG.isDebugEnabled()) {
for (int i = 0; i < bundles.size(); i++) {
BundleDescriptor desc = bundles.get(i);
LOG.debug("Bundle #{} -> {}", i, desc);
}
}
// setup pojosr to use our bundles
Map<String, List<BundleDescriptor>> config = new HashMap<String, List<BundleDescriptor>>();
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
// create pojorsr osgi service registry
PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
return reg.getBundleContext();
}
Aggregations