From 133467fc60093d13dd8f41d05f64d5342df0cd43 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Sun, 23 Jun 2024 18:56:40 +0200 Subject: [PATCH] ignore missing credential files instead of failing hard --- .../scala/scalafix/sbt/ScalafixPlugin.scala | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index 1242584a..880df397 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -293,15 +293,29 @@ object ScalafixPlugin extends AutoPlugin { scalafixSbtResolversAsCoursierRepositories := { val logger = streams.value.log - val credentialsByHost = Credentials - .allDirect(credentials.value) - .map { dc => + // mimics https://github.com/sbt/librarymanagement/blob/v1.10.0/ivy/src/main/scala/sbt/librarymanagement/ivy/Credentials.scala#L23-L28 + val asDirectCredentials = credentials.value.flatMap { + _ match { + case dc: DirectCredentials => + Some(dc) + case fc: FileCredentials => + Credentials.loadCredentials(fc.path) match { + case Left(err) => + logger.warn(err) + None + case Right(dc) => + Some(dc) + } + } + } + + val credentialsByHost = + asDirectCredentials.map { dc => dc.host -> coursierapi.Credentials.of( dc.userName, dc.passwd ) - } - .toMap + }.toMap resolvers.value.flatMap { resolver => CoursierRepoResolvers.repository(