Search in sources :

Example 1 with RequireCapabilityHeader

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 2 with RequireCapabilityHeader

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);
}
Also used : Requirement(org.osgi.resource.Requirement) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader) ArrayList(java.util.ArrayList) Clause(org.apache.aries.subsystem.core.archive.SubsystemContentHeader.Clause)

Example 3 with RequireCapabilityHeader

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Clause(org.apache.aries.subsystem.core.archive.Clause) Test(org.junit.Test)

Example 4 with RequireCapabilityHeader

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);
    }
}
Also used : RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader)

Example 5 with RequireCapabilityHeader

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) RequireCapabilityHeader(org.apache.aries.subsystem.core.archive.RequireCapabilityHeader) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Aggregations

RequireCapabilityHeader (org.apache.aries.subsystem.core.archive.RequireCapabilityHeader)5 Test (org.junit.Test)3 Bundle (org.osgi.framework.Bundle)3 Subsystem (org.osgi.service.subsystem.Subsystem)3 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)2 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)2 ArrayList (java.util.ArrayList)1 Clause (org.apache.aries.subsystem.core.archive.Clause)1 RequireCapabilityRequirement (org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement)1 Clause (org.apache.aries.subsystem.core.archive.SubsystemContentHeader.Clause)1 Requirement (org.osgi.resource.Requirement)1 SubsystemException (org.osgi.service.subsystem.SubsystemException)1