Merge pull request #4855 from eed3si9n/wip/credentials

add allCredentials to emulate credential registration
This commit is contained in:
eugene yokota 2019-07-12 15:21:36 -04:00 committed by GitHub
commit 5c3eff52d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View File

@ -2364,6 +2364,7 @@ object Classpaths {
),
ivySbt := ivySbt0.value,
ivyModule := { val is = ivySbt.value; new is.Module(moduleSettings.value) },
allCredentials := LMCoursier.allCredentialsTask.value,
transitiveUpdate := transitiveUpdateTask.value,
updateCacheName := {
val binVersion = scalaBinaryVersion.value

View File

@ -376,6 +376,7 @@ object Keys {
val packagedArtifacts = taskKey[Map[Artifact, File]]("Packages all artifacts for publishing and maps the Artifact definition to the generated file.").withRank(CTask)
val publishMavenStyle = settingKey[Boolean]("Configures whether to generate and publish a pom (true) or Ivy file (false).").withRank(BSetting)
val credentials = taskKey[Seq[Credentials]]("The credentials to use for updating and publishing.").withRank(BMinusTask)
val allCredentials = taskKey[Seq[Credentials]]("Aggregated credentials across current and root subprojects. Do not rewire this task.").withRank(DTask)
val makePom = taskKey[File]("Generates a pom for publishing when publishing Maven-style.").withRank(BPlusTask)
val deliver = taskKey[File]("Generates the Ivy file for publishing to a repository.").withRank(BTask)

View File

@ -204,7 +204,7 @@ object CoursierInputsTasks {
val credentialsTask = Def.task {
val log = streams.value.log
val creds = sbt.Keys.credentials.value
val creds = sbt.Keys.allCredentials.value
.flatMap {
case dc: IvyDirectCredentials => List(dc)
case fc: FileCredentials =>

View File

@ -9,6 +9,7 @@ package sbt
package coursierint
import java.io.File
import java.util.concurrent.ConcurrentHashMap
import lmcoursier.definitions.{
Classifier,
Configuration => CConfiguration,
@ -19,11 +20,15 @@ import lmcoursier._
import lmcoursier.credentials.Credentials
import Keys._
import sbt.librarymanagement._
import sbt.librarymanagement.ivy.{ Credentials => IvyCredentials }
import sbt.util.Logger
import sbt.io.syntax._
import xsbti.AppConfiguration
object LMCoursier {
private[this] val credentialRegistry: ConcurrentHashMap[(String, String), IvyCredentials] =
new ConcurrentHashMap
def defaultCacheLocation: File =
sys.props.get("sbt.coursier.home") match {
case Some(home) => new File(home).getAbsoluteFile / "cache"
@ -188,4 +193,19 @@ object LMCoursier {
def publicationsSetting(packageConfigs: Seq[(Configuration, CConfiguration)]): Def.Setting[_] = {
csrPublications := CoursierArtifactsTasks.coursierPublicationsTask(packageConfigs: _*).value
}
private[sbt] def registerCredentials(creds: IvyCredentials): Unit = {
val d = IvyCredentials.toDirect(creds)
credentialRegistry.put((d.host, d.realm), d)
()
}
// This emulates Ivy's credential registration which basically keeps mutating global registry
def allCredentialsTask: Def.Initialize[Task[Seq[IvyCredentials]]] = Def.task {
import scala.collection.JavaConverters._
(Keys.credentials in ThisBuild).value foreach registerCredentials
(Keys.credentials in LocalRootProject).value foreach registerCredentials
Keys.credentials.value foreach registerCredentials
credentialRegistry.values.asScala.toVector
}
}