Search in sources :

Example 16 with Scope

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);
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) HashSet(java.util.HashSet)

Example 17 with 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());
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Example 18 with Scope

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();
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 19 with Scope

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();
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 20 with Scope

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();
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Aggregations

Scope (org.apache.aries.subsystem.scope.Scope)29 Bundle (org.osgi.framework.Bundle)22 Test (org.junit.Test)20 ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)16 URL (java.net.URL)12 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)12 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 Ignore (org.junit.Ignore)5 BundleException (org.osgi.framework.BundleException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)4 Filter (org.osgi.framework.Filter)4 ServiceReference (org.osgi.framework.ServiceReference)3 HelloIsolation (org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 BundleContext (org.osgi.framework.BundleContext)2 Permission (java.security.Permission)1