Skip to content

Commit

Permalink
fix(analyzer): Suffix project types with "Project"
Browse files Browse the repository at this point in the history
To avoid one root cause of duplicate project vs package IDs, add a
"Project" suffix to the `type` of project IDs.

This change does not affect IDs used in package curation or package
configurations as these really only apply to packages, not projects.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 7, 2024
1 parent 2e76348 commit b51312d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 9 additions & 1 deletion analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ class AnalyzerResultBuilder {
* Add the given [project] to this builder. This function can be used for projects that have been obtained
* independently of a [ProjectAnalyzerResult].
*/
fun addProject(project: Project) = apply { projects += project }
fun addProject(project: Project) =
apply {
if (project.id.type.endsWith("Project")) {
projects += project
} else {
val projectId = project.id.copy(type = "${project.id.type}Project")
projects += project.copy(id = projectId)
}
}

/**
* Add the given [packageSet] to this builder. This function can be used for packages that have been obtained
Expand Down
8 changes: 4 additions & 4 deletions analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class AnalyzerResultBuilderTest : WordSpec() {
private val scope2 = Scope("scope-2", setOf(pkgRef2))

private val project1 = Project.EMPTY.copy(
id = Identifier("type-1", "namespace-1", "project-1", "version-1"),
id = Identifier("Type1Project", "namespace-1", "project-1", "version-1"),
scopeDependencies = setOf(scope1),
definitionFilePath = "project1"
)
private val project2 = Project.EMPTY.copy(
id = Identifier("type-2", "namespace-2", "project-2", "version-2"),
id = Identifier("Type2Project", "namespace-2", "project-2", "version-2"),
scopeDependencies = setOf(scope1, scope2)
)
private val project3 = Project.EMPTY.copy(
id = Identifier("type-1", "namespace-3", "project-1.2", "version-1"),
id = Identifier("Type1Project", "namespace-3", "project-1.2", "version-1"),
scopeNames = setOf("scope-2"),
scopeDependencies = null
)
Expand Down Expand Up @@ -297,7 +297,7 @@ class AnalyzerResultBuilderTest : WordSpec() {
.addResult(analyzerResult2)
.build()

mergedResults.dependencyGraphs.keys should containExactlyInAnyOrder("type-1", "type-2")
mergedResults.dependencyGraphs.keys should containExactlyInAnyOrder("Type1Project", "Type2Project")
}

"apply scope excludes" {
Expand Down
3 changes: 2 additions & 1 deletion model/src/main/kotlin/DependencyGraphNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class DependencyGraphNavigator(
override fun directDependencies(project: Project, scopeName: String): Sequence<DependencyNode> {
// TODO: Relax this assumption that package manager names start with the name of the type of project
// they manage, for example that "GradleInspector" manages "Gradle" projects.
val managers = graphs.keys.filter { it.startsWith(project.id.type) }
val projectType = project.id.type.removeSuffix("Project")
val managers = graphs.keys.filter { it.startsWith(projectType) }

val manager = requireNotNull(managers.singleOrNull()) {
"All of the $managers managers are able to manage '${project.id.type}' projects. Please enable only one " +
Expand Down

0 comments on commit b51312d

Please sign in to comment.