mirror of https://github.com/sbt/sbt.git
Rework / simplify credentials handling
This commit is contained in:
parent
84d8d7ac38
commit
973cce68ad
|
|
@ -22,25 +22,24 @@ final class CoursierConfiguration private (
|
||||||
val mavenProfiles: Vector[String],
|
val mavenProfiles: Vector[String],
|
||||||
val scalaOrganization: Option[String],
|
val scalaOrganization: Option[String],
|
||||||
val scalaVersion: Option[String],
|
val scalaVersion: Option[String],
|
||||||
val authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)],
|
val credentials: Seq[coursier.credentials.Credentials],
|
||||||
val authenticationByHost: Vector[(String, coursier.core.Authentication)],
|
|
||||||
val logger: Option[coursier.cache.CacheLogger],
|
val logger: Option[coursier.cache.CacheLogger],
|
||||||
val cache: Option[java.io.File]) extends Serializable {
|
val cache: Option[java.io.File]) extends Serializable {
|
||||||
|
|
||||||
private def this() = this(None, sbt.librarymanagement.Resolver.defaults, true, 6, 100, None, None, Vector.empty, Vector.empty, Vector.empty, Vector.empty, true, false, Vector.empty, Vector.empty, None, None, Vector.empty, Vector.empty, None, None)
|
private def this() = this(None, sbt.librarymanagement.Resolver.defaults, true, 6, 100, None, None, Vector.empty, Vector.empty, Vector.empty, Vector.empty, true, false, Vector.empty, Vector.empty, None, None, Vector.empty, None, None)
|
||||||
|
|
||||||
override def equals(o: Any): Boolean = o match {
|
override def equals(o: Any): Boolean = o match {
|
||||||
case x: CoursierConfiguration => (this.log == x.log) && (this.resolvers == x.resolvers) && (this.reorderResolvers == x.reorderResolvers) && (this.parallelDownloads == x.parallelDownloads) && (this.maxIterations == x.maxIterations) && (this.sbtScalaOrganization == x.sbtScalaOrganization) && (this.sbtScalaVersion == x.sbtScalaVersion) && (this.sbtScalaJars == x.sbtScalaJars) && (this.interProjectDependencies == x.interProjectDependencies) && (this.excludeDependencies == x.excludeDependencies) && (this.fallbackDependencies == x.fallbackDependencies) && (this.autoScalaLibrary == x.autoScalaLibrary) && (this.hasClassifiers == x.hasClassifiers) && (this.classifiers == x.classifiers) && (this.mavenProfiles == x.mavenProfiles) && (this.scalaOrganization == x.scalaOrganization) && (this.scalaVersion == x.scalaVersion) && (this.authenticationByRepositoryId == x.authenticationByRepositoryId) && (this.authenticationByHost == x.authenticationByHost) && (this.logger == x.logger) && (this.cache == x.cache)
|
case x: CoursierConfiguration => (this.log == x.log) && (this.resolvers == x.resolvers) && (this.reorderResolvers == x.reorderResolvers) && (this.parallelDownloads == x.parallelDownloads) && (this.maxIterations == x.maxIterations) && (this.sbtScalaOrganization == x.sbtScalaOrganization) && (this.sbtScalaVersion == x.sbtScalaVersion) && (this.sbtScalaJars == x.sbtScalaJars) && (this.interProjectDependencies == x.interProjectDependencies) && (this.excludeDependencies == x.excludeDependencies) && (this.fallbackDependencies == x.fallbackDependencies) && (this.autoScalaLibrary == x.autoScalaLibrary) && (this.hasClassifiers == x.hasClassifiers) && (this.classifiers == x.classifiers) && (this.mavenProfiles == x.mavenProfiles) && (this.scalaOrganization == x.scalaOrganization) && (this.scalaVersion == x.scalaVersion) && (this.credentials == x.credentials) && (this.logger == x.logger) && (this.cache == x.cache)
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
override def hashCode: Int = {
|
override def hashCode: Int = {
|
||||||
37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) + fallbackDependencies.##) + autoScalaLibrary.##) + hasClassifiers.##) + classifiers.##) + mavenProfiles.##) + scalaOrganization.##) + scalaVersion.##) + authenticationByRepositoryId.##) + authenticationByHost.##) + logger.##) + cache.##)
|
37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) + fallbackDependencies.##) + autoScalaLibrary.##) + hasClassifiers.##) + classifiers.##) + mavenProfiles.##) + scalaOrganization.##) + scalaVersion.##) + credentials.##) + logger.##) + cache.##)
|
||||||
}
|
}
|
||||||
override def toString: String = {
|
override def toString: String = {
|
||||||
"CoursierConfiguration(" + log + ", " + resolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ", " + fallbackDependencies + ", " + autoScalaLibrary + ", " + hasClassifiers + ", " + classifiers + ", " + mavenProfiles + ", " + scalaOrganization + ", " + scalaVersion + ", " + authenticationByRepositoryId + ", " + authenticationByHost + ", " + logger + ", " + cache + ")"
|
"CoursierConfiguration(" + log + ", " + resolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ", " + fallbackDependencies + ", " + autoScalaLibrary + ", " + hasClassifiers + ", " + classifiers + ", " + mavenProfiles + ", " + scalaOrganization + ", " + scalaVersion + ", " + credentials + ", " + logger + ", " + cache + ")"
|
||||||
}
|
}
|
||||||
private[this] def copy(log: Option[xsbti.Logger] = log, resolvers: Vector[sbt.librarymanagement.Resolver] = resolvers, reorderResolvers: Boolean = reorderResolvers, parallelDownloads: Int = parallelDownloads, maxIterations: Int = maxIterations, sbtScalaOrganization: Option[String] = sbtScalaOrganization, sbtScalaVersion: Option[String] = sbtScalaVersion, sbtScalaJars: Vector[java.io.File] = sbtScalaJars, interProjectDependencies: Vector[coursier.core.Project] = interProjectDependencies, excludeDependencies: Vector[(String, String)] = excludeDependencies, fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency] = fallbackDependencies, autoScalaLibrary: Boolean = autoScalaLibrary, hasClassifiers: Boolean = hasClassifiers, classifiers: Vector[String] = classifiers, mavenProfiles: Vector[String] = mavenProfiles, scalaOrganization: Option[String] = scalaOrganization, scalaVersion: Option[String] = scalaVersion, authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)] = authenticationByRepositoryId, authenticationByHost: Vector[(String, coursier.core.Authentication)] = authenticationByHost, logger: Option[coursier.cache.CacheLogger] = logger, cache: Option[java.io.File] = cache): CoursierConfiguration = {
|
private[this] def copy(log: Option[xsbti.Logger] = log, resolvers: Vector[sbt.librarymanagement.Resolver] = resolvers, reorderResolvers: Boolean = reorderResolvers, parallelDownloads: Int = parallelDownloads, maxIterations: Int = maxIterations, sbtScalaOrganization: Option[String] = sbtScalaOrganization, sbtScalaVersion: Option[String] = sbtScalaVersion, sbtScalaJars: Vector[java.io.File] = sbtScalaJars, interProjectDependencies: Vector[coursier.core.Project] = interProjectDependencies, excludeDependencies: Vector[(String, String)] = excludeDependencies, fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency] = fallbackDependencies, autoScalaLibrary: Boolean = autoScalaLibrary, hasClassifiers: Boolean = hasClassifiers, classifiers: Vector[String] = classifiers, mavenProfiles: Vector[String] = mavenProfiles, scalaOrganization: Option[String] = scalaOrganization, scalaVersion: Option[String] = scalaVersion, credentials: Seq[coursier.credentials.Credentials] = credentials, logger: Option[coursier.cache.CacheLogger] = logger, cache: Option[java.io.File] = cache): CoursierConfiguration = {
|
||||||
new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, authenticationByRepositoryId, authenticationByHost, logger, cache)
|
new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, credentials, logger, cache)
|
||||||
}
|
}
|
||||||
def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = {
|
def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = {
|
||||||
copy(log = log)
|
copy(log = log)
|
||||||
|
|
@ -108,11 +107,8 @@ final class CoursierConfiguration private (
|
||||||
def withScalaVersion(scalaVersion: String): CoursierConfiguration = {
|
def withScalaVersion(scalaVersion: String): CoursierConfiguration = {
|
||||||
copy(scalaVersion = Option(scalaVersion))
|
copy(scalaVersion = Option(scalaVersion))
|
||||||
}
|
}
|
||||||
def withAuthenticationByRepositoryId(authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = {
|
def withCredentials(credentials: Seq[coursier.credentials.Credentials]): CoursierConfiguration = {
|
||||||
copy(authenticationByRepositoryId = authenticationByRepositoryId)
|
copy(credentials = credentials)
|
||||||
}
|
|
||||||
def withAuthenticationByHost(authenticationByHost: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = {
|
|
||||||
copy(authenticationByHost = authenticationByHost)
|
|
||||||
}
|
}
|
||||||
def withLogger(logger: Option[coursier.cache.CacheLogger]): CoursierConfiguration = {
|
def withLogger(logger: Option[coursier.cache.CacheLogger]): CoursierConfiguration = {
|
||||||
copy(logger = logger)
|
copy(logger = logger)
|
||||||
|
|
@ -130,6 +126,6 @@ final class CoursierConfiguration private (
|
||||||
object CoursierConfiguration {
|
object CoursierConfiguration {
|
||||||
|
|
||||||
def apply(): CoursierConfiguration = new CoursierConfiguration()
|
def apply(): CoursierConfiguration = new CoursierConfiguration()
|
||||||
def apply(log: Option[xsbti.Logger], resolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: Option[String], sbtScalaVersion: Option[String], sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: Option[String], scalaVersion: Option[String], authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)], authenticationByHost: Vector[(String, coursier.core.Authentication)], logger: Option[coursier.cache.CacheLogger], cache: Option[java.io.File]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, authenticationByRepositoryId, authenticationByHost, logger, cache)
|
def apply(log: Option[xsbti.Logger], resolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: Option[String], sbtScalaVersion: Option[String], sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: Option[String], scalaVersion: Option[String], credentials: Seq[coursier.credentials.Credentials], logger: Option[coursier.cache.CacheLogger], cache: Option[java.io.File]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, credentials, logger, cache)
|
||||||
def apply(log: xsbti.Logger, resolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: String, sbtScalaVersion: String, sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: String, scalaVersion: String, authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)], authenticationByHost: Vector[(String, coursier.core.Authentication)], logger: coursier.cache.CacheLogger, cache: java.io.File): CoursierConfiguration = new CoursierConfiguration(Option(log), resolvers, reorderResolvers, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, Option(scalaOrganization), Option(scalaVersion), authenticationByRepositoryId, authenticationByHost, Option(logger), Option(cache))
|
def apply(log: xsbti.Logger, resolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: String, sbtScalaVersion: String, sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: String, scalaVersion: String, credentials: Seq[coursier.credentials.Credentials], logger: coursier.cache.CacheLogger, cache: java.io.File): CoursierConfiguration = new CoursierConfiguration(Option(log), resolvers, reorderResolvers, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, Option(scalaOrganization), Option(scalaVersion), credentials, Option(logger), Option(cache))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,14 +110,8 @@
|
||||||
"since": "0.0.1"
|
"since": "0.0.1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "authenticationByRepositoryId",
|
"name": "credentials",
|
||||||
"type": "(String, coursier.core.Authentication)*",
|
"type": "Seq[coursier.credentials.Credentials]",
|
||||||
"default": "Vector.empty",
|
|
||||||
"since": "0.0.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "authenticationByHost",
|
|
||||||
"type": "(String, coursier.core.Authentication)*",
|
|
||||||
"default": "Vector.empty",
|
"default": "Vector.empty",
|
||||||
"since": "0.0.1"
|
"since": "0.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import java.io.File
|
||||||
|
|
||||||
import _root_.coursier.{Artifact, Organization, Resolution, organizationString}
|
import _root_.coursier.{Artifact, Organization, Resolution, organizationString}
|
||||||
import _root_.coursier.core.{Classifier, Configuration, ModuleName}
|
import _root_.coursier.core.{Classifier, Configuration, ModuleName}
|
||||||
import _root_.coursier.lmcoursier.Inputs.withAuthenticationByHost
|
|
||||||
import coursier.cache.{CacheDefaults, FileCache}
|
import coursier.cache.{CacheDefaults, FileCache}
|
||||||
import coursier.internal.Typelevel
|
import coursier.internal.Typelevel
|
||||||
import sbt.internal.librarymanagement.IvySbt
|
import sbt.internal.librarymanagement.IvySbt
|
||||||
|
|
@ -87,18 +86,14 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
else
|
else
|
||||||
None
|
None
|
||||||
|
|
||||||
val authenticationByRepositoryId = conf.authenticationByRepositoryId.toMap
|
|
||||||
|
|
||||||
val mainRepositories = resolvers
|
val mainRepositories = resolvers
|
||||||
.flatMap { resolver =>
|
.flatMap { resolver =>
|
||||||
FromSbt.repository(
|
FromSbt.repository(
|
||||||
resolver,
|
resolver,
|
||||||
ivyProperties,
|
ivyProperties,
|
||||||
log,
|
log
|
||||||
authenticationByRepositoryId.get(resolver.name)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.map(withAuthenticationByHost(_, conf.authenticationByHost.toMap))
|
|
||||||
|
|
||||||
val interProjectRepo = InterProjectRepository(conf.interProjectDependencies)
|
val interProjectRepo = InterProjectRepository(conf.interProjectDependencies)
|
||||||
|
|
||||||
|
|
@ -123,6 +118,13 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
|
|
||||||
val typelevel = so == Typelevel.typelevelOrg
|
val typelevel = so == Typelevel.typelevelOrg
|
||||||
|
|
||||||
|
val cache0 = coursier.cache.FileCache()
|
||||||
|
.withLocation(cache)
|
||||||
|
.withCachePolicies(cachePolicies)
|
||||||
|
.withTtl(ttl)
|
||||||
|
.withChecksums(checksums)
|
||||||
|
.withCredentials(conf.credentials)
|
||||||
|
|
||||||
val resolutionParams = ResolutionParams(
|
val resolutionParams = ResolutionParams(
|
||||||
dependencies = dependencies,
|
dependencies = dependencies,
|
||||||
fallbackDependencies = conf.fallbackDependencies,
|
fallbackDependencies = conf.fallbackDependencies,
|
||||||
|
|
@ -135,11 +137,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
sbtClassifiers = false,
|
sbtClassifiers = false,
|
||||||
projectName = projectName,
|
projectName = projectName,
|
||||||
loggerOpt = loggerOpt,
|
loggerOpt = loggerOpt,
|
||||||
cache = coursier.cache.FileCache()
|
cache = cache0,
|
||||||
.withLocation(cache)
|
|
||||||
.withCachePolicies(cachePolicies)
|
|
||||||
.withTtl(ttl)
|
|
||||||
.withChecksums(checksums),
|
|
||||||
parallel = conf.parallelDownloads,
|
parallel = conf.parallelDownloads,
|
||||||
params = coursier.params.ResolutionParams()
|
params = coursier.params.ResolutionParams()
|
||||||
.withMaxIterations(conf.maxIterations)
|
.withMaxIterations(conf.maxIterations)
|
||||||
|
|
@ -156,11 +154,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
loggerOpt = loggerOpt,
|
loggerOpt = loggerOpt,
|
||||||
projectName = projectName,
|
projectName = projectName,
|
||||||
sbtClassifiers = false,
|
sbtClassifiers = false,
|
||||||
cache = FileCache()
|
cache = cache0,
|
||||||
.withLocation(cache)
|
|
||||||
.withChecksums(checksums)
|
|
||||||
.withTtl(ttl)
|
|
||||||
.withCachePolicies(cachePolicies),
|
|
||||||
parallel = conf.parallelDownloads
|
parallel = conf.parallelDownloads
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,18 +195,12 @@ object FromSbt {
|
||||||
|
|
||||||
private def mavenRepositoryOpt(
|
private def mavenRepositoryOpt(
|
||||||
root: String,
|
root: String,
|
||||||
log: Logger,
|
log: Logger
|
||||||
authentication: Option[Authentication]
|
|
||||||
): Option[MavenRepository] =
|
): Option[MavenRepository] =
|
||||||
try {
|
try {
|
||||||
CacheUrl.url(root) // ensure root is a URL whose protocol can be handled here
|
CacheUrl.url(root) // ensure root is a URL whose protocol can be handled here
|
||||||
val root0 = if (root.endsWith("/")) root else root + "/"
|
val root0 = if (root.endsWith("/")) root else root + "/"
|
||||||
Some(
|
Some(MavenRepository(root0))
|
||||||
MavenRepository(
|
|
||||||
root0,
|
|
||||||
authentication = authentication
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} catch {
|
} catch {
|
||||||
case e: MalformedURLException =>
|
case e: MalformedURLException =>
|
||||||
log.warn(
|
log.warn(
|
||||||
|
|
@ -222,12 +216,11 @@ object FromSbt {
|
||||||
def repository(
|
def repository(
|
||||||
resolver: Resolver,
|
resolver: Resolver,
|
||||||
ivyProperties: Map[String, String],
|
ivyProperties: Map[String, String],
|
||||||
log: Logger,
|
log: Logger
|
||||||
authentication: Option[Authentication]
|
|
||||||
): Option[Repository] =
|
): Option[Repository] =
|
||||||
resolver match {
|
resolver match {
|
||||||
case r: sbt.librarymanagement.MavenRepository =>
|
case r: sbt.librarymanagement.MavenRepository =>
|
||||||
mavenRepositoryOpt(r.root, log, authentication)
|
mavenRepositoryOpt(r.root, log)
|
||||||
|
|
||||||
case r: FileRepository
|
case r: FileRepository
|
||||||
if r.patterns.ivyPatterns.lengthCompare(1) == 0 &&
|
if r.patterns.ivyPatterns.lengthCompare(1) == 0 &&
|
||||||
|
|
@ -243,8 +236,7 @@ object FromSbt {
|
||||||
metadataPatternOpt = Some("file://" + r.patterns.ivyPatterns.head),
|
metadataPatternOpt = Some("file://" + r.patterns.ivyPatterns.head),
|
||||||
changing = Some(true),
|
changing = Some(true),
|
||||||
properties = ivyProperties,
|
properties = ivyProperties,
|
||||||
dropInfoAttributes = true,
|
dropInfoAttributes = true
|
||||||
authentication = authentication
|
|
||||||
) match {
|
) match {
|
||||||
case Left(err) =>
|
case Left(err) =>
|
||||||
sys.error(
|
sys.error(
|
||||||
|
|
@ -257,18 +249,18 @@ object FromSbt {
|
||||||
Some(repo)
|
Some(repo)
|
||||||
|
|
||||||
case Some(mavenCompatibleBase) =>
|
case Some(mavenCompatibleBase) =>
|
||||||
mavenRepositoryOpt("file://" + mavenCompatibleBase, log, authentication)
|
mavenRepositoryOpt("file://" + mavenCompatibleBase, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
case r: URLRepository if patternMatchGuard(r.patterns) =>
|
case r: URLRepository if patternMatchGuard(r.patterns) =>
|
||||||
parseMavenCompatResolver(log, ivyProperties, authentication, r.patterns)
|
parseMavenCompatResolver(log, ivyProperties, r.patterns)
|
||||||
|
|
||||||
case raw: RawRepository if raw.name == "inter-project" => // sbt.RawRepository.equals just compares names anyway
|
case raw: RawRepository if raw.name == "inter-project" => // sbt.RawRepository.equals just compares names anyway
|
||||||
None
|
None
|
||||||
|
|
||||||
// Pattern Match resolver-type-specific RawRepositories
|
// Pattern Match resolver-type-specific RawRepositories
|
||||||
case IBiblioRepository(p) =>
|
case IBiblioRepository(p) =>
|
||||||
parseMavenCompatResolver(log, ivyProperties, authentication, p)
|
parseMavenCompatResolver(log, ivyProperties, p)
|
||||||
|
|
||||||
case other =>
|
case other =>
|
||||||
log.warn(s"Unrecognized repository ${other.name}, ignoring it")
|
log.warn(s"Unrecognized repository ${other.name}, ignoring it")
|
||||||
|
|
@ -312,7 +304,6 @@ object FromSbt {
|
||||||
private def parseMavenCompatResolver(
|
private def parseMavenCompatResolver(
|
||||||
log: Logger,
|
log: Logger,
|
||||||
ivyProperties: Map[String, String],
|
ivyProperties: Map[String, String],
|
||||||
authentication: Option[Authentication],
|
|
||||||
patterns: Patterns
|
patterns: Patterns
|
||||||
): Option[Repository] = {
|
): Option[Repository] = {
|
||||||
val mavenCompatibleBaseOpt0 = mavenCompatibleBaseOpt(patterns)
|
val mavenCompatibleBaseOpt0 = mavenCompatibleBaseOpt(patterns)
|
||||||
|
|
@ -325,8 +316,7 @@ object FromSbt {
|
||||||
metadataPatternOpt = Some(patterns.ivyPatterns.head),
|
metadataPatternOpt = Some(patterns.ivyPatterns.head),
|
||||||
changing = None,
|
changing = None,
|
||||||
properties = ivyProperties,
|
properties = ivyProperties,
|
||||||
dropInfoAttributes = true,
|
dropInfoAttributes = true
|
||||||
authentication = authentication
|
|
||||||
) match {
|
) match {
|
||||||
case Left(err) =>
|
case Left(err) =>
|
||||||
sys.error(
|
sys.error(
|
||||||
|
|
@ -339,7 +329,7 @@ object FromSbt {
|
||||||
Some(repo)
|
Some(repo)
|
||||||
|
|
||||||
case Some(mavenCompatibleBase) =>
|
case Some(mavenCompatibleBase) =>
|
||||||
mavenRepositoryOpt(mavenCompatibleBase, log, authentication)
|
mavenRepositoryOpt(mavenCompatibleBase, log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
package coursier
|
|
||||||
|
|
||||||
import java.io.{File, FileInputStream}
|
|
||||||
import java.util.Properties
|
|
||||||
|
|
||||||
import coursier.core.Authentication
|
|
||||||
|
|
||||||
sealed abstract class Credentials extends Product with Serializable {
|
|
||||||
def user: String
|
|
||||||
def password: String
|
|
||||||
|
|
||||||
def authentication: Authentication =
|
|
||||||
Authentication(user, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
object Credentials {
|
|
||||||
|
|
||||||
final case class Direct(user: String, password: String) extends Credentials {
|
|
||||||
override def toString = s"Direct($user, ******)"
|
|
||||||
}
|
|
||||||
|
|
||||||
final case class FromFile(file: File) extends Credentials {
|
|
||||||
|
|
||||||
private lazy val props = {
|
|
||||||
val p = new Properties()
|
|
||||||
p.load(new FileInputStream(file))
|
|
||||||
p
|
|
||||||
}
|
|
||||||
|
|
||||||
private def findKey(keys: Seq[String]) = keys
|
|
||||||
.iterator
|
|
||||||
.map(props.getProperty)
|
|
||||||
.filter(_ != null)
|
|
||||||
.toStream
|
|
||||||
.headOption
|
|
||||||
.getOrElse {
|
|
||||||
throw new NoSuchElementException(s"${keys.head} key in $file")
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy val user: String = findKey(FromFile.fileUserKeys)
|
|
||||||
lazy val password: String = findKey(FromFile.filePasswordKeys)
|
|
||||||
}
|
|
||||||
|
|
||||||
object FromFile {
|
|
||||||
// from sbt.Credentials
|
|
||||||
private val fileUserKeys = Seq("user", "user.name", "username")
|
|
||||||
private val filePasswordKeys = Seq("password", "pwd", "pass", "passwd")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def apply(user: String, password: String): Credentials =
|
|
||||||
Direct(user, password)
|
|
||||||
|
|
||||||
def apply(file: File): Credentials =
|
|
||||||
FromFile(file)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package coursier.sbtcoursiershared
|
package coursier.sbtcoursiershared
|
||||||
|
|
||||||
import coursier.core._
|
import coursier.core._
|
||||||
|
import coursier.credentials.DirectCredentials
|
||||||
import coursier.lmcoursier._
|
import coursier.lmcoursier._
|
||||||
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
|
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
|
||||||
import coursier.sbtcoursiershared.Structure._
|
import coursier.sbtcoursiershared.Structure._
|
||||||
|
|
@ -181,32 +182,40 @@ object InputsTasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val authenticationByHostTask = Def.taskDyn {
|
val credentialsTask = Def.taskDyn {
|
||||||
|
|
||||||
val useSbtCredentials = coursierUseSbtCredentials.value
|
val useSbtCredentials = coursierUseSbtCredentials.value
|
||||||
|
|
||||||
if (useSbtCredentials)
|
val fromSbt =
|
||||||
Def.task {
|
if (useSbtCredentials)
|
||||||
val log = streams.value.log
|
Def.task {
|
||||||
|
val log = streams.value.log
|
||||||
|
|
||||||
sbt.Keys.credentials.value
|
sbt.Keys.credentials.value
|
||||||
.flatMap {
|
.flatMap {
|
||||||
case dc: sbt.DirectCredentials => List(dc)
|
case dc: sbt.DirectCredentials => List(dc)
|
||||||
case fc: sbt.FileCredentials =>
|
case fc: sbt.FileCredentials =>
|
||||||
sbt.Credentials.loadCredentials(fc.path) match {
|
sbt.Credentials.loadCredentials(fc.path) match {
|
||||||
case Left(err) =>
|
case Left(err) =>
|
||||||
log.warn(s"$err, ignoring it")
|
log.warn(s"$err, ignoring it")
|
||||||
Nil
|
Nil
|
||||||
case Right(dc) => List(dc)
|
case Right(dc) => List(dc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { c =>
|
.map { c =>
|
||||||
c.host -> Authentication(c.userName, c.passwd)
|
DirectCredentials()
|
||||||
}
|
.withHost(c.host)
|
||||||
.toMap
|
.withUsername(c.userName)
|
||||||
}
|
.withPassword(c.passwd)
|
||||||
else
|
.withRealm(Some(c.realm).filter(_.nonEmpty))
|
||||||
Def.task(Map.empty[String, Authentication])
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Def.task(Seq.empty[DirectCredentials])
|
||||||
|
|
||||||
|
Def.task {
|
||||||
|
fromSbt.value ++ coursierExtraCredentials.value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package coursier.sbtcoursiershared
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import coursier.cache.{CacheDefaults, CacheLogger}
|
import coursier.cache.{CacheDefaults, CacheLogger}
|
||||||
import coursier.Credentials
|
|
||||||
import coursier.core.{Configuration, Project, Publication}
|
import coursier.core.{Configuration, Project, Publication}
|
||||||
|
import coursier.credentials.Credentials
|
||||||
import coursier.lmcoursier.{FallbackDependency, SbtCoursierCache}
|
import coursier.lmcoursier.{FallbackDependency, SbtCoursierCache}
|
||||||
import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey}
|
import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey}
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
|
|
@ -35,7 +35,7 @@ object SbtCoursierShared extends AutoPlugin {
|
||||||
val mavenProfiles = settingKey[Set[String]]("")
|
val mavenProfiles = settingKey[Set[String]]("")
|
||||||
|
|
||||||
val coursierUseSbtCredentials = settingKey[Boolean]("")
|
val coursierUseSbtCredentials = settingKey[Boolean]("")
|
||||||
val coursierCredentials = taskKey[Map[String, Credentials]]("")
|
val coursierExtraCredentials = taskKey[Seq[Credentials]]("")
|
||||||
|
|
||||||
val coursierLogger = taskKey[Option[CacheLogger]]("")
|
val coursierLogger = taskKey[Option[CacheLogger]]("")
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ object SbtCoursierShared extends AutoPlugin {
|
||||||
coursierReorderResolvers := true,
|
coursierReorderResolvers := true,
|
||||||
coursierKeepPreloaded := false,
|
coursierKeepPreloaded := false,
|
||||||
coursierUseSbtCredentials := true,
|
coursierUseSbtCredentials := true,
|
||||||
coursierCredentials := Map.empty,
|
coursierExtraCredentials := Nil,
|
||||||
coursierLogger := None,
|
coursierLogger := None,
|
||||||
coursierCache := CacheDefaults.location
|
coursierCache := CacheDefaults.location
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import coursier.cache.FileCache
|
||||||
import coursier.core._
|
import coursier.core._
|
||||||
import coursier.lmcoursier._
|
import coursier.lmcoursier._
|
||||||
import coursier.sbtcoursier.Keys._
|
import coursier.sbtcoursier.Keys._
|
||||||
|
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
|
||||||
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport.{coursierCache, coursierLogger}
|
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport.{coursierCache, coursierLogger}
|
||||||
import sbt.Def
|
import sbt.Def
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
|
|
@ -45,6 +46,7 @@ object ArtifactsTasks {
|
||||||
val ttl = coursierTtl.value
|
val ttl = coursierTtl.value
|
||||||
val cache = coursierCache.value
|
val cache = coursierCache.value
|
||||||
val createLogger = coursierLogger.value
|
val createLogger = coursierLogger.value
|
||||||
|
val credentials = credentialsTask.value
|
||||||
|
|
||||||
val log = streams.value.log
|
val log = streams.value.log
|
||||||
|
|
||||||
|
|
@ -64,7 +66,8 @@ object ArtifactsTasks {
|
||||||
.withLocation(cache)
|
.withLocation(cache)
|
||||||
.withChecksums(artifactsChecksums)
|
.withChecksums(artifactsChecksums)
|
||||||
.withTtl(ttl)
|
.withTtl(ttl)
|
||||||
.withCachePolicies(cachePolicies),
|
.withCachePolicies(cachePolicies)
|
||||||
|
.withCredentials(credentials),
|
||||||
parallel = parallelDownloads
|
parallel = parallelDownloads
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@ import coursier.cache.FileCache
|
||||||
import coursier.core._
|
import coursier.core._
|
||||||
import coursier.internal.Typelevel
|
import coursier.internal.Typelevel
|
||||||
import coursier.lmcoursier._
|
import coursier.lmcoursier._
|
||||||
import coursier.lmcoursier.Inputs.withAuthenticationByHost
|
|
||||||
import coursier.sbtcoursier.Keys._
|
import coursier.sbtcoursier.Keys._
|
||||||
import coursier.sbtcoursiershared.InputsTasks.authenticationByHostTask
|
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
|
||||||
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
|
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
|
||||||
import sbt.Def
|
import sbt.Def
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
|
|
@ -82,8 +81,6 @@ object ResolutionTasks {
|
||||||
|
|
||||||
val ivyProperties = ResolutionParams.defaultIvyProperties()
|
val ivyProperties = ResolutionParams.defaultIvyProperties()
|
||||||
|
|
||||||
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication)
|
|
||||||
|
|
||||||
val (currentProject, fallbackDependencies, configGraphs) = currentProjectTask.value
|
val (currentProject, fallbackDependencies, configGraphs) = currentProjectTask.value
|
||||||
|
|
||||||
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
|
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
|
||||||
|
|
@ -92,7 +89,7 @@ object ResolutionTasks {
|
||||||
|
|
||||||
// TODO Warn about possible duplicated modules from source repositories?
|
// TODO Warn about possible duplicated modules from source repositories?
|
||||||
|
|
||||||
val authenticationByHost = authenticationByHostTask.value
|
val credentials = credentialsTask.value
|
||||||
|
|
||||||
val parentProjectCache: ProjectCache = coursierParentProjectCache.value
|
val parentProjectCache: ProjectCache = coursierParentProjectCache.value
|
||||||
.get(resolvers)
|
.get(resolvers)
|
||||||
|
|
@ -104,11 +101,9 @@ object ResolutionTasks {
|
||||||
FromSbt.repository(
|
FromSbt.repository(
|
||||||
resolver,
|
resolver,
|
||||||
ivyProperties,
|
ivyProperties,
|
||||||
log,
|
log
|
||||||
authenticationByRepositoryId.get(resolver.name)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.map(withAuthenticationByHost(_, authenticationByHost))
|
|
||||||
|
|
||||||
val resOrError = ResolutionRun.resolutions(
|
val resOrError = ResolutionRun.resolutions(
|
||||||
ResolutionParams(
|
ResolutionParams(
|
||||||
|
|
@ -128,7 +123,7 @@ object ResolutionTasks {
|
||||||
.withCachePolicies(cachePolicies)
|
.withCachePolicies(cachePolicies)
|
||||||
.withTtl(ttl)
|
.withTtl(ttl)
|
||||||
.withChecksums(checksums)
|
.withChecksums(checksums)
|
||||||
,
|
.withCredentials(credentials),
|
||||||
parallel = parallelDownloads,
|
parallel = parallelDownloads,
|
||||||
params = coursier.params.ResolutionParams()
|
params = coursier.params.ResolutionParams()
|
||||||
.withMaxIterations(maxIterations)
|
.withMaxIterations(maxIterations)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,18 @@
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
scalaVersion := "2.11.8"
|
scalaVersion := "2.11.8"
|
||||||
|
|
||||||
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
|
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
|
||||||
|
|
||||||
coursierCredentials += "authenticated" -> coursier.Credentials(file("credentials"))
|
coursierExtraCredentials += {
|
||||||
|
val content =
|
||||||
|
s"""foo.host=${uri(sys.env("TEST_REPOSITORY")).getHost}
|
||||||
|
|foo.username=user
|
||||||
|
|foo.password=pass
|
||||||
|
""".stripMargin
|
||||||
|
val dest = baseDirectory.in(ThisBuild).value / "project" / "target" / "cred"
|
||||||
|
Files.write(dest.toPath, content.getBytes("UTF-8"))
|
||||||
|
coursier.credentials.Credentials(dest)
|
||||||
|
}
|
||||||
|
|
||||||
libraryDependencies += "com.abc" % "test" % "0.1"
|
libraryDependencies += "com.abc" % "test" % "0.1"
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
user=user
|
|
||||||
password=pass
|
|
||||||
|
|
@ -2,7 +2,8 @@ scalaVersion := "2.11.8"
|
||||||
|
|
||||||
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
|
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
|
||||||
|
|
||||||
coursierCredentials += "authenticated" -> coursier.Credentials(
|
coursierExtraCredentials += coursier.credentials.Credentials(
|
||||||
|
uri(sys.env("TEST_REPOSITORY")).getHost,
|
||||||
sys.env("TEST_REPOSITORY_USER"),
|
sys.env("TEST_REPOSITORY_USER"),
|
||||||
sys.env("TEST_REPOSITORY_PASSWORD")
|
sys.env("TEST_REPOSITORY_PASSWORD")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package coursier.sbtlmcoursier
|
||||||
|
|
||||||
import coursier.core.Classifier
|
import coursier.core.Classifier
|
||||||
import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs}
|
import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs}
|
||||||
import coursier.sbtcoursiershared.InputsTasks.authenticationByHostTask
|
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
|
||||||
import coursier.sbtcoursiershared.SbtCoursierShared
|
import coursier.sbtcoursiershared.SbtCoursierShared
|
||||||
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
|
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
|
||||||
import sbt.Project.inTask
|
import sbt.Project.inTask
|
||||||
|
|
@ -87,8 +87,7 @@ object LmCoursierPlugin extends AutoPlugin {
|
||||||
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
|
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
|
||||||
val profiles = mavenProfiles.value
|
val profiles = mavenProfiles.value
|
||||||
|
|
||||||
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication)
|
val credentials = credentialsTask.value
|
||||||
val authenticationByHost = authenticationByHostTask.value
|
|
||||||
|
|
||||||
val createLogger = coursierLogger.value
|
val createLogger = coursierLogger.value
|
||||||
|
|
||||||
|
|
@ -123,8 +122,7 @@ object LmCoursierPlugin extends AutoPlugin {
|
||||||
.withMavenProfiles(profiles.toVector.sorted)
|
.withMavenProfiles(profiles.toVector.sorted)
|
||||||
.withScalaOrganization(scalaOrg)
|
.withScalaOrganization(scalaOrg)
|
||||||
.withScalaVersion(scalaVer)
|
.withScalaVersion(scalaVer)
|
||||||
.withAuthenticationByRepositoryId(authenticationByRepositoryId.toVector.sortBy(_._1))
|
.withCredentials(credentials)
|
||||||
.withAuthenticationByHost(authenticationByHost.toVector.sortBy(_._1))
|
|
||||||
.withLogger(createLogger)
|
.withLogger(createLogger)
|
||||||
.withCache(cache)
|
.withCache(cache)
|
||||||
.withLog(s.log)
|
.withLog(s.log)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue