Skip to content

Commit

Permalink
Pass sbt credentials to scalafmt interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Aug 29, 2023
1 parent 7b1d2ec commit 7ee8846
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scala.util.Failure
import scala.util.Success
import scala.util.Try

import org.scalafmt.interfaces.RepositoryCredential
import org.scalafmt.interfaces.Scalafmt
import org.scalafmt.sysops.AbsoluteFile
import org.scalafmt.sysops.FileOps
Expand Down Expand Up @@ -141,6 +142,7 @@ object ScalafmtPlugin extends AutoPlugin {
taskStreams: TaskStreams,
cacheStoreFactory: CacheStoreFactory,
resolvers: Seq[Resolver],
credentials: Seq[Credentials],
currentProject: ResolvedProject,
filterMode: String,
errorHandling: ErrorHandling
Expand All @@ -156,13 +158,24 @@ object ScalafmtPlugin extends AutoPlugin {
val repositories = resolvers.collect { case r: MavenRepository =>
r.root
}
val repoCredentials = credentials.map { x =>
val cred = Credentials.toDirect(x)
new RepositoryCredential(cred.host, cred.userName, cred.passwd)
}

log.debug(
s"Adding repositories ${repositories.mkString("[", ",", "]")}"
repositories.mkString("Adding repositories [", ",", "]")
)
log.debug {
val info = repoCredentials.map(x => s"${x.username}@${x.host}")
info.mkString("Adding credentials [", ",", "]")
}

val scalafmtSession =
globalInstance
.withReporter(reporter)
.withMavenRepositories(repositories: _*)
.withRepositoryCredentials(repoCredentials: _*)
.createSession(config.toAbsolutePath)
if (scalafmtSession == null)
throw messageException(
Expand Down Expand Up @@ -465,6 +478,7 @@ object ScalafmtPlugin extends AutoPlugin {
streams.value,
(scalafmt / streams).value.cacheStoreFactory,
fullResolvers.value,
credentials.value,
thisProject.value,
scalafmtFilter.value,
new ErrorHandling(
Expand Down Expand Up @@ -511,6 +525,7 @@ object ScalafmtPlugin extends AutoPlugin {
streams.value,
(scalafmt / streams).value.cacheStoreFactory,
fullResolvers.value,
credentials.value,
thisProject.value,
"",
new ErrorHandling(
Expand Down

0 comments on commit 7ee8846

Please sign in to comment.