use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class ScopeUpdateImpl method uninstall.
private void uninstall(ScopeImpl scope) throws BundleException {
for (Scope child : scope.getChildren()) {
uninstall((ScopeImpl) child);
}
Collection<Bundle> bundles = new HashSet<Bundle>(scope.getBundles());
for (Bundle bundle : bundles) {
if (!contains(bundle, null)) {
bundle.uninstall();
}
}
scope.getScopes().removeScope(scope);
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class BasicTest method testRootScopeInitialState.
/**
* Basic test of the initial state of the root scope.
*/
@Test
public void testRootScopeInitialState() {
Scope scope = getScope();
Collection<Bundle> bundles = Arrays.asList(bundleContext.getBundles());
assertCollectionEquals(bundles, scope.getBundles());
assertEmpty(scope.getChildren());
assertEquals(0, scope.getId());
assertNull(scope.getLocation());
assertEquals("root", scope.getName());
assertNull(scope.getParent());
assertEmpty(scope.getSharePolicies(SharePolicy.TYPE_EXPORT));
assertEmpty(scope.getSharePolicies(SharePolicy.TYPE_IMPORT));
assertNotNull(scope.newScopeUpdate());
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class BundleVisibilityTest method test1.
/**
* Install a bundle into the same scope as this one. Both bundles should be
* able to see each other.
* @throws Exception
*/
@Test
public void test1() throws Exception {
Scope scope = getScope();
assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
String location = getBundleLocation("tb-4.jar");
assertNull(bundleContext.getBundle(location));
URL url = new URL(location);
InstallInfo installInfo = new InstallInfo(location, url.openStream());
scopeUpdate.getBundlesToInstall().add(installInfo);
scopeUpdate.commit();
Bundle bundle = bundleContext.getBundle(location);
assertTrue(scope.getBundles().contains(bundle));
bundle.start();
ServiceReference<BundleProvider> bundleProviderRef = bundleContext.getServiceReference(BundleProvider.class);
BundleProvider bundleProvider = bundleContext.getService(bundleProviderRef);
assertTrue(bundleProvider.getBundles().contains(bundleContext.getBundle()));
assertTrue(Arrays.asList(bundleContext.getBundles()).contains(bundle));
assertNotNull(bundleContext.getBundle(bundle.getBundleId()));
assertNotNull(bundleProvider.getBundle(bundle.getBundleId()));
bundleContext.ungetService(bundleProviderRef);
bundle.uninstall();
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class BundleVisibilityTest method test2.
/**
* Install a bundle into a different scope than this one. Neither bundle
* should be able to see the other.
* @throws Exception
*/
@Test
public void test2() throws Exception {
Scope scope = getScope();
assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
ScopeUpdate child = scopeUpdate.newChild("tb4");
scopeUpdate.getChildren().add(child);
String location = getBundleLocation("tb-4.jar");
assertNull(bundleContext.getBundle(location));
URL url = new URL(location);
InstallInfo installInfo = new InstallInfo(location, url.openStream());
child.getBundlesToInstall().add(installInfo);
addPackageImportPolicy("org.osgi.framework", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
addServiceExportPolicy(BundleProvider.class, child);
scopeUpdate.commit();
Bundle bundle = bundleContext.getBundle(location);
assertNotNull(bundle);
Collection<Scope> childScopes = scope.getChildren();
assertEquals(1, childScopes.size());
assertTrue(childScopes.iterator().next().getBundles().contains(bundle));
bundle.start();
ServiceReference<BundleProvider> bundleProviderRef = bundleContext.getServiceReference(BundleProvider.class);
BundleProvider bundleProvider = bundleContext.getService(bundleProviderRef);
assertFalse(Arrays.asList(bundleContext.getBundles()).contains(bundle));
assertNull(bundleContext.getBundle(bundle.getBundleId()));
assertFalse(bundleProvider.getBundles().contains(bundleContext.getBundle()));
assertNull(bundleProvider.getBundle(bundleContext.getBundle().getBundleId()));
bundleContext.ungetService(bundleProviderRef);
bundle.uninstall();
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class GetScopeServiceTest method test2.
/**
* The tb3 bundle should also be in and receive the root scope by default.
* @throws Exception
*/
@Test
public void test2() throws Exception {
Bundle bundle = installBundle("tb-3.jar");
bundle.start();
ServiceReference<ScopeProvider> scopeProviderRef = bundleContext.getServiceReference(ScopeProvider.class);
ScopeProvider scopeProvider = bundleContext.getService(scopeProviderRef);
Scope scope = scopeProvider.getScope();
assertEquals(getScope(), scope);
assertTrue(scope.getBundles().contains(bundle));
bundleContext.ungetService(scopeProviderRef);
bundle.uninstall();
}
Aggregations