@@ -22,6 +22,9 @@ import cats.implicits.*
22
22
import coursier .cache .{CachePolicy , FileCache }
23
23
import coursier .core .{Authentication , Project }
24
24
import coursier .{Fetch , Module , ModuleName , Organization }
25
+ import coursier .{Fetch , Info , Module , ModuleName , Organization }
26
+ import org .http4s .Uri
27
+ import org .scalasteward .core .application .Config
25
28
import org .scalasteward .core .data .Resolver .Credentials
26
29
import org .scalasteward .core .data .{Dependency , Resolver , Version }
27
30
import org .scalasteward .core .util .uri
@@ -37,16 +40,29 @@ trait CoursierAlg[F[_]] {
37
40
}
38
41
39
42
object CoursierAlg {
40
- def create [F [_]](implicit
43
+ def create [F [_]](config : Config )( implicit
41
44
logger : Logger [F ],
42
45
parallel : Parallel [F ],
43
- F : Async [F ]
46
+ F : Async [F ],
47
+ fetchAlg : CoursierDependenciesFetchAlg [F ]
44
48
): CoursierAlg [F ] = {
45
- val fetch : Fetch [F ] =
46
- Fetch [F ](FileCache [F ]())
49
+ val fetch : F [Fetch [F ]] = fetchAlg
50
+ .classLoader(config.coursierDependencies)
51
+ .map { loader =>
52
+ Fetch [F ](
53
+ FileCache [F ]().withClassLoaders(loader :: Nil )
54
+ )
55
+ }
47
56
48
- val cacheNoTtl : FileCache [F ] =
49
- FileCache [F ]().withTtl(None ).withCachePolicies(List (CachePolicy .Update ))
57
+ val cacheNoTtl : F [FileCache [F ]] =
58
+ fetchAlg
59
+ .classLoader(config.coursierDependencies)
60
+ .map { loader =>
61
+ FileCache [F ]()
62
+ .withTtl(None )
63
+ .withCachePolicies(List (CachePolicy .Update ))
64
+ .withClassLoaders(loader :: Nil )
65
+ }
50
66
51
67
new CoursierAlg [F ] {
52
68
override def getMetadata (
@@ -64,38 +80,40 @@ object CoursierAlg {
64
80
repositories : List [coursier.Repository ],
65
81
acc : DependencyMetadata
66
82
): F [DependencyMetadata ] = {
67
- val fetchArtifacts = fetch
68
- .withArtifactTypes(Set (coursier.Type .pom, coursier.Type .ivy))
69
- .withDependencies(List (dependency))
70
- .withRepositories(repositories)
71
-
72
- fetchArtifacts.ioResult.attempt. flatMap {
73
- case Left (throwable) =>
74
- logger.debug (throwable)( s " Failed to fetch artifacts of $dependency " ).as(acc)
75
- case Right (result) =>
76
- val maybeProject = result.resolution.projectCache
77
- .get(dependency.moduleVersion)
78
- .map { case (_, project) => project }
79
-
80
- maybeProject.fold(F .pure(acc)) { project =>
81
- val metadata = acc.enrichWith(metadataFrom(project))
82
- val recurse = Option .when(metadata.repoUrl.isEmpty)(())
83
+ val fetchArtifacts = fetch.map(
84
+ _ .withArtifactTypes(Set (coursier.Type .pom, coursier.Type .ivy))
85
+ .withDependencies(List (dependency))
86
+ .withRepositories(repositories)
87
+ )
88
+ fetchArtifacts.flatMap {
89
+ _.ioResult.attempt.flatMap {
90
+ case Left (throwable) =>
91
+ logger.debug(throwable)( s " Failed to fetch artifacts of $dependency " ).as(acc)
92
+ case Right (result) =>
93
+ val maybeProject = result.resolution.projectCache
94
+ .get(dependency.moduleVersion)
95
+ .map { case (_, project) => project }
96
+ maybeProject.fold(F .pure(acc)) { project =>
97
+ val metadata = acc.enrichWith(metadataFrom(project))
98
+ val recurse = Option .when(metadata.repoUrl.isEmpty)(())
83
99
(recurse >> parentOf(project)).fold(F .pure(metadata)) { parent =>
84
- getMetadataImpl(parent, repositories, metadata)
100
+ getMetadataImpl(parent, repositories, metadata)
101
+ }
85
102
}
86
- }
103
+ }
87
104
}
88
105
}
89
106
90
107
override def getVersions (dependency : Dependency , resolver : Resolver ): F [List [Version ]] =
91
108
convertResolver(resolver).flatMap { repository =>
92
109
val module = toCoursierModule(dependency)
93
- repository.versions(module, cacheNoTtl.fetch).run.flatMap {
94
- case Left (message) =>
95
- logger.debug(message) >> F .raiseError[List [Version ]](new Throwable (message))
96
- case Right ((versions, _)) =>
97
- F .pure(versions.available.map(Version .apply).sorted)
98
- }
110
+ cacheNoTtl.flatMap { cacheNoTtl =>
111
+ repository.versions(module, cacheNoTtl.fetch).run.flatMap {
112
+ case Left (message) =>
113
+ logger.debug(message) >> F .raiseError[List [Version ]](new Throwable (message))
114
+ case Right ((versions, _)) => F .pure(versions.available.map(Version .apply).sorted)
115
+ }
116
+ }
99
117
}
100
118
101
119
private def convertResolver (resolver : Resolver ): F [coursier.Repository ] =
0 commit comments