Search in sources :

Example 26 with BundleRevision

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

the class BundleInfoImpl method populateFragementInfos.

private void populateFragementInfos(Bundle bundle) {
    this.isFragment = bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
    this.fragments = new ArrayList<>();
    this.fragmentHosts = new ArrayList<>();
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    if (revisions == null) {
        return;
    }
    for (BundleRevision revision : revisions.getRevisions()) {
        if (revision.getWiring() != null) {
            getFragments(revision);
            getFragmentHosts(revision);
        }
    }
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions)

Example 27 with BundleRevision

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

the class SubsystemResource method findContent.

private Resource findContent(Requirement requirement) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
    Map<Requirement, Collection<Capability>> map;
    // the case of a persisted subsystem.
    if (isUnscoped()) {
        map = Activator.getInstance().getSystemRepository().findProviders(Collections.singleton(requirement));
        if (map.containsKey(requirement)) {
            Collection<Capability> capabilities = map.get(requirement);
            for (Capability capability : capabilities) {
                Resource provider = capability.getResource();
                if (provider instanceof BundleRevision) {
                    if (getRegion().contains(((BundleRevision) provider).getBundle())) {
                        return provider;
                    }
                } else if (provider instanceof BasicSubsystem) {
                    if (getRegion().equals(((BasicSubsystem) provider).getRegion())) {
                        return provider;
                    }
                }
            }
        }
    }
    // First search the local repository.
    map = resource.getLocalRepository().findProviders(Collections.singleton(requirement));
    Collection<Capability> capabilities = map.get(requirement);
    if (capabilities.isEmpty()) {
        // Nothing found in the local repository so search the repository services.
        capabilities = new RepositoryServiceRepository().findProviders(requirement);
    }
    if (capabilities.isEmpty()) {
        // Nothing found period.
        return null;
    }
    for (Capability capability : capabilities) {
        if (!IdentityNamespace.TYPE_FRAGMENT.equals(capability.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE))) {
            // See ARIES-1425.
            return capability.getResource();
        }
    }
    // Nothing here but fragment bundles. Return the first one.
    return capabilities.iterator().next().getResource();
}
Also used : RequireBundleRequirement(org.apache.aries.subsystem.core.archive.RequireBundleRequirement) Requirement(org.osgi.resource.Requirement) RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) ImportPackageRequirement(org.apache.aries.subsystem.core.archive.ImportPackageRequirement) SubsystemImportServiceRequirement(org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) BundleRevision(org.osgi.framework.wiring.BundleRevision) Collection(java.util.Collection)

Example 28 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision 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 29 with BundleRevision

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

the class SystemRepository method addingBundle.

@Override
public AtomicReference<BundleRevisionResource> addingBundle(Bundle bundle, BundleEvent event) {
    // The state mask must guarantee this will only be called when the bundle is in the INSTALLED state.
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    BundleRevisionResource resource = new BundleRevisionResource(revision);
    if (ThreadLocalSubsystem.get() == null) {
        // This is an explicitly installed bundle. It must be prevented
        // from resolving as part of adding it to the repository. Searching
        // for service requirements and capabilities will result in a call
        // to findEntries which will cause the framework to attempt a
        // resolution.
        ThreadLocalBundleRevision.set(revision);
        try {
            repository.addResource(resource);
        } finally {
            ThreadLocalBundleRevision.remove();
        }
    } else {
        // If this is a bundle being installed as part of a subsystem
        // installation, it is already protected.
        repository.addResource(resource);
    }
    return new AtomicReference<BundleRevisionResource>(resource);
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 30 with BundleRevision

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

the class SystemRepository method modifiedBundle.

@Override
public void modifiedBundle(Bundle bundle, BundleEvent event, AtomicReference<BundleRevisionResource> object) {
    if (BundleEvent.UPDATED == event.getType()) {
        BundleRevision revision = bundle.adapt(BundleRevision.class);
        BundleRevisionResource resource = new BundleRevisionResource(revision);
        repository.removeResource(object.getAndSet(resource));
        repository.addResource(resource);
    }
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)79 Bundle (org.osgi.framework.Bundle)42 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)18 BundleWiring (org.osgi.framework.wiring.BundleWiring)14 BundleCapability (org.osgi.framework.wiring.BundleCapability)13 Test (org.junit.Test)12 Map (java.util.Map)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)11 Resource (org.osgi.resource.Resource)11 HashSet (java.util.HashSet)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 BundleContext (org.osgi.framework.BundleContext)8 BundleException (org.osgi.framework.BundleException)8 List (java.util.List)7 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 BundleWire (org.osgi.framework.wiring.BundleWire)7 Requirement (org.osgi.resource.Requirement)7 File (java.io.File)6 Collection (java.util.Collection)6