diff --git a/model/src/main/kotlin/OrtResult.kt b/model/src/main/kotlin/OrtResult.kt index bdb482e5778f7..0e20010746b8d 100644 --- a/model/src/main/kotlin/OrtResult.kt +++ b/model/src/main/kotlin/OrtResult.kt @@ -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, identifiers of + * excluded projects / packages are omitted from the result. */ - fun getDependencies(id: Identifier, maxLevel: Int = -1): Set { + fun getDependencies(id: Identifier, maxLevel: Int = -1, omitExcluded: Boolean = false): Set { val dependencies = mutableSetOf() + 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 diff --git a/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.json b/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.json index ba9f4876ed8ec..9ddc9622e09ef 100644 --- a/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.json +++ b/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.json @@ -240,10 +240,6 @@ "spdxElementId" : "SPDXRef-Package-Maven-seventh-package-group-seventh-package-0.0.1", "relationshipType" : "GENERATED_FROM", "relatedSpdxElement" : "SPDXRef-Package-Maven-seventh-package-group-seventh-package-0.0.1-source-artifact" - }, { - "spdxElementId" : "SPDXRef-Project-Maven-first-project-group-first-project-name-0.0.1", - "relationshipType" : "DEPENDS_ON", - "relatedSpdxElement" : "SPDXRef-Package-Maven-fifth-package-group-fifth-package-0.0.1" }, { "spdxElementId" : "SPDXRef-Project-Maven-first-project-group-first-project-name-0.0.1", "relationshipType" : "DEPENDS_ON", diff --git a/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.yml b/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.yml index e2ad5bdfedfc6..9eefa75bb61a2 100644 --- a/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.yml +++ b/plugins/reporters/spdx/src/funTest/assets/spdx-document-reporter-expected-output.spdx.yml @@ -241,9 +241,6 @@ relationships: - spdxElementId: "SPDXRef-Package-Maven-seventh-package-group-seventh-package-0.0.1" relationshipType: "GENERATED_FROM" relatedSpdxElement: "SPDXRef-Package-Maven-seventh-package-group-seventh-package-0.0.1-source-artifact" -- spdxElementId: "SPDXRef-Project-Maven-first-project-group-first-project-name-0.0.1" - relationshipType: "DEPENDS_ON" - relatedSpdxElement: "SPDXRef-Package-Maven-fifth-package-group-fifth-package-0.0.1" - spdxElementId: "SPDXRef-Project-Maven-first-project-group-first-project-name-0.0.1" relationshipType: "DEPENDS_ON" relatedSpdxElement: "SPDXRef-Package-Maven-first-package-group-first-package-0.0.1" diff --git a/plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt b/plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt index b01d0de2a9e86..219389650419f 100644 --- a/plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt +++ b/plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt @@ -70,7 +70,11 @@ internal object SpdxDocumentModelMapper : Logging { ortResult ) - ortResult.getDependencies(project.id, 1).mapTo(relationships) { dependency -> + ortResult.getDependencies( + id = project.id, + maxLevel = 1, + omitExcluded = true + ).mapTo(relationships) { dependency -> SpdxRelationship( spdxElementId = spdxProjectPackage.spdxId, relationshipType = SpdxRelationship.Type.DEPENDS_ON, @@ -91,7 +95,11 @@ internal object SpdxDocumentModelMapper : Logging { ortResult ) - ortResult.getDependencies(pkg.id, 1).mapTo(relationships) { dependency -> + ortResult.getDependencies( + id = pkg.id, + maxLevel = 1, + omitExcluded = true + ).mapTo(relationships) { dependency -> SpdxRelationship( spdxElementId = binaryPackage.spdxId, relationshipType = SpdxRelationship.Type.DEPENDS_ON,