Skip to content

Commit f296f2a

Browse files
committed
feat(OrtResult): Filter scan issues against path excludes
Scan issues limited to excluded files are irrelevant and can be filtered out. This avoids manualy effort for clarifing and fixing irrelevant issues. Signed-off-by: Frank Viernau <frank_viernau@epam.com>
1 parent 20e23f1 commit f296f2a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

model/src/main/kotlin/OrtResult.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.ossreviewtoolkit.model.config.Excludes
3131
import org.ossreviewtoolkit.model.config.IssueResolution
3232
import org.ossreviewtoolkit.model.config.LicenseFindingCuration
3333
import org.ossreviewtoolkit.model.config.PackageConfiguration
34+
import org.ossreviewtoolkit.model.config.PathExclude
3435
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
3536
import org.ossreviewtoolkit.model.config.Resolutions
3637
import org.ossreviewtoolkit.model.config.RuleViolationResolution
@@ -151,6 +152,16 @@ data class OrtResult(
151152
resolvedConfiguration.packageConfigurations.orEmpty().groupBy { it.id }
152153
}
153154

155+
private val pathExcludesById: Map<Identifier, List<PathExclude>> by lazy {
156+
getProjectsAndPackages().associateWith { id ->
157+
if (isProject(id)) {
158+
repository.config.excludes.paths
159+
} else {
160+
packageConfigurationsById[id].orEmpty().flatMap { it.pathExcludes }
161+
}
162+
}
163+
}
164+
154165
/**
155166
* A map of projects and their excluded state. Calculating this map once brings massive performance improvements
156167
* when querying projects in large analyzer results.
@@ -247,7 +258,7 @@ data class OrtResult(
247258
@JsonIgnore
248259
fun getIssues(): Map<Identifier, Set<Issue>> {
249260
val analyzerIssues = analyzer?.result?.getAllIssues().orEmpty()
250-
val scannerIssues = scanner?.getIssues().orEmpty()
261+
val scannerIssues = scanner?.getIssues(pathExcludesById).orEmpty()
251262
val advisorIssues = advisor?.results?.getIssues().orEmpty()
252263

253264
val analyzerAndScannerIssues = analyzerIssues.zipWithCollections(scannerIssues)

model/src/main/kotlin/ScannerRun.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import kotlin.time.measureTimedValue
2929

3030
import org.apache.logging.log4j.kotlin.logger
3131

32+
import org.ossreviewtoolkit.model.config.PathExclude
3233
import org.ossreviewtoolkit.model.config.ScannerConfiguration
3334
import org.ossreviewtoolkit.model.utils.FileListSortedSetConverter
3435
import org.ossreviewtoolkit.model.utils.ProvenanceResolutionResultSortedSetConverter
@@ -255,9 +256,11 @@ data class ScannerRun(
255256
fun getFileList(id: Identifier): FileList? = fileListById[id]
256257

257258
@JsonIgnore
258-
fun getIssues(): Map<Identifier, Set<Issue>> =
259-
scanResultsById.mapValues { (_, scanResults) ->
260-
scanResults.flatMapTo(mutableSetOf()) { it.summary.issues }
259+
fun getIssues(pathExcludesById: Map<Identifier, List<PathExclude>> = emptyMap()): Map<Identifier, Set<Issue>> =
260+
scanResultsById.mapValues { (id, scanResults) ->
261+
scanResults.flatMapTo(mutableSetOf()) { it.summary.issues }.filterTo(mutableSetOf()) { issue ->
262+
issue.affectedPath == null || pathExcludesById[id].orEmpty().none { it.matches(issue.affectedPath) }
263+
}
261264
}
262265
}
263266

0 commit comments

Comments
 (0)