Class ResourceUtils
java.lang.Object
aQute.bnd.osgi.resource.ResourceUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.osgi.resource.Resourcestatic final Comparator<? super org.osgi.resource.Resource> static final Comparator<Comparable> static final Comparator<org.osgi.resource.Requirement> static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends org.osgi.resource.Capability>
Tstatic <T extends org.osgi.resource.Requirement>
Tstatic <CAPABILITY extends org.osgi.resource.Capability, COLLECTION extends Collection<CAPABILITY>>
voidcapabilitiesAccumulator(COLLECTION collection, CAPABILITY capability) static <CAPABILITY extends org.osgi.resource.Capability, COLLECTION extends Collection<CAPABILITY>>
COLLECTIONcapabilitiesCombiner(COLLECTION leftCollection, COLLECTION rightCollection) static Stream<org.osgi.resource.Capability> capabilityStream(org.osgi.resource.Resource resource, String namespace) static <T extends org.osgi.resource.Capability>
Stream<T> capabilityStream(org.osgi.resource.Resource resource, String namespace, Class<T> type) static intcompareTo(org.osgi.resource.Capability a, org.osgi.resource.Capability b) Compare two capabilities.static intcompareTo(org.osgi.resource.Requirement a, org.osgi.resource.Requirement b) static intcompareTo(org.osgi.resource.Resource a, org.osgi.resource.Resource b) Compare two resources.static org.osgi.resource.Requirementstatic 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.static Map<org.osgi.resource.Requirement, Collection<org.osgi.resource.Capability>> emptyProviders(Collection<? extends org.osgi.resource.Requirement> requirements) static Predicate<org.osgi.resource.Capability> filterMatcher(org.osgi.resource.Requirement requirement) static Predicate<org.osgi.resource.Capability> filterMatcher(org.osgi.resource.Requirement requirement, Function<String, Predicate<Map<String, Object>>> filter) filterPredicate(String filterString) 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.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) static List<org.osgi.resource.Capability> findProviders(org.osgi.resource.Requirement requirement, Collection<? extends org.osgi.resource.Capability> capabilities) 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, seecreateWildcardRequirement()static ResourceUtils.BundleCapgetBundleCapability(org.osgi.resource.Resource resource) static BundleIdgetBundleId(org.osgi.resource.Resource resource) static List<ResourceUtils.ContentCapability> getContentCapabilities(org.osgi.resource.Resource resource) getContentCapability(org.osgi.resource.Resource resource) static StringgetEffective(Map<String, String> directives) static StringgetIdentity(org.osgi.resource.Capability identityCapability) static StringgetIdentity(org.osgi.resource.Resource resource) getIdentityCapability(org.osgi.resource.Resource resource) static StringgetIdentityVersion(org.osgi.resource.Resource resource) getIndexedByResource(Collection<? extends org.osgi.resource.Capability> providers) getLocations(org.osgi.resource.Resource resource) static ResolutionDirectivegetResolution(org.osgi.resource.Requirement requirement) static Set<org.osgi.resource.Resource> getResources(Collection<? extends org.osgi.resource.Capability> providers) getSubstitutionPackages(org.osgi.resource.Resource r) Calculates a list of packages which are exported and also imported.getType(org.osgi.resource.Resource r) Return the type field in the Identity capability.static URIgetURI(org.osgi.resource.Capability contentCapability) getURI(org.osgi.resource.Resource resource) static VersiongetVersion(org.osgi.resource.Capability cap) static VersiongetVersion(org.osgi.resource.Resource resource) static StringgetVersionAttributeForNamespace(String namespace) static booleanReturn if the current IdentityNamespace type of the given resource r is in the given list of types.static booleanisEffective(org.osgi.resource.Requirement r, org.osgi.resource.Capability c) static booleanisFragment(org.osgi.resource.Resource resource) static booleanisInitialRequirement(org.osgi.resource.Resource resource) static Predicate<org.osgi.resource.Capability> matcher(org.osgi.resource.Requirement requirement) static Predicate<org.osgi.resource.Capability> matcher(org.osgi.resource.Requirement requirement, Function<String, Predicate<Map<String, Object>>> filter) static booleanmatches(org.osgi.resource.Requirement requirement, org.osgi.resource.Capability capability) static booleanmatches(org.osgi.resource.Requirement requirement, org.osgi.resource.Resource resource) static List<org.osgi.resource.Resource> sort(Collection<org.osgi.resource.Resource> resources) static List<org.osgi.resource.Resource> sortByNameVersion(Collection<org.osgi.resource.Resource> resources) Sort the resources by symbolic name and versionstatic StringstripDirective(String name) static <CAPABILITY extends org.osgi.resource.Capability>
Collector<CAPABILITY, List<CAPABILITY>, List<CAPABILITY>> static StringtoProvideCapability(org.osgi.resource.Capability capability) static StringtoRequireCapability(org.osgi.resource.Requirement requirement) static Versionstatic VersionedClausetoVersionClause(org.osgi.resource.Resource resource) Create a VersionedClause by applying a version range mask to the resource! Masks are defined byMacro._range(String[]).static VersionedClausetoVersionClause(org.osgi.resource.Resource resource, String mask) static List<VersionedClause> toVersionedClauses(Collection<org.osgi.resource.Resource> resources)
-
Field Details
-
REQUIREMENT_COMPARATOR
-
IDENTITY_VERSION_COMPARATOR
-
DUMMY_RESOURCE
public static final org.osgi.resource.Resource DUMMY_RESOURCE -
WORKSPACE_NAMESPACE
- See Also:
-
nullsFirst
-
-
Constructor Details
-
ResourceUtils
public ResourceUtils()
-
-
Method Details
-
capabilityStream
-
capabilityStream
-
getContentCapability
public static ResourceUtils.ContentCapability getContentCapability(org.osgi.resource.Resource resource) -
getURI
-
getContentCapabilities
public static List<ResourceUtils.ContentCapability> getContentCapabilities(org.osgi.resource.Resource resource) -
getIdentityCapability
public static ResourceUtils.IdentityCapability getIdentityCapability(org.osgi.resource.Resource resource) -
getBundleId
-
getIdentityVersion
-
getBundleCapability
-
toVersion
-
getVersion
-
getURI
-
getVersionAttributeForNamespace
-
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
-
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
-
filterMatcher
public static Predicate<org.osgi.resource.Capability> filterMatcher(org.osgi.resource.Requirement requirement) -
filterMatcher
-
getEffective
-
getResolution
-
toRequireCapability
-
toProvideCapability
-
getLocations
-
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
-
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
Create a VersionedClause by applying a version range mask to the resource! Masks are defined byMacro._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
-
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, seecreateWildcardRequirement()- 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 resourceb- 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 capabilityb- 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
-
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
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
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 searchnamespace- the namespace to search or nullfilter- 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.
-