Search in sources :

Example 1 with FilteredRegion

use of org.eclipse.equinox.region.RegionDigraph.FilteredRegion 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 FilteredRegion

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

the class WovenClassListener method addSharingPolicyUpdates.

private void addSharingPolicyUpdates(final DynamicImportPackageRequirement requirement, final BasicSubsystem scopedSubsystem, final Collection<BundleCapability> providers, Map<Region, RegionUpdaterInfo> updates) {
    final List<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>();
    final Map<Region, BasicSubsystem> regionToSubsystem = new HashMap<Region, BasicSubsystem>();
    regionToSubsystem(scopedSubsystem, regionToSubsystem);
    scopedSubsystem.getRegion().visitSubgraph(new RegionDigraphVisitor() {

        private final List<BasicSubsystem> visited = new ArrayList<BasicSubsystem>();

        @Override
        public void postEdgeTraverse(RegionFilter filter) {
        // Nothing.
        }

        @Override
        public boolean preEdgeTraverse(RegionFilter filter) {
            return true;
        }

        @Override
        public boolean visit(Region region) {
            BasicSubsystem subsystem = regionToSubsystem.get(region);
            if (subsystem == null || subsystem.isRoot()) {
                // sharing policy.
                return false;
            }
            if (!visited.isEmpty() && !subsystem.equals(scopedParent(visited.get(visited.size() - 1)))) {
                // We're only interested in walking up the scoped parent tree.
                return false;
            }
            visited.add(subsystem);
            if (!requirement.getPackageName().contains("*")) {
                for (BundleCapability provider : providers) {
                    BundleRevision br = provider.getResource();
                    if (region.contains(br.getBundle())) {
                        // satisfied.
                        return false;
                    }
                }
            }
            boolean allowed = false;
            Set<FilteredRegion> filters = region.getEdges();
            for (FilteredRegion filteredRegion : filters) {
                RegionFilter filter = filteredRegion.getFilter();
                if (filter.isAllowed(providers.iterator().next())) {
                    // The region already allows matching capabilities
                    // through so there is no need to update the sharing
                    // policy.
                    allowed = true;
                    break;
                }
            }
            if (!allowed) {
                // The subsystem region requires a sharing policy update.
                subsystems.add(subsystem);
            }
            // Visit the next region.
            return true;
        }
    });
    // Collect the information for the necessary sharing policy updates.
    for (BasicSubsystem subsystem : subsystems) {
        Region tail = subsystem.getRegion();
        Region head = scopedParent(subsystem).getRegion();
        RegionUpdaterInfo info = updates.get(tail);
        if (info == null) {
            info = new RegionUpdaterInfo(tail, head);
            updates.put(tail, info);
        }
        info.requirement(requirement);
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegionDigraphVisitor(org.eclipse.equinox.region.RegionDigraphVisitor) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) RegionFilter(org.eclipse.equinox.region.RegionFilter) 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 3 with FilteredRegion

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

the class Aries1435Test method assertPackageFiltersInParentConnection.

private void assertPackageFiltersInParentConnection(Subsystem subsystem, Subsystem parent, int expectedEdges, int expectedFilters) {
    Region parentRegion = getRegion(parent);
    Region region = getRegion(subsystem);
    Set<FilteredRegion> edges = region.getEdges();
    assertEquals("Wrong number of edges", expectedEdges, edges.size());
    for (FilteredRegion edge : region.getEdges()) {
        if (!edge.getRegion().equals(parentRegion)) {
            continue;
        }
        RegionFilter filter = edge.getFilter();
        Map<String, Collection<String>> policy = filter.getSharingPolicy();
        Collection<String> packages = policy.get(PackageNamespace.PACKAGE_NAMESPACE);
        assertNotNull("Wrong number of packages", packages);
        assertEquals("Wrong number of packages", expectedFilters, packages.size());
        return;
    }
    fail("No connection to parent found");
}
Also used : FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) Collection(java.util.Collection)

Aggregations

Region (org.eclipse.equinox.region.Region)3 FilteredRegion (org.eclipse.equinox.region.RegionDigraph.FilteredRegion)3 RegionFilter (org.eclipse.equinox.region.RegionFilter)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1 RegionDigraphVisitor (org.eclipse.equinox.region.RegionDigraphVisitor)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1