Skip to content

Commit

Permalink
Analyzer: Remove projects that are also dependencies
Browse files Browse the repository at this point in the history
Local directories that are dependencies can appear in the
analyzer results both as packages, e.g. Pub, and projects.
After building the results, projects are removed if they match
with packages on VCS information and package manager type.

This is caused by issue oss-review-toolkit#5365. This is only a workaround which
should be replaced by a comprehensive solution for oss-review-toolkit#5365.
  • Loading branch information
bennati committed Jun 17, 2022
1 parent 4d167c2 commit 575f890
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
}
}

analyzerResultBuilder.deduplicateProjects()
return state.buildResult()
}
}
Expand Down
26 changes: 26 additions & 0 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,30 @@ class AnalyzerResultBuilder(private val curationProvider: PackageCurationProvide
dependencyGraphs[packageManagerName] = graph
return this
}

fun deduplicateProjects() {
val packages = this.packages.filter { p ->
p.pkg.vcsProcessed.path != ""
}
val duplicatedProjects = this.projects.filter { prj ->
prj.vcsProcessed.path != ""
}.filter { prj ->
val matchingPackages = packages.filter { p ->
prj.id.type == p.pkg.id.type &&
prj.vcsProcessed == p.pkg.vcsProcessed
}
if (matchingPackages.size > 0) {
matchingPackages.map { p ->
log.warn {
"Project ${prj.id.type}:${prj.id.namespace}:${prj.id.name} " +
"resembles package ${p.pkg.id.type}:${p.pkg.id.namespace}:${p.pkg.id.name}"
}
}
}
matchingPackages.size != 0
}
duplicatedProjects.map { prj ->
this.projects.remove(prj)
}
}
}

0 comments on commit 575f890

Please sign in to comment.