Skip to content

Commit

Permalink
refactor(stack): Make toPackage() return a non-nullable package
Browse files Browse the repository at this point in the history
This prepares for using associateWith in an upcoming change.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 3, 2024
1 parent 01f347e commit 4a33f34
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ class Stack(
val benchDependencies = listDependencies(workingDir, BENCH_SCOPE_NAME)

val dependencyPackageMap = buildMap {
(externalDependencies + testDependencies + benchDependencies).forEach { dependency ->
(externalDependencies + testDependencies + benchDependencies).filterNot {
// Do not add the project as a package.
it.isProject()
}.forEach { dependency ->
val pkg = dependency.toPackage()

// Do not add the Glasgow Haskell Compiler (GHC) as a package.
if (pkg != null && pkg.id.name != "ghc") this[dependency] = pkg
if (pkg.id.name != "ghc") this[dependency] = pkg
}
}

Expand Down Expand Up @@ -171,7 +174,7 @@ class Stack(
return dependenciesJson.parseDependencies()
}

private fun Dependency.toPackage(): Package? {
private fun Dependency.toPackage(): Package {
val id = Identifier(
type = "Hackage",
namespace = "",
Expand All @@ -193,11 +196,6 @@ class Stack(
} ?: fallback
}

PROJECT_PACKAGE_TYPE -> {
// Do not add the project as a package.
null
}

else -> fallback
}
}
Expand Down Expand Up @@ -340,3 +338,5 @@ class Stack(

private fun List<Dependency>.getProjectDependencies(): List<String> =
single { it.location?.type == PROJECT_PACKAGE_TYPE }.dependencies

private fun Dependency.isProject(): Boolean = location?.type == PROJECT_PACKAGE_TYPE

0 comments on commit 4a33f34

Please sign in to comment.