Search in sources :

Example 46 with Resource

use of org.osgi.resource.Resource in project aries by apache.

the class SubsystemResource method computeDependencies.

void computeDependencies(DeploymentManifest manifest, Coordination coordination) {
    if (manifest == null) {
        computeDependencies(getSubsystemManifest(), coordination);
    } else {
        ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
        if (header == null)
            return;
        for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
            Resource resource = findDependency(clause);
            if (resource == null)
                throw new SubsystemException("A required dependency 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: " + resource);
            addDependency(resource);
        }
    }
}
Also used : ProvisionResourceHeader(org.apache.aries.subsystem.core.archive.ProvisionResourceHeader) SubsystemException(org.osgi.service.subsystem.SubsystemException) Resource(org.osgi.resource.Resource)

Example 47 with Resource

use of org.osgi.resource.Resource 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)));
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability) Test(org.junit.Test)

Example 48 with Resource

use of org.osgi.resource.Resource in project aries by apache.

the class Aries1453Test method shouldResolveFragmentHostWithVersionRangeAndMatchWithBundlesInThatRange.

@Test
public void shouldResolveFragmentHostWithVersionRangeAndMatchWithBundlesInThatRange() {
    FragmentHostHeader header = new FragmentHostHeader("host-bundle;bundle-version=\"[9.6.0,10)\"");
    FragmentHostRequirement requirement = new FragmentHostRequirement(header.getClauses().iterator().next(), null);
    FragmentHostCapability capability = new FragmentHostCapability(new BundleSymbolicNameHeader("host-bundle"), new BundleVersionHeader("9.6.1"), new Resource() {

        @Override
        public List<Capability> getCapabilities(String namespace) {
            return null;
        }

        @Override
        public List<Requirement> getRequirements(String namespace) {
            return null;
        }
    });
    String filterDirective = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
    SimpleFilter simpleFilter = SimpleFilter.parse(filterDirective);
    CapabilitySet capabilitySet = new CapabilitySet(Arrays.asList(HostNamespace.HOST_NAMESPACE), true);
    capabilitySet.addCapability(capability);
    Set<Capability> capabilities = capabilitySet.match(simpleFilter, true);
    Assert.assertTrue(capabilities.size() == 1);
    Assert.assertSame(capabilities.iterator().next(), capability);
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) SimpleFilter(org.apache.aries.subsystem.core.capabilityset.SimpleFilter) CapabilitySet(org.apache.aries.subsystem.core.capabilityset.CapabilitySet) List(java.util.List) Test(org.junit.Test)

Example 49 with Resource

use of org.osgi.resource.Resource in project aries by apache.

the class BundleRequiredExecutionEnvironmentHeaderTest method assertRequirement.

private void assertRequirement(BundleRequiredExecutionEnvironmentHeader.Clause clause, String filter) {
    Resource resource = EasyMock.createNiceMock(Resource.class);
    assertRequirement(clause.toRequirement(resource), filter, resource);
}
Also used : Resource(org.osgi.resource.Resource)

Example 50 with Resource

use of org.osgi.resource.Resource in project aries by apache.

the class BundleRequiredExecutionEnvironmentHeaderTest method testHeaderWithOneClause.

@SuppressWarnings("deprecation")
@Test
public void testHeaderWithOneClause() {
    String value = "OSGi/Minimum-1.2";
    String filter = "(&(osgi.ee=OSGi/Minimum)(version=1.2.0))";
    BundleRequiredExecutionEnvironmentHeader header = new BundleRequiredExecutionEnvironmentHeader(value);
    assertEquals("Wrong number of clauses", 1, header.getClauses().size());
    assertClause(header.getClauses().iterator().next(), value, "OSGi/Minimum", "1.2", filter);
    assertEquals("Wrong name", Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, header.getName());
    assertEquals("Wrong value", value, header.getValue());
    Resource resource = EasyMock.createNiceMock(Resource.class);
    List<? extends Requirement> requirements = header.toRequirements(resource);
    assertEquals("Wrong number of requirements", 1, requirements.size());
    assertRequirement(requirements.get(0), filter, resource);
}
Also used : Resource(org.osgi.resource.Resource) Test(org.junit.Test)

Aggregations

Resource (org.osgi.resource.Resource)201 Capability (org.osgi.resource.Capability)62 Requirement (org.osgi.resource.Requirement)62 ArrayList (java.util.ArrayList)57 List (java.util.List)39 HashMap (java.util.HashMap)32 File (java.io.File)27 Collection (java.util.Collection)24 Wire (org.osgi.resource.Wire)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Map (java.util.Map)22 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 HashSet (java.util.HashSet)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13