Skip to content

Commit 7ee8846

Browse files
committed
Pass sbt credentials to scalafmt interface
1 parent 7b1d2ec commit 7ee8846

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import scala.util.Failure
1515
import scala.util.Success
1616
import scala.util.Try
1717

18+
import org.scalafmt.interfaces.RepositoryCredential
1819
import org.scalafmt.interfaces.Scalafmt
1920
import org.scalafmt.sysops.AbsoluteFile
2021
import org.scalafmt.sysops.FileOps
@@ -141,6 +142,7 @@ object ScalafmtPlugin extends AutoPlugin {
141142
taskStreams: TaskStreams,
142143
cacheStoreFactory: CacheStoreFactory,
143144
resolvers: Seq[Resolver],
145+
credentials: Seq[Credentials],
144146
currentProject: ResolvedProject,
145147
filterMode: String,
146148
errorHandling: ErrorHandling
@@ -156,13 +158,24 @@ object ScalafmtPlugin extends AutoPlugin {
156158
val repositories = resolvers.collect { case r: MavenRepository =>
157159
r.root
158160
}
161+
val repoCredentials = credentials.map { x =>
162+
val cred = Credentials.toDirect(x)
163+
new RepositoryCredential(cred.host, cred.userName, cred.passwd)
164+
}
165+
159166
log.debug(
160-
s"Adding repositories ${repositories.mkString("[", ",", "]")}"
167+
repositories.mkString("Adding repositories [", ",", "]")
161168
)
169+
log.debug {
170+
val info = repoCredentials.map(x => s"${x.username}@${x.host}")
171+
info.mkString("Adding credentials [", ",", "]")
172+
}
173+
162174
val scalafmtSession =
163175
globalInstance
164176
.withReporter(reporter)
165177
.withMavenRepositories(repositories: _*)
178+
.withRepositoryCredentials(repoCredentials: _*)
166179
.createSession(config.toAbsolutePath)
167180
if (scalafmtSession == null)
168181
throw messageException(
@@ -465,6 +478,7 @@ object ScalafmtPlugin extends AutoPlugin {
465478
streams.value,
466479
(scalafmt / streams).value.cacheStoreFactory,
467480
fullResolvers.value,
481+
credentials.value,
468482
thisProject.value,
469483
scalafmtFilter.value,
470484
new ErrorHandling(
@@ -511,6 +525,7 @@ object ScalafmtPlugin extends AutoPlugin {
511525
streams.value,
512526
(scalafmt / streams).value.cacheStoreFactory,
513527
fullResolvers.value,
528+
credentials.value,
514529
thisProject.value,
515530
"",
516531
new ErrorHandling(

0 commit comments

Comments
 (0)