use of org.osgi.resource.Requirement in project aries by apache.
the class AriesSubsystemTest method testAddRequirementsKeepsEdgesOtherThanParentChild.
/*
* The region copy process when adding additional requirements should
* keep all edges, not just the ones running between parent and child. This
* is of particular concern with regard to the connections all subsystem
* regions have with the root region to allow the subsystem services
* through. However, it may also be of concern if the region digraph is
* modified outside of the subsystems API.
*/
@Test
public void testAddRequirementsKeepsEdgesOtherThanParentChild() throws Exception {
AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
try {
AriesSubsystem applicationB = (AriesSubsystem) getConstituentAsSubsystem(compositeA, APPLICATION_B, null, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION);
Region bRegion = getRegion(applicationB);
// One edge to parent for import package. One edge to root for subsystem
// service.
assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
Requirement requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework)").resource(EasyMock.createMock(Resource.class)).build();
applicationB.addRequirements(Collections.singleton(requirement));
bRegion = getRegion(applicationB);
// Still one edge to parent for import package. One edge to root for
// subsystem service.
assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
Region rootRegion = getRegion(getRootSubsystem());
// The root region won't be the tail region for any connection unless
// manually added.
assertEquals("Wrong number of edges", 0, rootRegion.getEdges().size());
// Manually add a connection from root to application B.
rootRegion.connectRegion(bRegion, rootRegion.getRegionDigraph().createRegionFilterBuilder().allow("com.foo", "(bar=b)").build());
// The root region should now have an edge.
assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
// Add another requirement to force a copy.
requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework.wiring)").resource(EasyMock.createMock(Resource.class)).build();
applicationB.addRequirements(Collections.singleton(requirement));
rootRegion = getRegion(getRootSubsystem());
// The root region should still have its edge.
assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
bRegion = getRegion(applicationB);
// Still one edge to parent for import package. One edge to root for
// subsystem service.
assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
} finally {
uninstallSubsystemSilently(compositeA);
}
}
use of org.osgi.resource.Requirement in project aries by apache.
the class AriesSubsystemTest method testAddRequirementWithVisibleBundleNamespace.
/*
* Aries Subsystems uses Equinox Region Digraph as its isolation engine.
* Digraph has a "special" namespace value that tells the region to allow
* everything a bundle offers. This test ensures that a correctly formatted
* requirement in that namespace works as expected.
*/
@Test
public void testAddRequirementWithVisibleBundleNamespace() throws Exception {
Requirement requirement = new BasicRequirement.Builder().namespace(RegionFilter.VISIBLE_BUNDLE_NAMESPACE).directive(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(id=0)").resource(EasyMock.createMock(Resource.class)).build();
AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
try {
startSubsystem(compositeA);
// Test that the installation of applicationA fails.
try {
installSubsystemFromFile(compositeA, APPLICATION_A);
fail("Subsystem should not have installed due to unresolved org.osgi.framework package requirement");
} catch (SubsystemException e) {
// Okay.
}
// Add the requirement with the region digraph specific namespace.
compositeA.addRequirements(Collections.singleton(requirement));
// Test that the installation and startup of applicationA succeeds.
AriesSubsystem applicationA;
try {
applicationA = (AriesSubsystem) installSubsystemFromFile(compositeA, APPLICATION_A);
startSubsystem(applicationA);
} catch (SubsystemException e) {
fail("Subsystem should have installed and started");
}
assertCompositeAAfter(compositeA);
} finally {
stopAndUninstallSubsystemSilently(compositeA);
}
}
use of org.osgi.resource.Requirement in project aries by apache.
the class BundleResource method getRequirements.
public List<Requirement> getRequirements(String namespace) {
if (namespace == null)
return Collections.unmodifiableList(requirements);
ArrayList<Requirement> result = new ArrayList<Requirement>(requirements.size());
for (Requirement requirement : requirements) if (namespace.equals(requirement.getNamespace()))
result.add(requirement);
result.trimToSize();
return Collections.unmodifiableList(result);
}
use of org.osgi.resource.Requirement in project aries by apache.
the class PreferredProviderRepository method addProviders.
private boolean addProviders(Requirement requirement, Repository repository, boolean checkValid) {
boolean result = false;
Map<Requirement, Collection<Capability>> map = repository.findProviders(Collections.singleton(requirement));
Collection<Capability> capabilities = map.get(requirement);
for (Capability capability : capabilities) {
if (checkValid ? isValid(capability) : true) {
this.repository.addResource(capability.getResource());
result = true;
}
}
return result;
}
use of org.osgi.resource.Requirement in project aries by apache.
the class RegionUpdater method addRequirements.
private void addRequirements(Collection<? extends Requirement> requirements, RegionFilterBuilder builder) throws InvalidSyntaxException {
for (Requirement requirement : requirements) {
String namespace = requirement.getNamespace();
// The osgi.service namespace requires translation.
if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace))
namespace = RegionFilter.VISIBLE_SERVICE_NAMESPACE;
String filter = requirement.getDirectives().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
// A null filter means import everything from that namespace.
if (filter == null)
builder.allowAll(namespace);
else
builder.allow(namespace, filter);
}
}
Aggregations