Search in sources :

Example 26 with SubsystemException

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

the class SubsystemResource method computeDependencies.

void computeDependencies(DeploymentManifest manifest, Coordination coordination) {
    if (manifest == null) {
        computeDependencies(getSubsystemManifest(), coordination);
    } else {
        ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
        if (header == null)
            return;
        for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
            Resource resource = findDependency(clause);
            if (resource == null)
                throw new SubsystemException("A required dependency could not be found. This means the resource was either missing or not recognized as a supported resource format due to, for example, an invalid bundle manifest or blueprint XML file. Turn on debug logging for more information. The resource was: " + resource);
            addDependency(resource);
        }
    }
}
Also used : ProvisionResourceHeader(org.apache.aries.subsystem.core.archive.ProvisionResourceHeader) SubsystemException(org.osgi.service.subsystem.SubsystemException) Resource(org.osgi.resource.Resource)

Example 27 with SubsystemException

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

the class WovenClassListener method modified.

@Override
public void modified(WovenClass wovenClass) {
    if (wovenClass.getState() != WovenClass.TRANSFORMED) {
        // the defined state is reached.
        return;
    }
    List<String> dynamicImports = wovenClass.getDynamicImports();
    if (dynamicImports.isEmpty()) {
        // Nothing to do if there are no dynamic imports.
        return;
    }
    BundleWiring wiring = wovenClass.getBundleWiring();
    Bundle bundle = wiring.getBundle();
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    BundleConstituent constituent = new BundleConstituent(null, revision);
    Collection<BasicSubsystem> basicSubsystems = subsystems.getSubsystemsByConstituent(constituent);
    BasicSubsystem subsystem = basicSubsystems.iterator().next();
    // Find the scoped subsystem in the region.
    subsystem = scopedSubsystem(subsystem);
    if (subsystem.getSubsystemId() == 0) {
        // The root subsystem needs no sharing policy.
        return;
    }
    if (EnumSet.of(Subsystem.State.INSTALLING, Subsystem.State.INSTALLED).contains(subsystem.getState())) {
        // The scoped subsystem must be resolved before adding dynamic 
        // package imports to the sharing policy in order to minimize 
        // unpredictable wirings. Resolving the scoped subsystem will also
        // resolve all of the unscoped subsystems in the region.
        AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.RESOLVE_ONLY));
    }
    Bundle systemBundle = context.getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION);
    FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
    // The following map tracks all of the necessary updates as each dynamic
    // import is processed. The key is the tail region of the connection 
    // whose filter needs updating.
    Map<Region, RegionUpdaterInfo> updates = new HashMap<Region, RegionUpdaterInfo>();
    for (String dynamicImport : dynamicImports) {
        // For each dynamic import, collect the necessary update information.
        DynamicImportPackageHeader header = new DynamicImportPackageHeader(dynamicImport);
        List<DynamicImportPackageRequirement> requirements = header.toRequirements(revision);
        for (DynamicImportPackageRequirement requirement : requirements) {
            Collection<BundleCapability> providers = frameworkWiring.findProviders(requirement);
            if (providers.isEmpty()) {
                // import, no updates are made.
                continue;
            }
            addSharingPolicyUpdates(requirement, subsystem, providers, updates);
        }
    }
    // Now update each sharing policy only once.
    for (RegionUpdaterInfo update : updates.values()) {
        RegionUpdater updater = new RegionUpdater(update.tail(), update.head());
        try {
            updater.addRequirements(update.requirements());
        } catch (IllegalStateException e) {
        // Something outside of the subsystems implementation has
        // deleted the edge between the parent and child subsystems.
        // Assume the dynamic import sharing policy is being handled
        // elsewhere. See ARIES-1429.
        } catch (Exception e) {
            throw new SubsystemException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) SubsystemException(org.osgi.service.subsystem.SubsystemException) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) SubsystemException(org.osgi.service.subsystem.SubsystemException) DynamicImportPackageHeader(org.apache.aries.subsystem.core.archive.DynamicImportPackageHeader) BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) DynamicImportPackageRequirement(org.apache.aries.subsystem.core.archive.DynamicImportPackageRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 28 with SubsystemException

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

the class InstallTest method testLocationAsEmptyString.

@Test
public void testLocationAsEmptyString() throws Exception {
    try {
        Subsystem a = installSubsystemFromFile(getRootSubsystem(), new File(APPLICATION_A), "");
        try {
            BasicSubsystem basic = (BasicSubsystem) a;
            String location = basic.getLocation();
            assertEquals("Location value should be an empty string", "", location);
        } finally {
            uninstallSubsystemSilently(a);
        }
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) File(java.io.File) Test(org.junit.Test)

Example 29 with SubsystemException

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

the class ResolutionTest method testMissingNativeCodeRequirement.

@Test
public void testMissingNativeCodeRequirement() throws Exception {
    Subsystem applicationE = null;
    try {
        applicationE = installSubsystemFromFile(APPLICATION_E);
    // TODO this should fail to intsall
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Installation should succeed for Bundle-NativeCode");
    }
    try {
        applicationE.start();
        fail("Expected to fail to install");
    } catch (Exception e) {
    // expected 
    } finally {
        uninstallSubsystemSilently(applicationE);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) ResolutionException(org.osgi.service.resolver.ResolutionException) Test(org.junit.Test)

Example 30 with SubsystemException

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

the class ResolutionTest method testContentWithNonConstituentDependencyWithNonConstituentDependency.

/*
	 * Test that the right regions are used when validating capabilities.
	 * 
	 * Application A contains a content bundle requiring capability A. Bundle B
	 * provides capability A and is available as an installable resource from a
	 * repository service. Bundle B also requires capability B. Bundle C is an
	 * already installed resource in the root subsystem providing capability B.
	 * When validating capability A, the subsystem should use the root region as
	 * the from region, and its own region as the to region. When validating 
	 * capability B, the subsystem should use the root region as the from region
	 * as well as for the to region.
	 */
@Test
public void testContentWithNonConstituentDependencyWithNonConstituentDependency() throws Exception {
    // Register a repository service containing bundle B requiring
    // capability B and providing capability A.
    registerRepositoryService(BUNDLE_B);
    Subsystem root = getRootSubsystem();
    // Install unmanaged bundle C providing capability B as a constituent 
    // of the root subsystem.
    Bundle bundleC = installBundleFromFile(BUNDLE_C, root);
    try {
        // Install application A with content bundle A requiring
        // capability A.
        Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
        // Make sure the Require-Capability exists for capability a...
        assertHeaderExists(applicationA, Constants.REQUIRE_CAPABILITY);
        // ...but not for capability b.
        RequireCapabilityHeader header = new RequireCapabilityHeader(applicationA.getSubsystemHeaders(null).get(Constants.REQUIRE_CAPABILITY));
        assertEquals("Wrong number of clauses", 1, header.getClauses().size());
        Clause clause = header.getClauses().iterator().next();
        assertEquals("Wrong path", "a", clause.getPath());
        assertEquals("Wrong resolution directive", Constants.RESOLUTION_MANDATORY, clause.getDirective(Constants.RESOLUTION_DIRECTIVE).getValue());
        assertEquals("Wrong effective directive", Constants.EFFECTIVE_RESOLVE, clause.getDirective(Constants.EFFECTIVE_DIRECTIVE).getValue());
        try {
            // Make sure the runtime resolution works as well.
            applicationA.start();
        } catch (SubsystemException e) {
            fail("Application A should have started");
        } finally {
            stopAndUninstallSubsystemSilently(applicationA);
        }
    } catch (SubsystemException e) {
        fail("Application A should have installed." + e.getMessage());
    } finally {
        uninstallSilently(bundleC);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Clause(org.apache.aries.subsystem.core.archive.Clause) Test(org.junit.Test)

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