Package org.osgi.framework.resource

Examples of org.osgi.framework.resource.Requirement


    @Test
    public void testRepositoryService() throws Exception {

        Repository repo = getRepository();
        MavenCoordinates coordinates = MavenCoordinates.parse("org.apache.felix:org.apache.felix.eventadmin:1.2.6");
        Requirement req = XRequirementBuilder.createArtifactRequirement(coordinates);
        assertNotNull("Requirement not null", req);

        Collection<Capability> caps = repo.findProviders(req);
        assertEquals("Capability not null", 1, caps.size());
View Full Code Here


        }
    }

    private Bundle installSupportBundle(BundleContext context, ModuleIdentifier moduleid) throws BundleException {
        Repository repository = getRepository(context);
        Requirement req = XRequirementBuilder.createArtifactRequirement(moduleid);
        Capability cap = repository.findProviders(req).iterator().next();
        URL location = (URL) cap.getAttributes().get(XResourceConstants.CONTENT_URL);
        return context.installBundle(location.toExternalForm());
    }
View Full Code Here

        // Try the identifier as MavenCoordinates
        if (isValidMavenIdentifier(identifier)) {
            Repository repository = injectedRepository.getValue();
            MavenCoordinates mavenId = MavenCoordinates.parse(identifier);
            Requirement req = XRequirementBuilder.createArtifactRequirement(mavenId);
            Collection<Capability> caps = repository.findProviders(req);
            if (caps.isEmpty() == false) {
                XIdentityCapability icap = (XIdentityCapability) caps.iterator().next();
                URL bundleURL = (URL) icap.getAttribute(XResourceConstants.CONTENT_URL);
                return installBundleFromURL(bundleManager, bundleURL, startLevel);
View Full Code Here

        }

        // If we have requirements remaining, then find candidates for them.
        while (remainingReqs.size() > 0)
        {
            Requirement req = remainingReqs.remove(0);

            // Ignore non-effective and dynamic requirements.
            String resolution = req.getDirectives().get(Constants.RESOLUTION_DIRECTIVE);
            if (!env.isEffective(req)
                || ((resolution != null)
// TODO: RFC-112 - We need a constant here.
                    && resolution.equals("dynamic")))
            {
View Full Code Here

        throws ResolutionException
    {
        // Create a modifiable list of the revision's requirements.
        List<Requirement> remainingReqs = new ArrayList(resource.getRequirements(null));
        // Find the host requirement.
        Requirement hostReq = null;
        for (Iterator<Requirement> it = remainingReqs.iterator();
            it.hasNext(); )
        {
            Requirement r = it.next();
            if (r.getNamespace().equals(ResourceConstants.WIRING_HOST_NAMESPACE))
            {
                hostReq = r;
                it.remove();
                break;
            }
View Full Code Here

            }

            // Copy candidates for fragment requirements to the host.
            for (Requirement r : hostRevision.getRequirements(null))
            {
                Requirement origReq =
                    ((HostedRequirement) r).getOriginalRequirement();
                SortedSet<Capability> cands = m_candidateMap.get(origReq);
                if (cands != null)
                {
                    m_candidateMap.put(r, new TreeSet<Capability>(cands));
View Full Code Here

        Map<Capability, Map<String, Map<Version, List<Requirement>>>>
            hostFragments = new HashMap<Capability,
                Map<String, Map<Version, List<Requirement>>>>();
        for (Entry<Requirement, SortedSet<Capability>> entry : m_candidateMap.entrySet())
        {
            Requirement req = entry.getKey();
            SortedSet<Capability> caps = entry.getValue();
            for (Capability cap : caps)
            {
                // Record the requirement as dependent on the capability.
                Set<Requirement> dependents = m_dependentMap.get(cap);
                if (dependents == null)
                {
                    dependents = new HashSet<Requirement>();
                    m_dependentMap.put(cap, dependents);
                }
                dependents.add(req);

                // Keep track of hosts and associated fragments.
                if (req.getNamespace().equals(ResourceConstants.WIRING_HOST_NAMESPACE))
                {
                    String resSymName = Util.getSymbolicName(req.getResource());
                    Version resVersion = Util.getVersion(req.getResource());

                    Map<String, Map<Version, List<Requirement>>>
                        fragments = hostFragments.get(cap);
                    if (fragments == null)
                    {
View Full Code Here

                // If so, then remove the optionally resolved resolved and try
                // again; otherwise, rethrow the resolve exception.
                if (rethrow != null)
                {
                    Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
                    Requirement faultyReq = ((exReqs == null) || exReqs.isEmpty())
                        ? null : exReqs.iterator().next();
                    Resource faultyRevision = (faultyReq == null)
                        ? null : getActualResource(faultyReq.getResource());
                    if (faultyReq instanceof HostedRequirement)
                    {
                        faultyRevision =
                            ((HostedRequirement) faultyReq)
                                .getOriginalRequirement().getResource();
View Full Code Here

                    // If so, then remove the optionally resolved revision and try
                    // again; otherwise, rethrow the resolve exception.
                    if (rethrow != null)
                    {
                        Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
                        Requirement faultyReq = ((exReqs == null) || exReqs.isEmpty())
                            ? null : exReqs.iterator().next();
                        Resource faultyResource = null;
                        if (faultyReq instanceof HostedRequirement)
                        {
                            faultyResource =
View Full Code Here

                // Wrap the requirement as a hosted requirement if it comes
                // from a fragment, since we will need to know the host. We
                // also need to wrap if the requirement is a dynamic import,
                // since that requirement will be shared with any other
                // matching dynamic imports.
                Requirement r = wire.getRequirement();
                if (!r.getResource().equals(wire.getRequirer())
                    || ((r.getDirectives()
                            .get(ResourceConstants.REQUIREMENT_RESOLUTION_DIRECTIVE) != null)
// TODO: RFC-112 - Need dynamic constant.
                        && r.getDirectives()
                            .get(ResourceConstants.REQUIREMENT_RESOLUTION_DIRECTIVE).equals("dynamic")))
                {
                    r = new HostedRequirement(wire.getRequirer(), r);
                }
                // Wrap the capability as a hosted capability if it comes
                // from a fragment, since we will need to know the host.
                Capability c = wire.getCapability();
                if (!c.getResource().equals(wire.getProvider()))
                {
                    c = new HostedCapability(wire.getProvider(), c);
                }
                reqs.add(r);
                caps.add(c);
            }

            // Since the revision is resolved, it could be dynamically importing,
            // so check to see if there are candidates for any of its dynamic
            // imports.
            for (Requirement req
                : Util.getDynamicRequirements(wiring.getResourceRequirements(null)))
            {
                // Get the candidates for the current requirement.
                SortedSet<Capability> candCaps = allCandidates.getCandidates(req);
                // Optional requirements may not have any candidates.
                if (candCaps == null)
                {
                    continue;
                }

                Capability cap = candCaps.iterator().next();
                reqs.add(req);
                caps.add(cap);
                isDynamicImporting = true;
                // Can only dynamically import one at a time, so break
                // out of the loop after the first.
                break;
            }
        }
        else
        {
            for (Requirement req : resource.getRequirements(null))
            {
                String resolution = req.getDirectives()
                    .get(ResourceConstants.REQUIREMENT_RESOLUTION_DIRECTIVE);
// TODO: RFC-112 - Need dynamic constant.
                if ((resolution == null) || !resolution.equals("dynamic"))
                {
                    // Get the candidates for the current requirement.
                    SortedSet<Capability> candCaps = allCandidates.getCandidates(req);
                    // Optional requirements may not have any candidates.
                    if (candCaps == null)
                    {
                        continue;
                    }

                    Capability cap = candCaps.iterator().next();
                    reqs.add(req);
                    caps.add(cap);
                }
            }
        }

        // First, add all exported packages to the target revision's package space.
        calculateExportedPackages(env, resource, allCandidates, revisionPkgMap);
        Packages revisionPkgs = revisionPkgMap.get(resource);

        // Second, add all imported packages to the target revision's package space.
        for (int i = 0; i < reqs.size(); i++)
        {
            Requirement req = reqs.get(i);
            Capability cap = caps.get(i);
            calculateExportedPackages(env, cap.getResource(), allCandidates, revisionPkgMap);
            mergeCandidatePackages(
                env, resource, req, cap, revisionPkgMap, allCandidates,
                new HashMap<Resource, List<Capability>>());
        }

        // Third, have all candidates to calculate their package spaces.
        for (int i = 0; i < caps.size(); i++)
        {
            calculatePackageSpaces(
                env, caps.get(i).getResource(), allCandidates, revisionPkgMap,
                usesCycleMap, cycle);
        }

        // Fourth, if the target revision is unresolved or is dynamically importing,
        // then add all the uses constraints implied by its imported and required
        // packages to its package space.
        // NOTE: We do not need to do this for resolved revisions because their
        // package space is consistent by definition and these uses constraints
        // are only needed to verify the consistency of a resolving revision. The
        // only exception is if a resolved revision is dynamically importing, then
        // we need to calculate its uses constraints again to make sure the new
        // import is consistent with the existing package space.
        if ((wiring == null) || isDynamicImporting)
        {
            // Merge uses constraints from required capabilities.
            for (int i = 0; i < reqs.size(); i++)
            {
                Requirement req = reqs.get(i);
                Capability cap = caps.get(i);
                // Ignore bundle/package requirements, since they are
                // considered below.
                if (!req.getNamespace().equals(ResourceConstants.WIRING_BUNDLE_NAMESPACE)
                    && !req.getNamespace().equals(ResourceConstants.WIRING_PACKAGE_NAMESPACE))
                {
                    List<Requirement> blameReqs = new ArrayList();
                    blameReqs.add(req);

                    mergeUses(
View Full Code Here

TOP

Related Classes of org.osgi.framework.resource.Requirement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.