Search in sources :

Example 1 with RegionFilter

use of org.eclipse.equinox.region.RegionFilter in project aries by apache.

the class Aries1435Test method testSharingPolicy.

private void testSharingPolicy(Subsystem subsystem, String dynamicImport, boolean allowed) {
    Region region = getRegion(subsystem);
    Set<FilteredRegion> filteredRegions = region.getEdges();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(PackageNamespace.PACKAGE_NAMESPACE, dynamicImport);
    map.put(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion);
    boolean wasAllowed = false;
    for (FilteredRegion filteredRegion : filteredRegions) {
        RegionFilter filter = filteredRegion.getFilter();
        if (allowed) {
            if (filter.isAllowed(PackageNamespace.PACKAGE_NAMESPACE, map)) {
                wasAllowed = true;
                break;
            }
        } else {
            assertFalse("Sharing policy should not have been updated", filter.isAllowed(PackageNamespace.PACKAGE_NAMESPACE, map));
        }
    }
    if (allowed && !wasAllowed) {
        fail("Sharing policy should have been updated");
    }
}
Also used : FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) RegionFilter(org.eclipse.equinox.region.RegionFilter) HashMap(java.util.HashMap) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion)

Example 2 with RegionFilter

use of org.eclipse.equinox.region.RegionFilter in project aries by apache.

the class SubsystemResource method setImportIsolationPolicy.

private void setImportIsolationPolicy() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
    if (isRoot() || !isScoped())
        return;
    Region region = getRegion();
    Region from = region;
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    Region to = getParents().iterator().next().getRegion();
    addSubsystemServiceImportToSharingPolicy(builder, to);
    // TODO Is this check really necessary? Looks like it was done at the beginning of this method.
    if (isScoped()) {
        // Both applications and composites have Import-Package headers that require processing.
        // In the case of applications, the header is generated.
        Header<?> header = getSubsystemManifest().getImportPackageHeader();
        setImportIsolationPolicy(builder, (ImportPackageHeader) header);
        // Both applications and composites have Require-Capability headers that require processing.
        // In the case of applications, the header is generated.
        header = getSubsystemManifest().getRequireCapabilityHeader();
        setImportIsolationPolicy(builder, (RequireCapabilityHeader) header);
        // Both applications and composites have Subsystem-ImportService headers that require processing.
        // In the case of applications, the header is generated.
        header = getSubsystemManifest().getSubsystemImportServiceHeader();
        setImportIsolationPolicy(builder, (SubsystemImportServiceHeader) header);
        header = getSubsystemManifest().getRequireBundleHeader();
        setImportIsolationPolicy(builder, (RequireBundleHeader) header);
        // Always add access to osgi.ee and osgi.native namespaces
        setImplicitAccessToNativeAndEECapabilities(builder);
    }
    RegionFilter regionFilter = builder.build();
    from.connectRegion(to, regionFilter);
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 3 with RegionFilter

use of org.eclipse.equinox.region.RegionFilter in project aries by apache.

the class SubsystemResource method setImportIsolationPolicy.

private void setImportIsolationPolicy(Map<Resource, List<Wire>> resolution) throws Exception {
    if (!isApplication()) {
        return;
    }
    SubsystemContentHeader contentHeader = getSubsystemManifest().getSubsystemContentHeader();
    // Prepare the regions and filter builder to set the sharing policy.
    Region from = getRegion();
    Region to = ((BasicSubsystem) getParents().iterator().next()).getRegion();
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    // Always provide visibility to this subsystem's service registration.
    addSubsystemServiceImportToSharingPolicy(builder, to);
    for (Resource resource : resolution.keySet()) {
        if (!contentHeader.contains(resource)) {
            continue;
        }
        // If the resource is content but the wire provider is not,
        // the sharing policy must be updated.
        List<Wire> wires = resolution.get(resource);
        for (Wire wire : wires) {
            Resource provider = wire.getProvider();
            // visible.
            if (contentHeader.contains(provider)) {
                continue;
            }
            // requirements become part of the sharing policy.
            if (!(wire.getCapability() instanceof DependencyCalculator.MissingCapability) && Constants.ResourceTypeSynthesized.equals(ResourceHelper.getTypeAttribute(provider))) {
                continue;
            }
            // The requirement must be added to the sharing policy.
            Requirement requirement = wire.getRequirement();
            List<String> namespaces = new ArrayList<String>(2);
            namespaces.add(requirement.getNamespace());
            if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespaces.get(0))) {
                // Both service capabilities and services must be visible.
                namespaces.add(RegionFilter.VISIBLE_SERVICE_NAMESPACE);
            }
            String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
            if (filter == null) {
                for (String namespace : namespaces) builder.allowAll(namespace);
            } else {
                for (String namespace : namespaces) builder.allow(namespace, filter);
            }
        }
    }
    // Always add access to osgi.ee and osgi.native namespaces
    setImplicitAccessToNativeAndEECapabilities(builder);
    // Now set the sharing policy, if the regions are different.
    RegionFilter regionFilter = builder.build();
    from.connectRegion(to, regionFilter);
}
Also used : Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) Wire(org.osgi.resource.Wire) SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) 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) RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 4 with RegionFilter

