Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chores(analyzer): Print warning if duplicate packages #9260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.ossreviewtoolkit.analyzer

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

import org.ossreviewtoolkit.model.AnalyzerResult
import org.ossreviewtoolkit.model.DependencyGraph
import org.ossreviewtoolkit.model.DependencyGraphNavigator
Expand All @@ -41,10 +43,24 @@

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()) {
fviernau marked this conversation as resolved.
Show resolved Hide resolved
logger.warn {
"AnalyzerResult contains packages and projects with the same ids: ${duplicates.values}"
}
Comment on lines +47 to +49

Check warning

Code scanning / detekt

Reports code blocks that are not followed by an empty line Warning

Missing empty line after block.
// Log duplicates as issues
for ((key, items) in duplicates) {
val issue = createAndLogIssue(
source = "analyzer",
message = "AnalyzerResult contains packages and projects with the same ids: ${items}"

Check notice on line 54 in analyzer/src/main/kotlin/AnalyzerResultBuilder.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Redundant curly braces in string template

Redundant curly braces in string template

Check warning

Code scanning / detekt

Detects simplifications in template strings Warning

Redundant curly braces

Check notice

Code scanning / QDJVMC

Redundant curly braces in string template Note

Redundant curly braces in string template
)

val existingIssues = issues.getOrDefault(key, emptyList())
issues[key] = existingIssues + issue
}
Comment on lines +51 to +59

Check warning

Code scanning / detekt

Reports code blocks that are not followed by an empty line Warning

Missing empty line after block.
// Remove duplicates from packages, to avoid side effects by having duplicate entries in the dependency tree
packages.removeAll { it.id in duplicates.keys.toSet() }

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"

return AnalyzerResult(projects, packages, issues, dependencyGraphs)
.convertToDependencyGraph(excludes)
Expand Down
Loading