Search in sources :

Example 1 with BundleDescriptor

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);
    }
}
Also used : BundleDescriptor(de.kalpatec.pojosr.framework.launch.BundleDescriptor) JarInputStream(java.util.jar.JarInputStream) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream) URL(java.net.URL)

Example 2 with BundleDescriptor

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();
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) PojoServiceRegistry(de.kalpatec.pojosr.framework.launch.PojoServiceRegistry) BundleDescriptor(de.kalpatec.pojosr.framework.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) File(java.io.File)

Aggregations

BundleDescriptor (de.kalpatec.pojosr.framework.launch.BundleDescriptor)2 File (java.io.File)2 HashMap (java.util.HashMap)2 PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)1 PojoServiceRegistry (de.kalpatec.pojosr.framework.launch.PojoServiceRegistry)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 JarInputStream (java.util.jar.JarInputStream)1 TinyBundle (org.ops4j.pax.swissbox.tinybundles.core.TinyBundle)1 NodeList (org.w3c.dom.NodeList)1