Class ResourceUtils

java.lang.Object
aQute.bnd.osgi.resource.ResourceUtils

public abstract class ResourceUtils extends Object
  • Field Details

    • REQUIREMENT_COMPARATOR

      public static final Comparator<org.osgi.resource.Requirement> REQUIREMENT_COMPARATOR
    • IDENTITY_VERSION_COMPARATOR

      public static final Comparator<? super org.osgi.resource.Resource> IDENTITY_VERSION_COMPARATOR
    • DUMMY_RESOURCE

      public static final org.osgi.resource.Resource DUMMY_RESOURCE
    • WORKSPACE_NAMESPACE

      public static final String WORKSPACE_NAMESPACE
      See Also:
    • nullsFirst

      public static final Comparator<Comparable> nullsFirst
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • capabilityStream

      public static Stream<org.osgi.resource.Capability> capabilityStream(org.osgi.resource.Resource resource, String namespace)
    • capabilityStream

      public static <T extends org.osgi.resource.Capability> Stream<T> capabilityStream(org.osgi.resource.Resource resource, String namespace, Class<T> type)
    • getContentCapability

      public static ResourceUtils.ContentCapability getContentCapability(org.osgi.resource.Resource resource)
    • getURI

      public static Optional<URI> getURI(org.osgi.resource.Resource resource)
    • getContentCapabilities

      public static List<ResourceUtils.ContentCapability> getContentCapabilities(org.osgi.resource.Resource resource)
    • getIdentityCapability

      public static ResourceUtils.IdentityCapability getIdentityCapability(org.osgi.resource.Resource resource)
    • getBundleId

      public static BundleId getBundleId(org.osgi.resource.Resource resource)
    • getIdentityVersion

      public static String getIdentityVersion(org.osgi.resource.Resource resource)
    • getBundleCapability

      public static ResourceUtils.BundleCap getBundleCapability(org.osgi.resource.Resource resource)
    • toVersion

      public static Version toVersion(Object v)
    • getVersion

      public static Version getVersion(org.osgi.resource.Capability cap)
    • getURI

      public static URI getURI(org.osgi.resource.Capability contentCapability)
    • getVersionAttributeForNamespace

      public static String getVersionAttributeForNamespace(String namespace)
    • as

      public static <T extends org.osgi.resource.Capability> T as(org.osgi.resource.Capability cap, Class<T> type)
    • as

      public static <T extends org.osgi.resource.Requirement> T as(org.osgi.resource.Requirement req, Class<T> type)
    • getResources

      public static Set<org.osgi.resource.Resource> getResources(Collection<? extends org.osgi.resource.Capability> providers)
    • getIndexedByResource

      public static Map<org.osgi.resource.Resource, List<org.osgi.resource.Capability>> getIndexedByResource(Collection<? extends org.osgi.resource.Capability> providers)
    • createWildcardRequirement

      public static org.osgi.resource.Requirement createWildcardRequirement()
    • isEffective

      public static boolean isEffective(org.osgi.resource.Requirement r, org.osgi.resource.Capability c)
    • filterPredicate

      public static Predicate<Map<String,Object>> filterPredicate(String filterString)
    • matches

      public static boolean matches(org.osgi.resource.Requirement requirement, org.osgi.resource.Resource resource)
    • matches

      public static boolean matches(org.osgi.resource.Requirement requirement, org.osgi.resource.Capability capability)
    • matcher

      public static Predicate<org.osgi.resource.Capability> matcher(org.osgi.resource.Requirement requirement)
    • matcher

      public static Predicate<org.osgi.resource.Capability> matcher(org.osgi.resource.Requirement requirement, Function<String, Predicate<Map<String,Object>>> filter)
    • filterMatcher

      public static Predicate<org.osgi.resource.Capability> filterMatcher(org.osgi.resource.Requirement requirement)
    • filterMatcher

      public static Predicate<org.osgi.resource.Capability> filterMatcher(org.osgi.resource.Requirement requirement, Function<String, Predicate<Map<String,Object>>> filter)
    • getEffective

      public static String getEffective(Map<String,String> directives)
    • getResolution

      public static ResolutionDirective getResolution(org.osgi.resource.Requirement requirement)
    • toRequireCapability

      public static String toRequireCapability(org.osgi.resource.Requirement requirement) throws Exception
      Throws:
      Exception
    • toProvideCapability

      public static String toProvideCapability(org.osgi.resource.Capability capability) throws Exception
      Throws:
      Exception
    • getLocations

      public static Map<URI,String> getLocations(org.osgi.resource.Resource resource)
    • findProviders

      public static List<org.osgi.resource.Capability> findProviders(org.osgi.resource.Requirement requirement, Collection<? extends org.osgi.resource.Capability> capabilities)
    • isFragment

      public static boolean isFragment(org.osgi.resource.Resource resource)
    • stripDirective

      public static String stripDirective(String name)
    • getIdentity

      public static String getIdentity(org.osgi.resource.Capability identityCapability) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • getIdentity

      public static String getIdentity(org.osgi.resource.Resource resource) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • getVersion

      public static Version getVersion(org.osgi.resource.Resource resource) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • toVersionClause

      public static VersionedClause toVersionClause(org.osgi.resource.Resource resource)
      Create a VersionedClause by applying a version range mask to the resource! Masks are defined by Macro._range(String[]). If the resource should represent a project in the bnd workspace, then instead the VersionClause will refer to it as a snapshot version: e.g. ;version=snapshot
    • toVersionClause

      public static VersionedClause toVersionClause(org.osgi.resource.Resource resource, String mask)
    • toVersionedClauses

      public static List<VersionedClause> toVersionedClauses(Collection<org.osgi.resource.Resource> resources)
    • getAllResources

      public static Set<org.osgi.resource.Resource> getAllResources(org.osgi.service.repository.Repository repository)
      Return all resources from a repository as returned by the wildcard requirement, see createWildcardRequirement()
      Parameters:
      repository - the repository to use
      Returns:
      a set of resources from the repository.
    • compareTo

      public static int compareTo(org.osgi.resource.Resource a, org.osgi.resource.Resource b)
      Compare two resources. This can be used to act as a comparator. The comparison is first done on name and then version.
      Parameters:
      a - the left resource
      b - the right resource
      Returns:
      0 if equal bame and version, 1 if left has a higher name or same name and higher version, -1 otherwise
    • compareTo

      public static int compareTo(org.osgi.resource.Capability a, org.osgi.resource.Capability b)
      Compare two capabilities. The order is:
      • nulls last
      • namespace lexical
      • namespace specific as described in its Namespace.
      • by "version" if unknown namespace
      • compare resources
      Parameters:
      a - the left capability
      b - the right capability
      Returns:
      -1 if right is higher, 0 if equal, and 1 if left is higher
    • compareTo

      public static int compareTo(org.osgi.resource.Requirement a, org.osgi.resource.Requirement b)
    • sort

      public static List<org.osgi.resource.Resource> sort(Collection<org.osgi.resource.Resource> resources)
    • sortByNameVersion

      public static List<org.osgi.resource.Resource> sortByNameVersion(Collection<org.osgi.resource.Resource> resources)
      Sort the resources by symbolic name and version
      Parameters:
      resources - the set of resources to sort
      Returns:
      a sorted set of resources
    • isInitialRequirement

      public static boolean isInitialRequirement(org.osgi.resource.Resource resource)
    • toCapabilities

      public static <CAPABILITY extends org.osgi.resource.Capability> Collector<CAPABILITY, List<CAPABILITY>, List<CAPABILITY>> toCapabilities()
    • capabilitiesAccumulator

      public static <CAPABILITY extends org.osgi.resource.Capability, COLLECTION extends Collection<CAPABILITY>> void capabilitiesAccumulator(COLLECTION collection, CAPABILITY capability)
    • capabilitiesCombiner

      public static <CAPABILITY extends org.osgi.resource.Capability, COLLECTION extends Collection<CAPABILITY>> COLLECTION capabilitiesCombiner(COLLECTION leftCollection, COLLECTION rightCollection)
    • findProviders

      public static <CAPABILITY extends org.osgi.resource.Capability, COLLECTION extends Collection<CAPABILITY>> Map<org.osgi.resource.Requirement, Collection<org.osgi.resource.Capability>> findProviders(Collection<? extends org.osgi.resource.Requirement> requirements, Function<? super org.osgi.resource.Requirement, COLLECTION> provider)
    • emptyProviders

      public static Map<org.osgi.resource.Requirement, Collection<org.osgi.resource.Capability>> emptyProviders(Collection<? extends org.osgi.resource.Requirement> requirements)
    • getType

      public static Optional<String> getType(org.osgi.resource.Resource r)
      Return the type field in the Identity capability. The IdentityCapability interface has the problem that for the type it returns an enum, which makes it impossible to check for custom identity types.
      Parameters:
      r - the resource
      Returns:
      the type string
    • hasType

      public static boolean hasType(org.osgi.resource.Resource r, String... types)
      Return if the current IdentityNamespace type of the given resource r is in the given list of types.
    • findCapability

      public static List<org.osgi.resource.Capability> findCapability(org.osgi.resource.Resource resource, String namespace, String filter)
      Select the capabilities that match the namespace and the filter applied to the attributes.
      Parameters:
      resource - the resource to search
      namespace - the namespace to search or null
      filter - the filter to apply
      Returns:
      matching capabilities
    • detectDuplicateCapabilitiesWithDifferentHashes

      public static List<org.osgi.resource.Capability> detectDuplicateCapabilitiesWithDifferentHashes(String primaryAttributeName, List<org.osgi.resource.Capability> capabilities)
      Detect capabilities containing packages that have the same name but differ in the contained classes. Since the "bnd.hashes" attribute contains the hashes of each class, we can detect differences. A problem is when there are two bundles exporting the same package BUT with different content (e.g. different files). This can lead to the problem that a consumer expects a certain class in a package of bundleA but it is not there - instead it is in bundleB.
      Parameters:
      primaryAttributeName - E.g. for a package it is "osgi.wiring.package"
      capabilities - list of capabilities to filter
      Returns:
      list of problematic capabilities
    • getSubstitutionPackages

      public static Collection<FilterParser.PackageExpression> getSubstitutionPackages(org.osgi.resource.Resource r)
      Calculates a list of packages which are exported and also imported. This can be handy for debugging and identify unwanted substitution packages / self-imports.
      Parameters:
      r - the resource
      Returns:
      a non-null list of packages.