Skip to content

Commit

Permalink
refactor(stack): Use buildMap and inline allDependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jul 1, 2024
1 parent 325c842 commit 1e765df
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ class Stack(
val projectPackage = parseCabalFile(cabalFile.readText())
val projectId = projectPackage.id.copy(type = managerName)

val allDependencies = mutableSetOf<Dependency>()
val externalDependencies = listDependencies(workingDir, EXTERNAL_SCOPE_NAME).also { allDependencies += it }
val testDependencies = listDependencies(workingDir, TEST_SCOPE_NAME).also { allDependencies += it }
val benchDependencies = listDependencies(workingDir, BENCH_SCOPE_NAME).also { allDependencies += it }
val externalDependencies = listDependencies(workingDir, EXTERNAL_SCOPE_NAME)
val testDependencies = listDependencies(workingDir, TEST_SCOPE_NAME)
val benchDependencies = listDependencies(workingDir, BENCH_SCOPE_NAME)

val dependencyPackageMap = mutableMapOf<Dependency, Package>()
val dependencyPackageMap = buildMap {
(externalDependencies + testDependencies + benchDependencies).forEach { dependency ->
val pkg = dependency.toPackage()

allDependencies.forEach { dependency ->
val pkg = dependency.toPackage()

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

fun List<String>.toPackageReferences(): Set<PackageReference> =
Expand Down

0 comments on commit 1e765df

Please sign in to comment.