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");
}
}
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);
}
}
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");
}
Aggregations