use of org.eclipse.equinox.region.RegionFilter in project karaf by apache.

the class RegionInfoCommand method showRegion.

private void showRegion(Region region) {
    BundleContext bundleContext = this.bundleContext.getBundle(0).getBundleContext();
    System.out.println(region.getName());
    if (verbose || bundles) {
        for (Long id : new TreeSet<>(region.getBundleIds())) {
            Bundle b = bundleContext.getBundle(id);
            System.out.println(String.format("  %3d  %s%s", id, getStateString(b), b));
        }
    }
    if (verbose || filters || namespaces) {
        for (RegionDigraph.FilteredRegion f : region.getEdges()) {
            System.out.println("  filter to " + f.getRegion().getName());
            if (verbose || namespaces) {
                RegionFilter rf = f.getFilter();
                for (Map.Entry<String, Collection<String>> policy : rf.getSharingPolicy().entrySet()) {
                    String namespace = policy.getKey();
                    System.out.println("    namespace: " + namespace);
                    for (String e : policy.getValue()) {
                        System.out.println("      " + e);
                    }
                }
            }
        }
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) RegionFilter(org.eclipse.equinox.region.RegionFilter) TreeSet(java.util.TreeSet) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) Map(java.util.Map) BundleContext(org.osgi.framework.BundleContext)

Example 5 with RegionFilter

use of org.eclipse.equinox.region.RegionFilter in project fabric8 by jboss-fuse.

the class SubsystemResolveContext method isResourceVisibleFromRegion.

private boolean isResourceVisibleFromRegion(Resource resource, Region region) {
    AbstractRegionDigraphVisitor<Resource> visitor = new AbstractRegionDigraphVisitor<Resource>(Collections.singletonList(resource)) {

        @Override
        protected boolean contains(Region region, Resource candidate) {
            return getRegion(candidate).equals(region);
        }

        @Override
        protected boolean isAllowed(Resource resource, RegionFilter filter) {
            List<Capability> identities = resource.getCapabilities(IDENTITY_NAMESPACE);
            if (identities != null && !identities.isEmpty()) {
                Capability identity = identities.iterator().next();
                Map<String, Object> attrs = new HashMap<String, Object>();
                attrs.put(BUNDLE_SYMBOLICNAME_ATTRIBUTE, identity.getAttributes().get(IDENTITY_NAMESPACE));
                attrs.put(BUNDLE_VERSION_ATTRIBUTE, identity.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE));
                return filter.isAllowed(VISIBLE_BUNDLE_NAMESPACE, attrs);
            }
            return false;
        }
    };
    region.visitSubgraph(visitor);
    return !visitor.getAllowed().isEmpty();
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) Region(org.eclipse.equinox.region.Region)

Aggregations

RegionFilter (org.eclipse.equinox.region.RegionFilter)9 Region (org.eclipse.equinox.region.Region)8 HashMap (java.util.HashMap)3 FilteredRegion (org.eclipse.equinox.region.RegionDigraph.FilteredRegion)3 RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Resource (org.osgi.resource.Resource)2 IOException (java.io.IOException)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ImportPackageRequirement (org.apache.aries.subsystem.core.archive.ImportPackageRequirement)1 RequireBundleRequirement (org.apache.aries.subsystem.core.archive.RequireBundleRequirement)1 RequireCapabilityRequirement (org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement)1 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 SubsystemImportServiceRequirement (org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement)1 RegionDigraph (org.eclipse.equinox.region.RegionDigraph)1 RegionDigraphVisitor (org.eclipse.equinox.region.RegionDigraphVisitor)1