Search in sources :

Example 6 with TinyBundle

use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle 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

TinyBundle (org.ops4j.pax.swissbox.tinybundles.core.TinyBundle)6 File (java.io.File)3 URL (java.net.URL)2 PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)1 BundleDescriptor (de.kalpatec.pojosr.framework.launch.BundleDescriptor)1 PojoServiceRegistry (de.kalpatec.pojosr.framework.launch.PojoServiceRegistry)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 Test (org.junit.Test)1 NodeList (org.w3c.dom.NodeList)1