Search in sources :

Example 1 with BundleConstituent

use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent 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 2 with BundleConstituent

use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.

the class ResolveContext method addWiring.

private void addWiring(Resource resource, Map<Resource, Wiring> wirings) {
    if (resource instanceof BundleConstituent) {
        BundleConstituent bc = (BundleConstituent) resource;
        BundleWiring wiring = bc.getWiring();
        if (wiring != null) {
            wirings.put(bc.getBundle().adapt(BundleRevision.class), wiring);
        }
    } else if (resource instanceof BundleRevision) {
        BundleRevision br = (BundleRevision) resource;
        BundleWiring wiring = br.getWiring();
        if (wiring != null) {
            wirings.put(br, wiring);
        }
    }
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 3 with BundleConstituent

use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.

the class ResolveContext method installDependenciesOfRequirerIfNecessary.

private void installDependenciesOfRequirerIfNecessary(Requirement requirement) {
    if (requirement == null) {
        return;
    }
    Resource requirer = requirement.getResource();
    if (resource.equals(requirer)) {
        return;
    }
    Collection<BasicSubsystem> subsystems;
    if (requirer instanceof BasicSubsystem) {
        BasicSubsystem subsystem = (BasicSubsystem) requirer;
        subsystems = Collections.singletonList(subsystem);
    } else if (requirer instanceof BundleRevision) {
        BundleRevision revision = (BundleRevision) requirer;
        BundleConstituent constituent = new BundleConstituent(null, revision);
        subsystems = Activator.getInstance().getSubsystems().getSubsystemsByConstituent(constituent);
    } else {
        return;
    }
    for (BasicSubsystem subsystem : subsystems) {
        if (Utils.isProvisionDependenciesInstall(subsystem) || !State.INSTALLING.equals(subsystem.getState())) {
            continue;
        }
        AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.INSTALL_ONLY));
    }
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) Resource(org.osgi.resource.Resource) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 4 with BundleConstituent

use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent 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 5 with BundleConstituent

use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent 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)

Aggregations

BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 BundleRevision (org.osgi.framework.wiring.BundleRevision)7 Resource (org.osgi.resource.Resource)3 Bundle (org.osgi.framework.Bundle)2 BundleWiring (org.osgi.framework.wiring.BundleWiring)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DynamicImportPackageHeader (org.apache.aries.subsystem.core.archive.DynamicImportPackageHeader)1 DynamicImportPackageRequirement (org.apache.aries.subsystem.core.archive.DynamicImportPackageRequirement)1 Region (org.eclipse.equinox.region.Region)1 FilteredRegion (org.eclipse.equinox.region.RegionDigraph.FilteredRegion)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)1 SubsystemException (org.osgi.service.subsystem.SubsystemException)1