Search in sources :

Example 6 with Requirement

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

the class RawSubsystemResource method createFakeResource.

private static Resource createFakeResource(SubsystemManifest manifest) {
    Header<?> importServiceHeader = manifest.getHeaders().get(APPLICATION_IMPORT_SERVICE_HEADER);
    if (importServiceHeader == null) {
        return null;
    }
    List<Capability> modifiableCaps = new ArrayList<Capability>();
    final List<Capability> fakeCapabilities = Collections.unmodifiableList(modifiableCaps);
    Resource fakeResource = new Resource() {

        @Override
        public List<Capability> getCapabilities(String namespace) {
            if (namespace == null) {
                return fakeCapabilities;
            }
            List<Capability> results = new ArrayList<Capability>();
            for (Capability capability : fakeCapabilities) {
                if (namespace.equals(capability.getNamespace())) {
                    results.add(capability);
                }
            }
            return results;
        }

        @Override
        public List<Requirement> getRequirements(String namespace) {
            return Collections.emptyList();
        }
    };
    modifiableCaps.add(new OsgiIdentityCapability(fakeResource, Constants.ResourceTypeSynthesized, new Version(1, 0, 0), Constants.ResourceTypeSynthesized));
    Map<String, Map<String, String>> serviceImports = ManifestHeaderProcessor.parseImportString(importServiceHeader.getValue());
    for (Entry<String, Map<String, String>> serviceImport : serviceImports.entrySet()) {
        Collection<String> objectClasses = new ArrayList<String>(Arrays.asList(serviceImport.getKey()));
        String filter = serviceImport.getValue().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
        BasicCapability.Builder capBuilder = new BasicCapability.Builder();
        capBuilder.namespace(ServiceNamespace.SERVICE_NAMESPACE);
        capBuilder.attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClasses);
        if (filter != null)
            capBuilder.attributes(new HashMap<String, Object>(SimpleFilter.attributes(filter)));
        capBuilder.attribute("service.imported", "");
        capBuilder.resource(fakeResource);
        modifiableCaps.add(capBuilder.build());
    }
    return fakeResource;
}
Also used : Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) Version(org.osgi.framework.Version) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with Requirement

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

the class RawSubsystemResource method computeRequirements.

private List<Requirement> computeRequirements(SubsystemManifest manifest) throws ResolutionException {
    if (isComposite(manifest)) {
        // Composites determine their own requirements.
        return manifest.toRequirements(this);
    }
    // Gather up all of the content resources for the subsystem.
    SubsystemContentHeader header = manifest.getSubsystemContentHeader();
    if (header == null) {
        // Empty subsystems (i.e. subsystems with no content) are allowed.
        return Collections.emptyList();
    }
    List<Requirement> requirements = header.toRequirements(this);
    List<Resource> resources = new ArrayList<Resource>(requirements.size());
    // TODO Do we need the system repository in here (e.g., for features)?
    // What about the preferred provider repository?
    // Search the local repository and service repositories for content.
    RepositoryServiceRepository serviceRepo = new RepositoryServiceRepository();
    // TODO Should we search the service repositories first, the assumption
    // being they will contain more current content than the subsystem
    // archive?
    CompositeRepository compositeRepo = new CompositeRepository(localRepository, serviceRepo);
    for (Requirement requirement : requirements) {
        Collection<Capability> capabilities = compositeRepo.findProviders(requirement);
        if (!capabilities.isEmpty()) {
            resources.add(capabilities.iterator().next().getResource());
        }
    }
    if (fakeImportServiceResource != null) {
        // Add the fake resource so the dependency calculator knows not to
        // return service requirements that are included in 
        // Application-ImportService.
        resources.add(fakeImportServiceResource);
    }
    // dependencies not satisfied by the content resources themselves.
    return new DependencyCalculator(resources).calculateDependencies();
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource)

Example 8 with Requirement

use of org.osgi.resource.Requirement 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 9 with Requirement

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

the class RawSubsystemResource method getRequirements.

@Override
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);
}
Also used : Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList)

Example 10 with Requirement

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

the class OsgiRequirementAdapterTest method testIsMultipleTrue.

@Test
public void testIsMultipleTrue() {
    Requirement req = EasyMock.createNiceMock(Requirement.class);
    Map<String, String> directives = new HashMap<String, String>();
    directives.put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
    EasyMock.expect(req.getDirectives()).andReturn(directives);
    EasyMock.replay(req);
    OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
    assertTrue("Requirement was not multiple", adapter.isMultiple());
}
Also used : Requirement(org.osgi.resource.Requirement) HashMap(java.util.HashMap) OsgiRequirementAdapter(org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter) Test(org.junit.Test)

Aggregations

Requirement (org.osgi.resource.Requirement)193 Capability (org.osgi.resource.Capability)102 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)46 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 HashMap (java.util.HashMap)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)14 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9