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);
}
}
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;
}
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);
}
}
}
}
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();
}
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;
}
Aggregations