use of org.apache.aries.subsystem.core.archive.RequireCapabilityHeader in project aries by apache.
the class Aries1421Test method testRequireCapability.
@Test
public void testRequireCapability() throws Exception {
Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
try {
Bundle bundleA = getConstituentAsBundle(applicationA, BUNDLE_A, null, null);
String expectedStr = bundleA.getHeaders().get(Constants.REQUIRE_CAPABILITY);
RequireCapabilityHeader expected = new RequireCapabilityHeader(expectedStr);
Map<String, String> headers = ((BasicSubsystem) applicationA).getDeploymentHeaders();
String actualStr = headers.get(Constants.REQUIRE_CAPABILITY);
RequireCapabilityHeader actual = new RequireCapabilityHeader(actualStr);
assertEquals("Wrong header", expected, actual);
} finally {
uninstallSubsystemSilently(applicationA);
}
}
use of org.apache.aries.subsystem.core.archive.RequireCapabilityHeader in project aries by apache.
the class RawSubsystemResource method computeRequireCapabilityHeader.
private RequireCapabilityHeader computeRequireCapabilityHeader() {
if (requirements.isEmpty())
return null;
ArrayList<RequireCapabilityHeader.Clause> clauses = new ArrayList<RequireCapabilityHeader.Clause>();
for (Requirement requirement : requirements) {
String namespace = requirement.getNamespace();
if (namespace.startsWith("osgi.") && !(// Don't filter out the osgi.ee namespace...
namespace.equals(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE) || // ...or the osgi.service namespace.
namespace.equals(ServiceNamespace.SERVICE_NAMESPACE)))
continue;
clauses.add(RequireCapabilityHeader.Clause.valueOf(requirement));
}
if (clauses.isEmpty())
return null;
clauses.trimToSize();
return new RequireCapabilityHeader(clauses);
}
use of org.apache.aries.subsystem.core.archive.RequireCapabilityHeader in project aries by apache.
the class ResolutionTest method testContentWithNonConstituentDependencyWithNonConstituentDependency.
/*
* Test that the right regions are used when validating capabilities.
*
* Application A contains a content bundle requiring capability A. Bundle B
* provides capability A and is available as an installable resource from a
* repository service. Bundle B also requires capability B. Bundle C is an
* already installed resource in the root subsystem providing capability B.
* When validating capability A, the subsystem should use the root region as
* the from region, and its own region as the to region. When validating
* capability B, the subsystem should use the root region as the from region
* as well as for the to region.
*/
@Test
public void testContentWithNonConstituentDependencyWithNonConstituentDependency() throws Exception {
// Register a repository service containing bundle B requiring
// capability B and providing capability A.
registerRepositoryService(BUNDLE_B);
Subsystem root = getRootSubsystem();
// Install unmanaged bundle C providing capability B as a constituent
// of the root subsystem.
Bundle bundleC = installBundleFromFile(BUNDLE_C, root);
try {
// Install application A with content bundle A requiring
// capability A.
Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
// Make sure the Require-Capability exists for capability a...
assertHeaderExists(applicationA, Constants.REQUIRE_CAPABILITY);
// ...but not for capability b.
RequireCapabilityHeader header = new RequireCapabilityHeader(applicationA.getSubsystemHeaders(null).get(Constants.REQUIRE_CAPABILITY));
assertEquals("Wrong number of clauses", 1, header.getClauses().size());
Clause clause = header.getClauses().iterator().next();
assertEquals("Wrong path", "a", clause.getPath());
assertEquals("Wrong resolution directive", Constants.RESOLUTION_MANDATORY, clause.getDirective(Constants.RESOLUTION_DIRECTIVE).getValue());
assertEquals("Wrong effective directive", Constants.EFFECTIVE_RESOLVE, clause.getDirective(Constants.EFFECTIVE_DIRECTIVE).getValue());
try {
// Make sure the runtime resolution works as well.
applicationA.start();
} catch (SubsystemException e) {
fail("Application A should have started");
} finally {
stopAndUninstallSubsystemSilently(applicationA);
}
} catch (SubsystemException e) {
fail("Application A should have installed." + e.getMessage());
} finally {
uninstallSilently(bundleC);
}
}
use of org.apache.aries.subsystem.core.archive.RequireCapabilityHeader in project aries by apache.
the class SubsystemResource method setImportIsolationPolicy.
private void setImportIsolationPolicy(RegionFilterBuilder builder, RequireCapabilityHeader header) throws InvalidSyntaxException {
if (header == null)
return;
for (RequireCapabilityHeader.Clause clause : header.getClauses()) {
RequireCapabilityRequirement requirement = new RequireCapabilityRequirement(clause, this);
String policy = requirement.getNamespace();
String filter = requirement.getDirectives().get(RequireCapabilityRequirement.DIRECTIVE_FILTER);
if (filter == null)
// A null filter directive means the requirement matches any
// capability from the same namespace.
builder.allowAll(policy);
else
// Otherwise, the capabilities must be filtered accordingly.
builder.allow(policy, filter);
}
}
use of org.apache.aries.subsystem.core.archive.RequireCapabilityHeader in project aries by apache.
the class Aries1419Test method testRequireCapability.
@Test
public void testRequireCapability() throws Exception {
Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
try {
Bundle bundleA = getConstituentAsBundle(applicationA, BUNDLE_A, null, null);
String expectedStr = bundleA.getHeaders().get(Constants.REQUIRE_CAPABILITY);
RequireCapabilityHeader expected = new RequireCapabilityHeader(expectedStr);
Map<String, String> headers = ((BasicSubsystem) applicationA).getDeploymentHeaders();
String actualStr = headers.get(Constants.REQUIRE_CAPABILITY);
RequireCapabilityHeader actual = new RequireCapabilityHeader(actualStr);
assertEquals("Wrong header", expected, actual);
} finally {
uninstallSubsystemSilently(applicationA);
}
}
Aggregations