@@ -36,42 +36,39 @@ final class BuildToolDispatcher[F[_]](config: Config)(implicit
36
36
repoConfigAlg : RepoConfigAlg [F ],
37
37
F : Monad [F ]
38
38
) {
39
- private val allBuildTools = List (mavenAlg, millAlg, sbtAlg)
40
- private val fallbackBuildTool = sbtAlg
39
+ def getDependencies (repo : Repo ): F [List [Scope .Dependencies ]] =
40
+ getBuildRootsAndTools(repo).flatMap(_.flatTraverse { case (buildRoot, buildTools) =>
41
+ for {
42
+ dependencies <- buildTools.flatTraverse(_.getDependencies(buildRoot))
43
+ additionalDependencies <- getAdditionalDependencies(buildRoot)
44
+ } yield Scope .combineByResolvers(additionalDependencies ::: dependencies)
45
+ })
41
46
42
- private def buildRootsForRepo (repo : Repo ): F [List [BuildRoot ]] = for {
43
- repoConfigOpt <- repoConfigAlg.readRepoConfig(repo)
44
- repoConfig <- repoConfigAlg.mergeWithDefault(repoConfigOpt)
45
- buildRoots = repoConfig.buildRootsOrDefault
46
- .map(config => BuildRoot (repo, config.relativePath))
47
- } yield buildRoots
47
+ def runMigration (repo : Repo , migration : ScalafixMigration ): F [Unit ] =
48
+ getBuildRootsAndTools(repo).flatMap(_.traverse_ { case (buildRoot, buildTools) =>
49
+ buildTools.traverse_(_.runMigration(buildRoot, migration))
50
+ })
48
51
49
- def getDependencies (repo : Repo ): F [List [Scope . Dependencies ]] =
52
+ private def getBuildRoots (repo : Repo ): F [List [BuildRoot ]] =
50
53
for {
51
- buildRoots <- buildRootsForRepo(repo)
52
- result <- buildRoots.flatTraverse(buildRoot =>
53
- for {
54
- dependencies <- foundBuildTools(buildRoot).flatMap(
55
- _.flatTraverse(_.getDependencies(buildRoot))
56
- )
57
- additionalDependencies <- getAdditionalDependencies(buildRoot)
58
- } yield Scope .combineByResolvers(additionalDependencies ::: dependencies)
59
- )
60
- } yield result
54
+ repoConfigOpt <- repoConfigAlg.readRepoConfig(repo)
55
+ repoConfig <- repoConfigAlg.mergeWithDefault(repoConfigOpt)
56
+ buildRoots = repoConfig.buildRootsOrDefault
57
+ .map(config => BuildRoot (repo, config.relativePath))
58
+ } yield buildRoots
61
59
62
- def runMigration (repo : Repo , migration : ScalafixMigration ): F [Unit ] =
63
- buildRootsForRepo(repo).flatMap(buildRoots =>
64
- buildRoots.traverse_(buildRoot =>
65
- foundBuildTools(buildRoot).flatMap(_.traverse_(_.runMigration(buildRoot, migration)))
66
- )
67
- )
60
+ private val allBuildTools = List (mavenAlg, millAlg, sbtAlg)
61
+ private val fallbackBuildTool = List (sbtAlg)
68
62
69
- private def foundBuildTools (buildRoot : BuildRoot ): F [List [BuildToolAlg [F ]]] =
63
+ private def findBuildTools (buildRoot : BuildRoot ): F [( BuildRoot , List [BuildToolAlg [F ]]) ] =
70
64
allBuildTools.filterA(_.containsBuild(buildRoot)).map {
71
- case Nil => List ( fallbackBuildTool)
72
- case list => list
65
+ case Nil => buildRoot -> fallbackBuildTool
66
+ case list => buildRoot -> list
73
67
}
74
68
69
+ private def getBuildRootsAndTools (repo : Repo ): F [List [(BuildRoot , List [BuildToolAlg [F ]])]] =
70
+ getBuildRoots(repo).flatMap(_.traverse(findBuildTools))
71
+
75
72
private def getAdditionalDependencies (buildRoot : BuildRoot ): F [List [Scope .Dependencies ]] =
76
73
scalafmtAlg
77
74
.getScalafmtDependency(buildRoot)
0 commit comments