Skip to content

Commit

Permalink
feat(model): Adhere to Issue.affectedPath when filtering a summary
Browse files Browse the repository at this point in the history
Filter out issues which are outside the VCS path or which do match an
ignore pattern. For example, this filters out ScanCode timeout issues
which are not relevant and thereby reduces manual effort for the
creation of resolutions corresponding to such irrelevant issues.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Dec 7, 2023
1 parent 27bc117 commit 5839604
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 8 additions & 4 deletions model/src/main/kotlin/ScanSummary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,18 @@ data class ScanSummary(
directories = paths
).values.flatten().mapTo(mutableSetOf()) { it.location.path }

fun TextLocation.matchesPaths() =
fun String.matchesPaths() =
paths.any { filterPath ->
this.path.startsWith("$filterPath/") || this.path in applicableLicenseFiles
startsWith("$filterPath/") || this in applicableLicenseFiles
}

fun TextLocation.matchesPaths() = path.matchesPaths()

return copy(
licenseFindings = licenseFindings.filterTo(mutableSetOf()) { it.location.matchesPaths() },
copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { it.location.matchesPaths() },
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { it.sourceLocation.matchesPaths() }
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { it.sourceLocation.matchesPaths() },
issues = issues.filter { it.affectedPath?.matchesPaths() ?: true }
)
}

Expand All @@ -136,7 +139,8 @@ data class ScanSummary(
return copy(
licenseFindings = licenseFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) },
copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) },
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { !matcher.matches(it.sourceLocation.path) }
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { !matcher.matches(it.sourceLocation.path) },
issues = issues.filter { it.affectedPath == null || !matcher.matches(it.affectedPath) }
)
}
}
16 changes: 14 additions & 2 deletions model/src/test/kotlin/ScanSummaryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.ossreviewtoolkit.utils.spdx.SpdxExpression

class ScanSummaryTest : WordSpec({
"filterByPaths()" should {
val summary = createSummaryWithFindingPaths(
val summary = createSummaryWithFindingAndIssuePaths(
"a/file.txt",
"b/c/file.txt",
"d/file.txt"
Expand All @@ -49,10 +49,15 @@ class ScanSummaryTest : WordSpec({
filteredSummary.snippetFindings.map { it.sourceLocation.path } should
containExactly("a/file.txt", "b/c/file.txt")
}

"filter issues" {
filteredSummary.issues.map { it.affectedPath } should
containExactly("a/file.txt", "b/c/file.txt")
}
}
})

private fun createSummaryWithFindingPaths(vararg paths: String): ScanSummary {
private fun createSummaryWithFindingAndIssuePaths(vararg paths: String): ScanSummary {
fun textLocation(path: String) = TextLocation(path = path, startLine = 1, endLine = 2)

return ScanSummary.EMPTY.copy(
Expand All @@ -73,6 +78,13 @@ private fun createSummaryWithFindingPaths(vararg paths: String): ScanSummary {
sourceLocation = textLocation(path),
snippets = emptySet()
)
},
issues = paths.map { path ->
Issue(
source = "Some source",
message = "Some message.",
affectedPath = path
)
}
)
}

0 comments on commit 5839604

Please sign in to comment.