Skip to content

Commit

Permalink
chores(analyzer): Do not throw exception if duplicate packages
Browse files Browse the repository at this point in the history
When duplicate packages or projects are found in the dependency tree, print a
warning instead of throwing an exception and inteerrupting the scan.
Duplicate packages may arise when the same package is imported twice, in these
cases the dependency tree will be completed as the package is imported at
least once.

Signed-off-by: Stefano Bennati <[email protected]>
  • Loading branch information
bennati committed Oct 9, 2024
1 parent 546550e commit 49cb302
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* License-Filename: LICENSE
*/

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

package org.ossreviewtoolkit.analyzer

import org.ossreviewtoolkit.model.AnalyzerResult
Expand All @@ -41,9 +43,10 @@ class AnalyzerResultBuilder {

fun build(excludes: Excludes = Excludes.EMPTY): AnalyzerResult {
val duplicates = (projects.map { it.toPackage() } + packages).getDuplicates { it.id }
require(duplicates.isEmpty()) {
"Unable to create the AnalyzerResult as it contains packages and projects with the same ids: " +
duplicates.values
if (duplicates.isNotEmpty()) {
logger.warn {
"AnalyzerResult contains packages and projects with the same ids: ${duplicates.values}"
}
}

return AnalyzerResult(projects, packages, issues, dependencyGraphs)
Expand Down

0 comments on commit 49cb302

Please sign in to comment.