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