Package org.osgi.resource

Examples of org.osgi.resource.Resource


    return builder.toString();
  }

  ResourceHandle findExactMatch(String identity, String version, Map<String,SortedMap<Version,Resource>> resourceMap) throws Exception {
    Resource resource;
    VersionRange range = new VersionRange(version);
    if (range.isRange())
      return null;

    SortedMap<Version,Resource> versions = resourceMap.get(identity);
View Full Code Here


  static Resource findVersion(Version version, SortedMap<Version,Resource> versions) {
    if (version.getQualifier() != null && version.getQualifier().length() > 0) {
      return versions.get(version);
    }

    Resource latest = null;
    for (Map.Entry<Version,Resource> entry : versions.entrySet()) {
      if (version.getMicro() == entry.getKey().getMicro() && version.getMinor() == entry.getKey().getMinor()
          && version.getMajor() == entry.getKey().getMajor()) {
        latest = entry.getValue();
        continue;
View Full Code Here

  public boolean equals(Object o) {
    if (o == this)
      return true;
    if (!(o instanceof Resource))
      return false;
    Resource that = (Resource)o;
    if (!ResourceHelper.getTypeAttribute(that).equals(ResourceHelper.getTypeAttribute(this)))
      return false;
    if (!ResourceHelper.getSymbolicNameAttribute(that).equals(ResourceHelper.getSymbolicNameAttribute(this)))
      return false;
    if (!ResourceHelper.getVersionAttribute(that).equals(ResourceHelper.getVersionAttribute(this)))
View Full Code Here

    else {
      org.apache.felix.bundlerepository.Resource[] resources = repository.getResources();
      if (resources != null && resources.length != 0) {
        result = new ArrayList<Capability>(resources.length);
        for (final org.apache.felix.bundlerepository.Resource resource : resources) {
          Resource r = new FelixResourceAdapter(resource);
          for (Capability capability : r.getCapabilities(requirement.getNamespace()))
            if (ResourceHelper.matches(requirement, capability))
              result.add(capability);
        }
        ((ArrayList<Capability>)result).trimToSize();
      }
View Full Code Here

     * @param r the resource whose wrapper is desired.
     * @return the wrapper resource or the resource itself if it was not wrapped.
    **/
    public Resource getWrappedHost(Resource r)
    {
        Resource wrapped = m_allWrappedHosts.get(r);
        return (wrapped == null) ? r : wrapped;
    }
View Full Code Here

                // Populate mandatory resources; since these are mandatory
                // resources, failure throws a resolve exception.
                for (Iterator<Resource> it = mandatoryResources.iterator();
                    it.hasNext();)
                {
                    Resource resource = it.next();
                    if (Util.isFragment(resource) || (rc.getWirings().get(resource) == null))
                    {
                        allCandidates.populate(rc, resource, Candidates.MANDATORY);
                    }
                    else
                    {
                        it.remove();
                    }
                }

                // Populate optional resources; since these are optional
                // resources, failure does not throw a resolve exception.
                for (Resource resource : optionalResources)
                {
                    boolean isFragment = Util.isFragment(resource);
                    if (isFragment || (rc.getWirings().get(resource) == null))
                    {
                        allCandidates.populate(rc, resource, Candidates.OPTIONAL);
                    }
                }

                // Populate ondemand fragments; since these are optional
                // resources, failure does not throw a resolve exception.
                for (Resource resource : ondemandFragments)
                {
                    boolean isFragment = Util.isFragment(resource);
                    if (isFragment)
                    {
                        allCandidates.populate(rc, resource, Candidates.ON_DEMAND);
                    }
                }

                // Merge any fragments into hosts.
                allCandidates.prepare(rc);

                // Create a combined list of populated resources; for
                // optional resources. We do not need to consider ondemand
                // fragments, since they will only be pulled in if their
                // host is already present.
                Set<Resource> allResources =
                    new HashSet<Resource>(mandatoryResources);
                for (Resource resource : optionalResources)
                {
                    if (allCandidates.isPopulated(resource))
                    {
                        allResources.add(resource);
                    }
                }

                List<Candidates> usesPermutations = session.getUsesPermutations();
                List<Candidates> importPermutations = session.getImportPermutations();

                // Record the initial candidate permutation.
                usesPermutations.add(allCandidates);

                ResolutionException rethrow = null;

                // If a populated resource is a fragment, then its host
                // must ultimately be verified, so store its host requirement
                // to use for package space calculation.
                Map<Resource, List<Requirement>> hostReqs =
                    new HashMap<Resource, List<Requirement>>();
                for (Resource resource : allResources)
                {
                    if (Util.isFragment(resource))
                    {
                        hostReqs.put(
                            resource,
                            resource.getRequirements(HostNamespace.HOST_NAMESPACE));
                    }
                }

                do
                {
                    rethrow = null;

                    resourcePkgMap.clear();
                    session.getPackageSourcesCache().clear();
                    // Null out each time a new permutation is attempted.
                    // We only use this to store a valid permutation which is a
                    // delta of the current permutation.
                    session.setMultipleCardCandidates(null);

                    allCandidates = (usesPermutations.size() > 0)
                        ? usesPermutations.remove(0)
                        : importPermutations.remove(0);
//allCandidates.dump();
                    // Reuse a resultCache map for checking package consistency
                    // for all resources.
                    Map<Resource, Object> resultCache =
                        new HashMap<Resource, Object>(allResources.size());
                    // Check the package space consistency for all 'root' resources.
                    for (Resource resource : allResources)
                    {
                        Resource target = resource;

                        // If we are resolving a fragment, then get its
                        // host candidate and verify it instead.
                        List<Requirement> hostReq = hostReqs.get(resource);
                        if (hostReq != null)
                        {
                            target = allCandidates.getCandidates(hostReq.get(0))
                                .iterator().next().getResource();
                        }

                        calculatePackageSpaces(
                            session, allCandidates.getWrappedHost(target), allCandidates,
                            resourcePkgMap, new HashMap(), new HashSet());
//System.out.println("+++ PACKAGE SPACES START +++");
//dumpResourcePkgMap(resourcePkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");

                        try
                        {
                            checkPackageSpaceConsistency(
                                session, allCandidates.getWrappedHost(target),
                                allCandidates, resourcePkgMap, resultCache);
                        }
                        catch (ResolutionException ex)
                        {
                            rethrow = ex;
                        }
                    }
                }
                while ((rethrow != null)
                    && ((usesPermutations.size() > 0) || (importPermutations.size() > 0)));

                // If there is a resolve exception, then determine if an
                // optionally resolved resource is to blame (typically a fragment).
                // 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 faultyResource = (faultyReq == null)
                        ? null : getDeclaredResource(faultyReq.getResource());
                    // If the faulty requirement is wrapped, then it may
                    // be from a fragment, so consider the fragment faulty
                    // instead of the host.
                    if (faultyReq instanceof WrappedRequirement)
                    {
                        faultyResource =
                            ((WrappedRequirement) faultyReq)
                            .getDeclaredRequirement().getResource();
                    }
                    // Try to ignore the faulty resource if it is not mandatory.
                    if (optionalResources.remove(faultyResource))
                    {
                        retry = true;
                    }
                    else if (ondemandFragments.remove(faultyResource))
                    {
                        retry = true;
                    }
                    else
                    {
                        throw rethrow;
                    }
                }
                // If there is no exception to rethrow, then this was a clean
                // resolve, so populate the wire map.
                else
                {
                    if (session.getMultipleCardCandidates() != null)
                    {
                        // Candidates for multiple cardinality requirements were
                        // removed in order to provide a consistent class space.
                        // Use the consistent permutation
                        allCandidates = session.getMultipleCardCandidates();
                    }
                    for (Resource resource : allResources)
                    {
                        Resource target = resource;

                        // If we are resolving a fragment, then we
                        // actually want to populate its host's wires.
                        List<Requirement> hostReq = hostReqs.get(resource);
                        if (hostReq != null)
View Full Code Here

                    if (rethrow != null)
                    {
                        Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
                        Requirement faultyReq = ((exReqs == null) || (exReqs.isEmpty()))
                            ? null : exReqs.iterator().next();
                        Resource faultyResource = (faultyReq == null)
                            ? null : getDeclaredResource(faultyReq.getResource());
                        // If the faulty requirement is wrapped, then it may
                        // be from a fragment, so consider the fragment faulty
                        // instead of the host.
                        if (faultyReq instanceof WrappedRequirement)
View Full Code Here

    private static Map<Resource, List<Wire>> populateWireMap(
        ResolveContext rc, Resource resource, Map<Resource, Packages> resourcePkgMap,
        Map<Resource, List<Wire>> wireMap, Candidates allCandidates)
    {
        Resource unwrappedResource = getDeclaredResource(resource);
        if (!rc.getWirings().containsKey(unwrappedResource)
            && !wireMap.containsKey(unwrappedResource))
        {
            wireMap.put(unwrappedResource, (List<Wire>) Collections.EMPTY_LIST);

            List<Wire> packageWires = new ArrayList<Wire>();
            List<Wire> bundleWires = new ArrayList<Wire>();
            List<Wire> capabilityWires = new ArrayList<Wire>();

            for (Requirement req : resource.getRequirements(null))
            {
                List<Capability> cands = allCandidates.getCandidates(req);
                if ((cands != null) && (cands.size() > 0))
                {
                    for (Capability cand : cands)
                    {
                        // Do not create wires for the osgi.wiring.* namespaces
                        // if the provider and requirer are the same resource;
                        // allow such wires for non-OSGi wiring namespaces.
                        if (!cand.getNamespace().startsWith("osgi.wiring.")
                            || !resource.equals(cand.getResource()))
                        {
                            // If we don't already have wires for the candidate,
                            // then recursively populate them.
                            if (!rc.getWirings().containsKey(cand.getResource()))
                            {
                                // Need to special case the candidate for identity
                                // capabilities since it may be from a fragment and
                                // we don't want to populate wires for the fragment,
                                // but rather the host to which it is attached.
                                Resource targetCand = cand.getResource();
                                if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cand.getNamespace())
                                    && Util.isFragment(targetCand))
                                {
                                    targetCand = allCandidates.getCandidates(
                                        targetCand.getRequirements(HostNamespace.HOST_NAMESPACE).get(0))
                                            .iterator().next().getResource();
                                    targetCand = allCandidates.getWrappedHost(targetCand);
                                }

                                populateWireMap(rc, targetCand,
View Full Code Here

     * @return The deployed resource
     * @throws Exception
     */
    private Resource deploySnapshotResource(Resource developmentResource) throws Exception {
        Version releasedBaseVersion = getReleasedBaseVersion(developmentResource);
        Resource snapshotResource = getHighestSnapshotResource(developmentResource, releasedBaseVersion);

        if (snapshotResource == null) {
            System.out.println("Uploading initial snapshot: " + getString(developmentResource) + " -> " + getNextSnapshotVersion(releasedBaseVersion));
            return deploySnapshotResource(developmentResource, getNextSnapshotVersion(releasedBaseVersion));
        }
View Full Code Here

        }
    }

    private Resource getHighestSnapshotResource(Resource resource, Version base) throws Exception {
        List<Resource> resources = findResources(m_deploymentRepo, getIdentity(resource));
        Resource matchedResource = null;
        for (Resource candidateResource : resources) {
            Version candidateVersion = getVersion(candidateResource);
            if (isSnapshotVersion(candidateVersion) && isSameBaseVersion(getVersion(candidateResource), base)
                && (matchedResource == null || getVersion(matchedResource).compareTo(getVersion(candidateResource)) < 0)) {
                matchedResource = candidateResource;
View Full Code Here

TOP

Related Classes of org.osgi.resource.Resource

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.