Skip to content

Commit

Permalink
feat(OrtResult): Allow getDependencies() to omit excluded IDs
Browse files Browse the repository at this point in the history
This is needed in a following change.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Sep 26, 2023
1 parent 03d09e4 commit 4f78499
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions model/src/main/kotlin/OrtResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@ data class OrtResult(
/**
* Return the dependencies of the given [id] (which can refer to a [Project] or a [Package]), up to and including a
* depth of [maxLevel] where counting starts at 0 (for the [Project] or [Package] itself) and 1 are direct
* dependencies etc. A value below 0 means to not limit the depth.
* dependencies etc. A value below 0 means to not limit the depth. If [omitExcluded] is set to true, idenfitifers of
* excluded projects / packages are omitted from the result.
*/
fun getDependencies(id: Identifier, maxLevel: Int = -1): Set<Identifier> {
fun getDependencies(id: Identifier, maxLevel: Int = -1, omitExcluded: Boolean = false): Set<Identifier> {
val dependencies = mutableSetOf<Identifier>()
val matcher = DependencyNavigator.MATCH_ALL.takeUnless { omitExcluded } ?: { !isExcluded(it.id) }

getProjects().forEach { project ->
if (project.id == id) {
dependencies += dependencyNavigator.projectDependencies(project, maxLevel)
dependencies += dependencyNavigator.projectDependencies(project, maxLevel, matcher)
}

dependencies += dependencyNavigator.packageDependencies(project, id, maxLevel)
dependencies += dependencyNavigator.packageDependencies(project, id, maxLevel, matcher)
}

return dependencies
Expand Down

0 comments on commit 4f78499

Please sign in to comment.