Search in sources :

Example 1 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredRequirements.

@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
    Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
    BundleRevision br = (BundleRevision) a.adapt(BundleRevision.class);
    List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData[] jmxRequirements = brsMBean.getCurrentRevisionDeclaredRequirements(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(requirements.size(), jmxRequirements.length);
    Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
    Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
    Assert.assertEquals(expectedRequirements, actualRequirements);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap) Map(java.util.Map) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 2 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class BundleEventHook method handleUninstalledEvent.

@SuppressWarnings("unchecked")
private void handleUninstalledEvent(BundleEvent event) {
    Bundle bundle = event.getBundle();
    BundleRevision revision = bundleToRevision.remove(bundle);
    if (ThreadLocalSubsystem.get() != null || (revision == null ? false : // Region context bundles must be treated as explicit installations.
    revision.getSymbolicName().startsWith(Constants.RegionContextBundleSymbolicNamePrefix))) {
        return;
    }
    Collection<BasicSubsystem> subsystems;
    if (revision == null) {
        // The bundle was installed while the bundle event hook was unregistered.
        Object[] o = activator.getSubsystems().getSubsystemsByBundle(bundle);
        if (o == null)
            return;
        revision = (BundleRevision) o[0];
        subsystems = (Collection<BasicSubsystem>) o[1];
    } else {
        subsystems = activator.getSubsystems().getSubsystemsByConstituent(new BundleConstituent(null, revision));
    }
    for (BasicSubsystem subsystem : subsystems) {
        ResourceUninstaller.newInstance(revision, subsystem).uninstall();
    }
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 3 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class BundleResourceUninstaller method uninstall.

public void uninstall() {
    removeReference();
    // Always remove the bundle as a constituent of the subsystem being
    // acted upon. The bundle may or may not actually be a constituent.
    // This covers the case of unscoped subsystems with shared content
    // where the resource may not be uninstallable.
    removeConstituent(subsystem, new BundleConstituent(null, (BundleRevision) resource));
    if (!isResourceUninstallable())
        return;
    // If the resource is uninstallable, remove it from the "provisioned to"
    // subsystem in case it was a dependency. The "provisioned to" subsystem
    // may be the same subsystem as the one being acted upon. This covers
    // the case where a dependency of the subsystem being acted upon was 
    // provisioned to another subsystem but is not content of the other
    // subsystem.
    removeConstituent(provisionTo, new BundleConstituent(null, (BundleRevision) resource));
    if (isBundleUninstallable())
        uninstallBundle();
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 4 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class StartAction method getBundles.

private static Collection<Bundle> getBundles(BasicSubsystem subsystem) {
    Collection<Resource> constituents = Activator.getInstance().getSubsystems().getConstituents(subsystem);
    ArrayList<Bundle> result = new ArrayList<Bundle>(constituents.size());
    for (Resource resource : constituents) {
        if (resource instanceof BundleRevision)
            result.add(((BundleRevision) resource).getBundle());
    }
    result.trimToSize();
    return result;
}
Also used : Bundle(org.osgi.framework.Bundle) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 5 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class RegionContextBundleHelper method uninstallRegionContextBundle.

public static void uninstallRegionContextBundle(BasicSubsystem subsystem) {
    String symbolicName = SYMBOLICNAME_PREFIX + subsystem.getSubsystemId();
    Bundle bundle = subsystem.getRegion().getBundle(symbolicName, VERSION);
    if (bundle == null)
        return;
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    try {
        bundle.uninstall();
    } catch (BundleException e) {
    // TODO Should we really eat this? At least log it?
    }
    ResourceUninstaller.newInstance(revision, subsystem).uninstall();
    subsystem.setRegionContextBundle(null);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleException(org.osgi.framework.BundleException)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)66 Bundle (org.osgi.framework.Bundle)38 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)14 Map (java.util.Map)11 Test (org.junit.Test)11 BundleCapability (org.osgi.framework.wiring.BundleCapability)11 BundleWiring (org.osgi.framework.wiring.BundleWiring)11 Resource (org.osgi.resource.Resource)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 HashSet (java.util.HashSet)8 BundleWire (org.osgi.framework.wiring.BundleWire)8 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 Set (java.util.Set)6 TreeMap (java.util.TreeMap)6 TabularData (javax.management.openmbean.TabularData)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 List (java.util.List)5