Search in sources :

Example 46 with SubsystemException

use of org.osgi.service.subsystem.SubsystemException in project aries by apache.

the class SubsystemGraph method add.

public synchronized void add(BasicSubsystem parent, BasicSubsystem child) {
    SubsystemWrapper parentWrap = new SubsystemWrapper(parent);
    SubsystemWrapper childWrap = new SubsystemWrapper(child);
    if (containsAncestor(childWrap, parentWrap))
        throw new SubsystemException("Cycle detected between '" + parentWrap + "' and '" + childWrap + "'");
    Collection<SubsystemWrapper> subsystems = adjacencyList.get(childWrap);
    if (subsystems == null) {
        subsystems = new HashSet<SubsystemWrapper>();
        adjacencyList.put(childWrap, subsystems);
    }
    subsystems = adjacencyList.get(parentWrap);
    if (subsystems == null) {
        subsystems = new HashSet<SubsystemWrapper>();
        adjacencyList.put(parentWrap, subsystems);
    }
    subsystems.add(childWrap);
}
Also used : SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 47 with SubsystemException

use of org.osgi.service.subsystem.SubsystemException in project aries by apache.

the class Aries1445Test method test.

private void test(String type1, String type2) throws Exception {
    serviceRegistrations.add(bundleContext.registerService(Repository.class, new TestRepository.Builder().resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "b.package").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion)).requirement(new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=c.package)")).requirement(new TestRequirement.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).directive(ServiceNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(objectClass=foo.Bar)").directive(ServiceNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, ServiceNamespace.EFFECTIVE_ACTIVE)).content(new BundleArchiveBuilder().symbolicName("b").exportPackage("b.package").importPackage("c.package").requireCapability("osgi.service;filter:=\"(objectClass=foo.Bar)\";effective:=active").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "c").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "c.package").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion)).content(new BundleArchiveBuilder().symbolicName("c").exportPackage("c.package").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "d").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).attribute(Constants.OBJECTCLASS, "foo.Bar").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).directive(ServiceNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE, ServiceNamespace.EFFECTIVE_ACTIVE)).content(new BundleArchiveBuilder().symbolicName("d").provideCapability("osgi.service;objectClass=foo.Bar;effective:=active").buildAsBytes()).build()).build(), null));
    Subsystem root = getRootSubsystem();
    Subsystem s1 = installSubsystem(root, "s1", buildSubsystem(root, "s1", type1));
    uninstallableSubsystems.add(s1);
    startSubsystem(s1);
    stoppableSubsystems.add(s1);
    Subsystem s2 = installSubsystem(root, "s2", buildSubsystem(root, "s2", type2));
    uninstallableSubsystems.add(s2);
    stopSubsystem(s1);
    stoppableSubsystems.remove(s1);
    uninstallSubsystem(s1);
    uninstallableSubsystems.remove(s1);
    getSystemBundleAsFrameworkWiring().refreshBundles(null, (FrameworkListener) null);
    try {
        s2.start();
        stoppableSubsystems.add(s2);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have started");
    }
    // Test the effective:=active service capability and requirement. Bundle
    // D should have had a reference count of 2 and not uninstalled as part
    // of S1. Because effective:=active does not effect runtime resolution,
    // we must ensure it is still a constituent of root.
    assertConstituent(root, "d");
}
Also used : TestRepository(org.apache.aries.subsystem.itests.util.TestRepository) Repository(org.osgi.service.repository.Repository) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) TestCapability(org.apache.aries.subsystem.itests.util.TestCapability) TestRepositoryContent(org.apache.aries.subsystem.itests.util.TestRepositoryContent)

Example 48 with SubsystemException

use of org.osgi.service.subsystem.SubsystemException in project aries by apache.

the class Aries1522Test method test.

private void test(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    Subsystem root = getRootSubsystem();
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).content("org.apache.aries.subsystem.itests.aries1523host,org.apache.aries.subsystem.itests.aries1523fragment").bundle("aries1523host", getClass().getClassLoader().getResourceAsStream("aries1523/aries1523host.jar")).build(), flag);
        try {
            startSubsystem(subsystem, flag);
            stopSubsystem(subsystem);
        } catch (SubsystemException e) {
            e.printStackTrace();
            fail("Subsystem should have started");
        } finally {
            uninstallSubsystemSilently(subsystem);
        }
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 49 with SubsystemException

use of org.osgi.service.subsystem.SubsystemException in project aries by apache.

the class Aries1538Test method testHostFragmentCircularDependency.

private void testHostFragmentCircularDependency(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    BundleArchiveBuilder hostBuilder = new BundleArchiveBuilder();
    hostBuilder.symbolicName("host");
    hostBuilder.exportPackage("foo");
    hostBuilder.importPackage("bar");
    BundleArchiveBuilder fragmentBuilder = new BundleArchiveBuilder();
    fragmentBuilder.symbolicName("fragment");
    fragmentBuilder.exportPackage("bar");
    fragmentBuilder.importPackage("foo");
    fragmentBuilder.header("Fragment-Host", "host");
    Subsystem root = getRootSubsystem();
    Bundle host = root.getBundleContext().installBundle("host", hostBuilder.build());
    uninstallableBundles.add(host);
    Bundle fragment = root.getBundleContext().installBundle("fragment", fragmentBuilder.build());
    uninstallableBundles.add(fragment);
    startBundle(host);
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("foo").build()).build(), flag);
        uninstallableSubsystems.add(subsystem);
        startSubsystem(subsystem, flag);
        stoppableSubsystems.add(subsystem);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed and started");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 50 with SubsystemException

use of org.osgi.service.subsystem.SubsystemException in project aries by apache.

the class Aries1538Test method testSubstitutableExport.

private void testSubstitutableExport(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    BundleArchiveBuilder hostBuilder = new BundleArchiveBuilder();
    hostBuilder.symbolicName("host");
    BundleArchiveBuilder fragmentBuilder = new BundleArchiveBuilder();
    fragmentBuilder.symbolicName("fragment");
    fragmentBuilder.exportPackage("foo");
    fragmentBuilder.importPackage("foo");
    fragmentBuilder.header("Fragment-Host", "host");
    Subsystem root = getRootSubsystem();
    Bundle host = root.getBundleContext().installBundle("host", hostBuilder.build());
    uninstallableBundles.add(host);
    Bundle fragment = root.getBundleContext().installBundle("fragment", fragmentBuilder.build());
    uninstallableBundles.add(fragment);
    startBundle(host);
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("foo").build()).build(), flag);
        uninstallableSubsystems.add(subsystem);
        startSubsystem(subsystem, flag);
        stoppableSubsystems.add(subsystem);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed and started");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Aggregations

SubsystemException (org.osgi.service.subsystem.SubsystemException)61 Subsystem (org.osgi.service.subsystem.Subsystem)39 Test (org.junit.Test)32 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)23 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)19 SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)15 Bundle (org.osgi.framework.Bundle)11 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)7 Resource (org.osgi.resource.Resource)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)5 BundleException (org.osgi.framework.BundleException)5 Requirement (org.osgi.resource.Requirement)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 BundleRevision (org.osgi.framework.wiring.BundleRevision)3 Repository (org.osgi.service.repository.Repository)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 DeploymentManifest (org.apache.aries.subsystem.core.archive.DeploymentManifest)2