Class PackageReference
-
- All Implemented Interfaces:
-
kotlin.Comparable,org.ossreviewtoolkit.model.DependencyNode
public final class PackageReference implements Comparable<PackageReference>, DependencyNode
A human-readable reference to a software Package. Each package reference itself refers to other package references that are dependencies of the package.
-
-
Field Summary
Fields Modifier and Type Field Description private final Identifieridprivate final PackageLinkagelinkageprivate final Set<PackageReference>dependenciesprivate final List<Issue>issues
-
Constructor Summary
Constructors Constructor Description PackageReference(Identifier id, PackageLinkage linkage, Set<PackageReference> dependencies, List<Issue> issues)
-
Method Summary
Modifier and Type Method Description IdentifiergetId()The identifier of the package. PackageLinkagegetLinkage()The type of linkage used for the referred package from its dependent package. final Set<PackageReference>getDependencies()The set of references to packages this package depends on. List<Issue>getIssues()A list of Issues that occurred handling this PackageReference. final Set<Identifier>collectDependencies(Integer maxDepth, Function1<PackageReference, Boolean> filterPredicate)Return the set of Identifiers the package referred by this PackageReference transitively depends on, up to and including a depth of maxDepth where counting starts at 0 (for the PackageReference itself) and 1 are direct dependencies etc. IntegercompareTo(PackageReference other)A comparison function to sort package references by their identifier. final BooleandependsOn(Identifier id)Return whether the package identified by id is a (transitive) dependency of this reference. final List<PackageReference>findReferences(Identifier id)Return all references to id as a dependency. final PackageReferencetraverse(Function1<PackageReference, PackageReference> transform)Apply the provided transform to each node in the dependency tree represented by this PackageReference and return the modified PackageReference. <T extends Any> TvisitDependencies(Function1<Sequence<DependencyNode>, T> block)Visit the direct dependencies of this DependencyNode by calling the specified block with a sequence of all child nodes. -
-
Constructor Detail
-
PackageReference
PackageReference(Identifier id, PackageLinkage linkage, Set<PackageReference> dependencies, List<Issue> issues)
-
-
Method Detail
-
getId
Identifier getId()
The identifier of the package.
-
getLinkage
PackageLinkage getLinkage()
The type of linkage used for the referred package from its dependent package. As most of our supported package managers / languages only support dynamic linking or at least default to it, also use that as the default value here to not blow up our result files.
-
getDependencies
final Set<PackageReference> getDependencies()
The set of references to packages this package depends on. Note that this list depends on the scope in which this package is referenced.
-
getIssues
List<Issue> getIssues()
A list of Issues that occurred handling this PackageReference.
-
collectDependencies
final Set<Identifier> collectDependencies(Integer maxDepth, Function1<PackageReference, Boolean> filterPredicate)
Return the set of Identifiers the package referred by this PackageReference transitively depends on, up to and including a depth of maxDepth where counting starts at 0 (for the PackageReference itself) and 1 are direct dependencies etc. A value below 0 means to not limit the depth. If the given filterPredicate is false for a specific PackageReference the corresponding Identifier is excluded from the result.
-
compareTo
Integer compareTo(PackageReference other)
A comparison function to sort package references by their identifier. This function ignores all other properties except for id.
-
dependsOn
final Boolean dependsOn(Identifier id)
Return whether the package identified by id is a (transitive) dependency of this reference.
-
findReferences
final List<PackageReference> findReferences(Identifier id)
Return all references to id as a dependency.
-
traverse
final PackageReference traverse(Function1<PackageReference, PackageReference> transform)
Apply the provided transform to each node in the dependency tree represented by this PackageReference and return the modified PackageReference. The tree is traversed depth-first (post-order).
-
visitDependencies
<T extends Any> T visitDependencies(Function1<Sequence<DependencyNode>, T> block)
Visit the direct dependencies of this DependencyNode by calling the specified block with a sequence of all child nodes. The code block can produce a result, which is returned by this function. The function is the basis for traversing the whole dependency graph; each call yields the direct dependencies of a node, by calling the function recursively on these dependencies, the transitive dependency set can be visited.
Notes:
Not all storage formats used for dependency information use structures that can be mapped directly to this interface; therefore, some kind of wrapping may be required. To allow for optimizations, this function operates of a sequence rather than a collection; a collection would require wrapping a whole level of dependencies, while this is not necessarily required with a sequence.
When constructing dependency graphs, package managers are required to prevent cycles. Therefore, code using this function does not have to implement its own check for cycles to prevent infinite loops. With other words: It is safe to recursively call visitDependencies on the nodes in the sequence.
-
-
-
-