use of org.osgi.resource.Requirement 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();
}
use of org.osgi.resource.Requirement 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.osgi.resource.Requirement in project aries by apache.
the class SubsystemResource method computeContentResources.
private void computeContentResources(SubsystemManifest manifest) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader();
if (contentHeader == null)
return;
for (SubsystemContentHeader.Clause clause : contentHeader.getClauses()) {
Requirement requirement = clause.toRequirement(this);
Resource resource = findContent(requirement);
if (resource == null) {
if (clause.isMandatory())
throw new SubsystemException("A required content resource could not be found. This means the resource was either missing or not recognized as a supported resource format due to, for example, an invalid bundle manifest or blueprint XML file. Turn on debug logging for more information. The resource was: " + requirement);
continue;
}
addContentResource(resource);
}
}
use of org.osgi.resource.Requirement in project aries by apache.
the class SubsystemResource method getRequirements.
@Override
public List<Requirement> getRequirements(String namespace) {
if (isScoped())
return resource.getRequirements(namespace);
else {
ArrayList<Requirement> result = new ArrayList<Requirement>();
result.addAll(resource.getRequirements(namespace));
for (Resource r : getContentResources()) result.addAll(r.getRequirements(namespace));
result.trimToSize();
return result;
}
}
use of org.osgi.resource.Requirement in project aries by apache.
the class Aries1425Test method testToRequirement.
@Test
public void testToRequirement() {
SubsystemContentHeader header = new SubsystemContentHeader(HEADER_1);
Collection<SubsystemContentHeader.Clause> clauses = header.getClauses();
assertEquals("Wrong size", 3, clauses.size());
Map<String, SubsystemContentHeader.Clause> map = new HashMap<String, SubsystemContentHeader.Clause>(3);
for (SubsystemContentHeader.Clause clause : clauses) {
map.put(clause.toString(), clause);
}
Resource resource = new Resource() {
@Override
public List<Capability> getCapabilities(String namespace) {
return Collections.emptyList();
}
@Override
public List<Requirement> getRequirements(String namespace) {
return Collections.emptyList();
}
};
SubsystemContentHeader.Clause clause = map.get(BUNDLE_A);
Requirement requirement = clause.toRequirement(resource);
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
clause = map.get(BUNDLE_B);
requirement = clause.toRequirement(resource);
assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
clause = map.get(BUNDLE_C);
requirement = clause.toRequirement(resource);
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
}
Aggregations