Search in sources :

Example 21 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class SharePolicyTest method test2.

/**
	 * Bundle tb5
	 * Bundle tb6
	 * tb5 imports package exported by tb6
	 * tb5 in root scope
	 * tb6 in child scope of root
	 * tb6 scope does not export tb6 package
	 * tb5 should not resolve
	 * @throws Exception
	 */
@Test
public void test2() throws Exception {
    Bundle tb5 = null;
    Bundle tb6 = null;
    try {
        String tb5Location = getBundleLocation("tb-5.jar");
        String tb6Location = getBundleLocation("tb-6.jar");
        InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
        InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
        ScopeUpdate scopeUpdate = getScope().newScopeUpdate();
        scopeUpdate.getBundlesToInstall().add(tb5Info);
        scopeUpdate.commit();
        tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
        assertNotNull(tb5);
        FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5 })));
        scopeUpdate = getScope().newScopeUpdate();
        ScopeUpdate tb6ScopeUpdate = scopeUpdate.newChild("tb6");
        scopeUpdate.getChildren().add(tb6ScopeUpdate);
        tb6ScopeUpdate.getBundlesToInstall().add(tb6Info);
        scopeUpdate.commit();
        tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate.getScope());
        assertNotNull(tb6);
        assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5, tb6 })));
    } finally {
        uninstallQuietly(tb6);
        uninstallQuietly(tb5);
    }
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Bundle(org.osgi.framework.Bundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 22 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class SharePolicyTest method test3.

/**
	 * Bundle tb5
	 * Bundle tb6
	 * tb5 imports package exported by tb6
	 * tb5 in root scope
	 * tb6 in child scope of root
	 * tb6 scope exports tb6 package
	 * tb5 should resolve
	 * 
	 * There is an implicit import between parent and child. In other words,
	 * anything exported by a child is automatically available without the
	 * parent explicitly importing it.
	 * 
	 * @throws Exception
	 */
@Test
public void test3() throws Exception {
    Bundle tb5 = null;
    Bundle tb6 = null;
    try {
        String tb5Location = getBundleLocation("tb-5.jar");
        String tb6Location = getBundleLocation("tb-6.jar");
        InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
        InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
        ScopeUpdate scopeUpdate = getScope().newScopeUpdate();
        scopeUpdate.getBundlesToInstall().add(tb5Info);
        scopeUpdate.commit();
        tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
        assertNotNull(tb5);
        FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5 })));
        scopeUpdate = getScope().newScopeUpdate();
        ScopeUpdate tb6ScopeUpdate = scopeUpdate.newChild("tb6");
        scopeUpdate.getChildren().add(tb6ScopeUpdate);
        tb6ScopeUpdate.getBundlesToInstall().add(tb6Info);
        addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate);
        scopeUpdate.commit();
        tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate.getScope());
        assertNotNull(tb6);
        tb5.start();
        assertTrue(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5, tb6 })));
    } finally {
        uninstallQuietly(tb6);
        uninstallQuietly(tb5);
    }
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Bundle(org.osgi.framework.Bundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 23 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class ScopeAdminTest method testPackageSharingFromTestScope.

// test sharing the helloIsolation package from the test scope.
@Test
@Ignore
public void testPackageSharingFromTestScope() throws Exception {
    // make sure we are using a framework that provides composite admin service
    assertNotNull("scope admin should not be null", scope);
    System.out.println("able to get scope admin service");
    ScopeUpdate su = scope.newScopeUpdate();
    ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
    su.getChildren().add(childScopeUpdate);
    addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
    addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
    Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
    final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" + ")");
    final Filter filter2 = FrameworkUtil.createFilter("(&" + "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
    List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
    if (packagePolicies == null) {
        packagePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
    }
    packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
    List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
    if (servicePolicies == null) {
        servicePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put("scope.share.service", servicePolicies);
    }
    servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
    // build up installInfo object for the scope
    InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT"));
    InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT"));
    List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
    bundlesToInstall.add(info1);
    bundlesToInstall.add(info2);
    // add bundles to be installed, based on subsystem content
    su.commit();
    // start all bundles in the scope scope_test1
    Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
    for (Bundle b : bundlesToStart) {
        b.start();
    }
    // install helloIsolationRef1 bundle in the root scope
    URL url1 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT");
    Bundle helloIsolationRef = bundleContext.installBundle("helloIsolationRef1-rootScope", url1.openStream());
    try {
        helloIsolationRef.start();
    } catch (Exception ex) {
        fail("should be able to start helloIsolationRef by import packages from scope_test1");
    }
    // remove helloIsolationRef
    helloIsolationRef.uninstall();
    // remove child scope
    su = scope.newScopeUpdate();
    Collection<ScopeUpdate> scopes = su.getChildren();
    childScopeUpdate = scopes.iterator().next();
    // obtain child scope admin from service registry
    //        String filter = "ScopeName=scope_test1";
    Scope childScopeAdmin = childScopeUpdate.getScope();
    assertEquals(scope, childScopeAdmin.getParent());
    scopes.remove(childScopeUpdate);
    su.commit();
    assertFalse(scope.getChildren().contains(childScopeAdmin));
    su = scope.newScopeUpdate();
    assertFalse(su.getChildren().contains(childScopeUpdate));
//        childScopeAdmin = null;
//        try {
//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
//        } catch (Exception ex) {
//            // ignore
//        }
//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Scope(org.apache.aries.subsystem.scope.Scope) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class ScopeAdminTest method testScopeAffinity.

// test ability to select the helloIsolation package from which scope it wants to use
// not necessarily the highest version one by default.
@Test
@Ignore
public void testScopeAffinity() throws Exception {
    // install helloIsolation 0.3 in scope_test1
    Scope scope1 = createScope(scope, "scope_test1", "mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT", "0.3");
    // install helloIsolation 2.0 in scope_test2
    Scope scope2 = createScope(scope, "scope_test2", "mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT", "2.0");
    // install helloIsolationRef 2.0 in scope_test3
    ScopeUpdate su = scope.newScopeUpdate();
    ScopeUpdate childScopeUpdate = su.newChild("scope_test3");
    su.getChildren().add(childScopeUpdate);
    addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
    Scope scope3 = childScopeUpdate.getScope();
    Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
    /*final Filter filter1 = FrameworkUtil.createFilter(
                "(&" + 
                  "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" +
                  "(bundle-symbolic-name=org.apache.aries.subsystem.example.helloIsolation)" + 
                  "(bundle-version<=1.1)" + 
                ")");*/
    final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" + //"(scopeName=scope_test1)" +  
    ")");
    final Filter filter2 = FrameworkUtil.createFilter("(&" + "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
    List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
    if (packagePolicies == null) {
        packagePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
    }
    packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
    List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
    if (servicePolicies == null) {
        servicePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put("scope.share.service", servicePolicies);
    }
    servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", filter2));
    // build up installInfo object for the scope
    InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT"));
    List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
    bundlesToInstall.add(info2);
    // add bundles to be installed, based on subsystem content
    su.commit();
    // start all bundles in the scope scope_test3
    Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
    for (Bundle b : bundlesToStart) {
        try {
            b.start();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("should be able to start helloIsolationRef in scope_test1");
        }
    }
    /*  // install helloIsolationRef in root scope
        URL url1 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT");
        Bundle helloIsolationRef = bundleContext.installBundle("helloIsolationRef1-rootScope", url1.openStream());
   
        try {
            helloIsolationRef.start();
        } catch (Exception ex) {
            fail("should be able to start helloIsolationRef");
        }*/
    // remove child scope - cleanup
    su = scope.newScopeUpdate();
    Collection<ScopeUpdate> scopes = su.getChildren();
    scopes.clear();
    //        scopes.add(scope1);
    //        scopes.add(scope2);
    //        scopes.add(scope3);
    su.commit();
    assertTrue(scope.getChildren().isEmpty());
    assertTrue(scope.newScopeUpdate().getChildren().isEmpty());
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Scope(org.apache.aries.subsystem.scope.Scope) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class ScopeAdminTest method createScope.

//    @org.ops4j.pax.exam.junit.Configuration
//    public static Option[] configuration() {
//        Option[] options = options(
//            // Log
//            mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
//            mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
//            // Felix Config Admin
//            mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
//            // Felix mvn url handler
//            mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
//
//
//            // this is how you set the default log level when using pax logging (logProfile)
//            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
//
//            // Bundles
//            mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
//            mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
//            mavenBundle("org.apache.aries", "org.apache.aries.util"),
//            mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
//            mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
//            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
//            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
//            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
//
//            // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
//
//            PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
//
//            equinox().version("3.7.0.v20110221")
//        );
//        options = updateOptions(options);
//        return options;
//    }
private Scope createScope(Scope scope, String scopeName, String loc, String version) throws MalformedURLException, InvalidSyntaxException, BundleException, IOException {
    ScopeUpdate su = scope.newScopeUpdate();
    ScopeUpdate childScopeUpdate = su.newChild(scopeName);
    su.getChildren().add(childScopeUpdate);
    addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
    addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
    Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
    final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" + "(version=" + version + ")" + ")");
    final Filter filter2 = FrameworkUtil.createFilter("(&" + "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
    List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
    if (packagePolicies == null) {
        packagePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
    }
    packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
    List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
    if (servicePolicies == null) {
        servicePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put("scope.share.service", servicePolicies);
    }
    servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
    // build up installInfo object for the scope
    InstallInfo info1 = new InstallInfo("helloIsolation_" + scopeName, new URL(loc));
    List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
    bundlesToInstall.add(info1);
    // add bundles to be installed, based on subsystem content
    su.commit();
    // start all bundles in the scope scope_test1
    Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
    for (Bundle b : bundlesToStart) {
        b.start();
    }
    return childScopeUpdate.getScope();
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)27 Bundle (org.osgi.framework.Bundle)22 Test (org.junit.Test)21 URL (java.net.URL)20 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)20 Scope (org.apache.aries.subsystem.scope.Scope)16 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)5 BundleException (org.osgi.framework.BundleException)5 Filter (org.osgi.framework.Filter)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 Ignore (org.junit.Ignore)4 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)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