Skip to content

Commit 8fad7d1

Browse files
authored
Merge pull request #2910 from tgodzik/automatically-detect-credentials
improvement: Attach credentials file if present in Bloop properties
2 parents 52b9748 + f775a96 commit 8fad7d1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

backend/src/main/scala/bloop/DependencyResolution.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,26 @@ object DependencyResolution {
141141
logger.debug(
142142
s"Found coursier in path under $path, Bloop will use it to fetch the dependency"
143143
)(DebugFilter.All)
144+
val additionalProperties = List(
145+
Properties
146+
.propOrNone("coursier.credentials")
147+
.map(cred => List("--credential-file", cred))
148+
.getOrElse(Nil)
149+
).flatten
144150
val module = dependency.getModule()
145151
val depString =
146152
s"${module.getOrganization()}:${module.getName()}:${dependency.getVersion}"
147153
val withSourceFlag = if (resolveSources) List("--sources") else Nil
154+
val envWithMirrors = Properties
155+
.propOrNone("coursier.mirrors")
156+
.map(mirror => Map("COURSIER_MIRRORS" -> mirror))
157+
.getOrElse(Map.empty)
148158
runSync(
149-
List(path.toString(), "fetch", depString) ++ withSourceFlag,
150-
AbsolutePath(userHome)
159+
List(path.toString(), "fetch") ++ additionalProperties ++ List(
160+
depString
161+
) ++ withSourceFlag,
162+
AbsolutePath(userHome),
163+
envWithMirrors
151164
) match {
152165
case Some(out) =>
153166
val lines = out.linesIterator.toList
@@ -197,11 +210,13 @@ object DependencyResolution {
197210
*/
198211
private def runSync(
199212
command: List[String],
200-
workingDirectory: AbsolutePath
213+
workingDirectory: AbsolutePath,
214+
additionalEnvironment: Map[String, String] = Map.empty
201215
): Option[String] = {
202216
try {
203217
val pb = new ProcessBuilder(command: _*)
204218
pb.directory(workingDirectory.underlying.toFile)
219+
pb.environment().putAll(additionalEnvironment.asJava)
205220
val process = pb.start()
206221
val is = process.getInputStream
207222
val reader = new BufferedReader(new InputStreamReader(is))

0 commit comments

Comments
 (0)