Search in sources :

Example 1 with CompositeBundle

use of org.osgi.service.framework.CompositeBundle in project aries by apache.

the class IsolatedRuntimeTest method testFrameworkResolvedBeforeInnerBundlesStart.

@Test
@Ignore
public void testFrameworkResolvedBeforeInnerBundlesStart() throws Exception {
    /*
       * Lazy bundles have in the past triggered recursive bundle trackers to handle them before
       * the composite bundle framework was even resolved. In such a case the below loadClass
       * operation on a class that depends on a class imported from the outside of the composite 
       * will fail with an NPE.
       */
    final AtomicBoolean loadedClass = new AtomicBoolean(false);
    context().addBundleListener(new SynchronousBundleListener() {

        public void bundleChanged(BundleEvent event) {
            Bundle b = event.getBundle();
            if (event.getType() == BundleEvent.STARTING || event.getType() == BundleEvent.LAZY_ACTIVATION) {
                if (b.getEntry("org/apache/aries/isolated/sample/SharedImpl.class") != null) {
                    try {
                        Class<?> cl = b.loadClass("org.apache.aries.isolated.sample.SharedImpl");
                        cl.newInstance();
                        loadedClass.set(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    }
                }
            } else if (event.getType() == BundleEvent.INSTALLED && b instanceof CompositeBundle) {
                ((CompositeBundle) b).getCompositeFramework().getBundleContext().addBundleListener(this);
            }
        }
    });
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    AriesApplicationContext ctx = manager.install(app);
    try {
        ctx.start();
        app = ctx.getApplication();
        assertEquals(1, app.getDeploymentMetadata().getApplicationDeploymentContents().size());
        assertEquals(1, app.getDeploymentMetadata().getApplicationProvisionBundles().size());
        assertTrue(loadedClass.get());
    } finally {
        manager.uninstall(ctx);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompositeBundle(org.osgi.service.framework.CompositeBundle) Bundle(org.osgi.framework.Bundle) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleEvent(org.osgi.framework.BundleEvent) PerClass(org.ops4j.pax.exam.spi.reactors.PerClass) CompositeBundle(org.osgi.service.framework.CompositeBundle) File(java.io.File) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 2 with CompositeBundle

use of org.osgi.service.framework.CompositeBundle in project aries by apache.

the class BundleFrameworkFactoryImpl method createBundleFramework.

public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config) throws BundleException {
    BundleFramework framework = null;
    ServiceReference sr = bc.getServiceReference(CompositeBundleFactory.class.getName());
    if (sr != null) {
        CompositeBundleFactory cbf = (CompositeBundleFactory) bc.getService(sr);
        CompositeBundle compositeBundle = cbf.installCompositeBundle(config.getFrameworkProperties(), config.getFrameworkID(), config.getFrameworkManifest());
        framework = new BundleFrameworkImpl(compositeBundle);
    } else
        throw new BundleException("Failed to obtain framework factory service");
    return framework;
}
Also used : BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleException(org.osgi.framework.BundleException) CompositeBundleFactory(org.osgi.service.framework.CompositeBundleFactory) CompositeBundle(org.osgi.service.framework.CompositeBundle) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with CompositeBundle

use of org.osgi.service.framework.CompositeBundle in project aries by apache.

the class InternalRecursiveBundleTracker method customizedProcessBundle.

protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event, boolean removing) {
    if (b instanceof CompositeBundle) {
        CompositeBundle cb = (CompositeBundle) b;
        // check if the compositeBundle is already tracked in the
        // BundleTrackerFactory
        String bundleScope = cb.getSymbolicName() + "_" + cb.getVersion().toString();
        List<BundleTracker> btList = BundleTrackerFactory.getBundleTrackerList(bundleScope);
        // or when the tracker is being closed.
        if (event == null && !!!removing) {
            if (cb.getState() == Bundle.INSTALLED || cb.getState() == Bundle.RESOLVED || cb.getState() == Bundle.STARTING || cb.getState() == Bundle.ACTIVE) {
                openTracker(btc, cb, bundleScope, mask);
            }
        } else {
            // if we are removing, or the event is of the right type then we need to shutdown.
            if (removing || event.getType() == BundleEvent.STOPPED || event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) {
                // if CompositeBundle is being stopped, let's remove the bundle
                // tracker(s) associated with the composite bundle
                String bundleId = b.getSymbolicName() + "/" + b.getVersion();
                alreadyRecursedContexts.remove(bundleId);
                if (btList != null) {
                    // unregister the bundlescope off the factory and close
                    // bundle trackers
                    BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope);
                }
            } else if (event.getType() == BundleEvent.INSTALLED || event.getType() == BundleEvent.RESOLVED || event.getType() == BundleEvent.STARTING) {
                openTracker(btc, cb, bundleScope, mask);
            }
        }
    }
}
Also used : BundleTracker(org.osgi.util.tracker.BundleTracker) CompositeBundle(org.osgi.service.framework.CompositeBundle)

Example 4 with CompositeBundle

use of org.osgi.service.framework.CompositeBundle in project aries by apache.

the class RecursiveBundleTrackerTest method testCompositeLifeCycle.

@Test
public void testCompositeLifeCycle() {
    makeSUT();
    CompositeBundle cb = composite("test.composite", "1.0.0");
    assertNoTrackers();
    // full lifecycle
    sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
    assertTracker(cb);
    sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
    sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTING, cb), cb);
    sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTED, cb), cb);
    sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STOPPING, cb), cb);
    sut.removedBundle(cb, new BundleEvent(BundleEvent.STOPPED, cb), cb);
    assertNoTrackers();
    // short lifecycle
    sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
    assertTracker(cb);
    sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
    sut.removedBundle(cb, new BundleEvent(BundleEvent.UNRESOLVED, cb), cb);
    assertNoTrackers();
    // shortest lifecycle
    sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
    assertTracker(cb);
    sut.removedBundle(cb, new BundleEvent(BundleEvent.UNINSTALLED, cb), cb);
    assertNoTrackers();
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) CompositeBundle(org.osgi.service.framework.CompositeBundle) Test(org.junit.Test)

Example 5 with CompositeBundle

use of org.osgi.service.framework.CompositeBundle in project aries by apache.

the class RecursiveBundleTrackerTest method composite.

private CompositeBundle composite(String symbolicName, String version) {
    CompositeBundle cb = Skeleton.newMock(CompositeBundle.class);
    Skeleton cbSkel = Skeleton.getSkeleton(cb);
    cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getSymbolicName"), symbolicName);
    cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getVersion"), new Version(version));
    return cb;
}
Also used : Version(org.osgi.framework.Version) Skeleton(org.apache.aries.unittest.mocks.Skeleton) CompositeBundle(org.osgi.service.framework.CompositeBundle) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

Aggregations

CompositeBundle (org.osgi.service.framework.CompositeBundle)5 Test (org.junit.Test)2 BundleEvent (org.osgi.framework.BundleEvent)2 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AriesApplication (org.apache.aries.application.management.AriesApplication)1 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)1 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)1 BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)1 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 MethodCall (org.apache.aries.unittest.mocks.MethodCall)1 Skeleton (org.apache.aries.unittest.mocks.Skeleton)1 Ignore (org.junit.Ignore)1 PerClass (org.ops4j.pax.exam.spi.reactors.PerClass)1 Bundle (org.osgi.framework.Bundle)1 BundleException (org.osgi.framework.BundleException)1 ServiceReference (org.osgi.framework.ServiceReference)1 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)1 Version (org.osgi.framework.Version)1 CompositeBundleFactory (org.osgi.service.framework.CompositeBundleFactory)1