From 84d8d7ac38fca9b714d3d0d1a54268c3adb14e8f Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 3 Apr 2019 15:40:19 +0200 Subject: [PATCH 1/6] Switch to coursier 1.1.0-M14 --- build.sbt | 2 +- .../coursier/lmcoursier/CoursierDependencyResolution.scala | 4 ++-- .../src/main/scala/coursier/sbtcoursier/CoursierPlugin.scala | 2 +- .../src/main/scala/coursier/sbtcoursier/DisplayTasks.scala | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 473412e74..4de1d44e7 100644 --- a/build.sbt +++ b/build.sbt @@ -21,7 +21,7 @@ lazy val `lm-coursier` = project .settings( shared, libraryDependencies ++= Seq( - "io.get-coursier" %% "coursier" % "1.1.0-M13-2", + "io.get-coursier" %% "coursier" % "1.1.0-M14-1", // We depend on librarymanagement-ivy rather than just // librarymanagement-core to handle the ModuleDescriptor passed // to DependencyResolutionInterface.update, which is an diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala index a6ee832db..d6a0db792 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala @@ -5,7 +5,7 @@ import java.io.File import _root_.coursier.{Artifact, Organization, Resolution, organizationString} import _root_.coursier.core.{Classifier, Configuration, ModuleName} import _root_.coursier.lmcoursier.Inputs.withAuthenticationByHost -import coursier.cache.{CacheDefaults, CachePolicy, FileCache} +import coursier.cache.{CacheDefaults, FileCache} import coursier.internal.Typelevel import sbt.internal.librarymanagement.IvySbt import sbt.librarymanagement._ @@ -75,7 +75,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen val ttl = CacheDefaults.ttl val loggerOpt = conf.logger val cache = conf.cache.getOrElse(CacheDefaults.location) - val cachePolicies = CachePolicy.default + val cachePolicies = CacheDefaults.cachePolicies val checksums = CacheDefaults.checksums val projectName = "" // used for logging only… diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/CoursierPlugin.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/CoursierPlugin.scala index fa164d19d..e76f84d8c 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/CoursierPlugin.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/CoursierPlugin.scala @@ -191,7 +191,7 @@ object CoursierPlugin extends AutoPlugin { coursierMaxIterations := ResolutionProcess.defaultMaxIterations, coursierChecksums := Seq(Some("SHA-1"), None), coursierArtifactsChecksums := Seq(None), - coursierCachePolicies := CachePolicy.default, + coursierCachePolicies := CacheDefaults.cachePolicies, coursierTtl := CacheDefaults.ttl, coursierVerbosity := Settings.defaultVerbosityLevel(sLog.value) ) diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/DisplayTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/DisplayTasks.scala index 0da889b8f..2ff2b5256 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/DisplayTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/DisplayTasks.scala @@ -2,9 +2,10 @@ package coursier.sbtcoursier import coursier.core._ import coursier.lmcoursier._ +import coursier.parse.ModuleParser import coursier.sbtcoursier.Keys._ import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._ -import coursier.util.{Parse, Print} +import coursier.util.Print import sbt.Def import sbt.Keys._ @@ -102,7 +103,7 @@ object DisplayTasks { sbtClassifiers: Boolean = false, ignoreArtifactErrors: Boolean = false ) = Def.task { - val module = Parse.module(moduleName, scalaVersion.value) + val module = ModuleParser.module(moduleName, scalaVersion.value) .right .getOrElse(throw new RuntimeException(s"Could not parse module `$moduleName`")) From 973cce68adc7cc892d18353109b91cb299523abd Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 3 Apr 2019 16:13:18 +0200 Subject: [PATCH 2/6] Rework / simplify credentials handling --- .../lmcoursier/CoursierConfiguration.scala | 26 ++++----- .../src/main/contraband/lm-coursier.json | 10 +--- .../CoursierDependencyResolution.scala | 26 ++++----- .../scala/coursier/lmcoursier/FromSbt.scala | 30 ++++------ .../src/main/scala/coursier/Credentials.scala | 57 ------------------- .../sbtcoursiershared/InputsTasks.scala | 53 ++++++++++------- .../sbtcoursiershared/SbtCoursierShared.scala | 6 +- .../coursier/sbtcoursier/ArtifactsTasks.scala | 5 +- .../sbtcoursier/ResolutionTasks.scala | 13 ++--- .../shared-1/credentials-from-file/build.sbt | 13 ++++- .../credentials-from-file/credentials | 2 - .../sbt-test/shared-1/credentials/build.sbt | 3 +- .../sbtlmcoursier/LmCoursierPlugin.scala | 8 +-- 13 files changed, 92 insertions(+), 160 deletions(-) delete mode 100644 modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala delete mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/credentials diff --git a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala index c18c5c8da..f968a642d 100644 --- a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala +++ b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala @@ -22,25 +22,24 @@ final class CoursierConfiguration private ( val mavenProfiles: Vector[String], val scalaOrganization: Option[String], val scalaVersion: Option[String], - val authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)], - val authenticationByHost: Vector[(String, coursier.core.Authentication)], + val credentials: Seq[coursier.credentials.Credentials], val logger: Option[coursier.cache.CacheLogger], 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 { - 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 } 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 = { - "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 = { - new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, authenticationByRepositoryId, authenticationByHost, 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, 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, credentials, logger, cache) } def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = { copy(log = log) @@ -108,11 +107,8 @@ final class CoursierConfiguration private ( def withScalaVersion(scalaVersion: String): CoursierConfiguration = { copy(scalaVersion = Option(scalaVersion)) } - def withAuthenticationByRepositoryId(authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = { - copy(authenticationByRepositoryId = authenticationByRepositoryId) - } - def withAuthenticationByHost(authenticationByHost: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = { - copy(authenticationByHost = authenticationByHost) + def withCredentials(credentials: Seq[coursier.credentials.Credentials]): CoursierConfiguration = { + copy(credentials = credentials) } def withLogger(logger: Option[coursier.cache.CacheLogger]): CoursierConfiguration = { copy(logger = logger) @@ -130,6 +126,6 @@ final class CoursierConfiguration private ( object 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: 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: 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, 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)) } diff --git a/modules/lm-coursier/src/main/contraband/lm-coursier.json b/modules/lm-coursier/src/main/contraband/lm-coursier.json index c97f96821..aa72d3212 100644 --- a/modules/lm-coursier/src/main/contraband/lm-coursier.json +++ b/modules/lm-coursier/src/main/contraband/lm-coursier.json @@ -110,14 +110,8 @@ "since": "0.0.1" }, { - "name": "authenticationByRepositoryId", - "type": "(String, coursier.core.Authentication)*", - "default": "Vector.empty", - "since": "0.0.1" - }, - { - "name": "authenticationByHost", - "type": "(String, coursier.core.Authentication)*", + "name": "credentials", + "type": "Seq[coursier.credentials.Credentials]", "default": "Vector.empty", "since": "0.0.1" }, diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala index d6a0db792..0dda8d3bc 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala @@ -4,7 +4,6 @@ import java.io.File import _root_.coursier.{Artifact, Organization, Resolution, organizationString} import _root_.coursier.core.{Classifier, Configuration, ModuleName} -import _root_.coursier.lmcoursier.Inputs.withAuthenticationByHost import coursier.cache.{CacheDefaults, FileCache} import coursier.internal.Typelevel import sbt.internal.librarymanagement.IvySbt @@ -87,18 +86,14 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen else None - val authenticationByRepositoryId = conf.authenticationByRepositoryId.toMap - val mainRepositories = resolvers .flatMap { resolver => FromSbt.repository( resolver, ivyProperties, - log, - authenticationByRepositoryId.get(resolver.name) + log ) } - .map(withAuthenticationByHost(_, conf.authenticationByHost.toMap)) val interProjectRepo = InterProjectRepository(conf.interProjectDependencies) @@ -123,6 +118,13 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen val typelevel = so == Typelevel.typelevelOrg + val cache0 = coursier.cache.FileCache() + .withLocation(cache) + .withCachePolicies(cachePolicies) + .withTtl(ttl) + .withChecksums(checksums) + .withCredentials(conf.credentials) + val resolutionParams = ResolutionParams( dependencies = dependencies, fallbackDependencies = conf.fallbackDependencies, @@ -135,11 +137,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen sbtClassifiers = false, projectName = projectName, loggerOpt = loggerOpt, - cache = coursier.cache.FileCache() - .withLocation(cache) - .withCachePolicies(cachePolicies) - .withTtl(ttl) - .withChecksums(checksums), + cache = cache0, parallel = conf.parallelDownloads, params = coursier.params.ResolutionParams() .withMaxIterations(conf.maxIterations) @@ -156,11 +154,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen loggerOpt = loggerOpt, projectName = projectName, sbtClassifiers = false, - cache = FileCache() - .withLocation(cache) - .withChecksums(checksums) - .withTtl(ttl) - .withCachePolicies(cachePolicies), + cache = cache0, parallel = conf.parallelDownloads ) diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala index 0dcbd5f82..739bf4f2a 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala @@ -195,18 +195,12 @@ object FromSbt { private def mavenRepositoryOpt( root: String, - log: Logger, - authentication: Option[Authentication] + log: Logger ): Option[MavenRepository] = try { CacheUrl.url(root) // ensure root is a URL whose protocol can be handled here val root0 = if (root.endsWith("/")) root else root + "/" - Some( - MavenRepository( - root0, - authentication = authentication - ) - ) + Some(MavenRepository(root0)) } catch { case e: MalformedURLException => log.warn( @@ -222,12 +216,11 @@ object FromSbt { def repository( resolver: Resolver, ivyProperties: Map[String, String], - log: Logger, - authentication: Option[Authentication] + log: Logger ): Option[Repository] = resolver match { case r: sbt.librarymanagement.MavenRepository => - mavenRepositoryOpt(r.root, log, authentication) + mavenRepositoryOpt(r.root, log) case r: FileRepository if r.patterns.ivyPatterns.lengthCompare(1) == 0 && @@ -243,8 +236,7 @@ object FromSbt { metadataPatternOpt = Some("file://" + r.patterns.ivyPatterns.head), changing = Some(true), properties = ivyProperties, - dropInfoAttributes = true, - authentication = authentication + dropInfoAttributes = true ) match { case Left(err) => sys.error( @@ -257,18 +249,18 @@ object FromSbt { Some(repo) case Some(mavenCompatibleBase) => - mavenRepositoryOpt("file://" + mavenCompatibleBase, log, authentication) + mavenRepositoryOpt("file://" + mavenCompatibleBase, log) } 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 None // Pattern Match resolver-type-specific RawRepositories case IBiblioRepository(p) => - parseMavenCompatResolver(log, ivyProperties, authentication, p) + parseMavenCompatResolver(log, ivyProperties, p) case other => log.warn(s"Unrecognized repository ${other.name}, ignoring it") @@ -312,7 +304,6 @@ object FromSbt { private def parseMavenCompatResolver( log: Logger, ivyProperties: Map[String, String], - authentication: Option[Authentication], patterns: Patterns ): Option[Repository] = { val mavenCompatibleBaseOpt0 = mavenCompatibleBaseOpt(patterns) @@ -325,8 +316,7 @@ object FromSbt { metadataPatternOpt = Some(patterns.ivyPatterns.head), changing = None, properties = ivyProperties, - dropInfoAttributes = true, - authentication = authentication + dropInfoAttributes = true ) match { case Left(err) => sys.error( @@ -339,7 +329,7 @@ object FromSbt { Some(repo) case Some(mavenCompatibleBase) => - mavenRepositoryOpt(mavenCompatibleBase, log, authentication) + mavenRepositoryOpt(mavenCompatibleBase, log) } } } diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala deleted file mode 100644 index ac55f8579..000000000 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala +++ /dev/null @@ -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) - -} diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala index e54f3671c..417f510cd 100644 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala @@ -1,6 +1,7 @@ package coursier.sbtcoursiershared import coursier.core._ +import coursier.credentials.DirectCredentials import coursier.lmcoursier._ import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._ import coursier.sbtcoursiershared.Structure._ @@ -181,32 +182,40 @@ object InputsTasks { } } - val authenticationByHostTask = Def.taskDyn { + val credentialsTask = Def.taskDyn { val useSbtCredentials = coursierUseSbtCredentials.value - if (useSbtCredentials) - Def.task { - val log = streams.value.log + val fromSbt = + if (useSbtCredentials) + Def.task { + val log = streams.value.log - sbt.Keys.credentials.value - .flatMap { - case dc: sbt.DirectCredentials => List(dc) - case fc: sbt.FileCredentials => - sbt.Credentials.loadCredentials(fc.path) match { - case Left(err) => - log.warn(s"$err, ignoring it") - Nil - case Right(dc) => List(dc) - } - } - .map { c => - c.host -> Authentication(c.userName, c.passwd) - } - .toMap - } - else - Def.task(Map.empty[String, Authentication]) + sbt.Keys.credentials.value + .flatMap { + case dc: sbt.DirectCredentials => List(dc) + case fc: sbt.FileCredentials => + sbt.Credentials.loadCredentials(fc.path) match { + case Left(err) => + log.warn(s"$err, ignoring it") + Nil + case Right(dc) => List(dc) + } + } + .map { c => + DirectCredentials() + .withHost(c.host) + .withUsername(c.userName) + .withPassword(c.passwd) + .withRealm(Some(c.realm).filter(_.nonEmpty)) + } + } + else + Def.task(Seq.empty[DirectCredentials]) + + Def.task { + fromSbt.value ++ coursierExtraCredentials.value + } } } diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala index 45832c5c0..443f854b9 100644 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala @@ -3,8 +3,8 @@ package coursier.sbtcoursiershared import java.io.File import coursier.cache.{CacheDefaults, CacheLogger} -import coursier.Credentials import coursier.core.{Configuration, Project, Publication} +import coursier.credentials.Credentials import coursier.lmcoursier.{FallbackDependency, SbtCoursierCache} import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey} import sbt.Keys._ @@ -35,7 +35,7 @@ object SbtCoursierShared extends AutoPlugin { val mavenProfiles = settingKey[Set[String]]("") val coursierUseSbtCredentials = settingKey[Boolean]("") - val coursierCredentials = taskKey[Map[String, Credentials]]("") + val coursierExtraCredentials = taskKey[Seq[Credentials]]("") val coursierLogger = taskKey[Option[CacheLogger]]("") @@ -54,7 +54,7 @@ object SbtCoursierShared extends AutoPlugin { coursierReorderResolvers := true, coursierKeepPreloaded := false, coursierUseSbtCredentials := true, - coursierCredentials := Map.empty, + coursierExtraCredentials := Nil, coursierLogger := None, coursierCache := CacheDefaults.location ) diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala index 33a05738d..c62f90fa0 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala @@ -7,6 +7,7 @@ import coursier.cache.FileCache import coursier.core._ import coursier.lmcoursier._ import coursier.sbtcoursier.Keys._ +import coursier.sbtcoursiershared.InputsTasks.credentialsTask import coursier.sbtcoursiershared.SbtCoursierShared.autoImport.{coursierCache, coursierLogger} import sbt.Def import sbt.Keys._ @@ -45,6 +46,7 @@ object ArtifactsTasks { val ttl = coursierTtl.value val cache = coursierCache.value val createLogger = coursierLogger.value + val credentials = credentialsTask.value val log = streams.value.log @@ -64,7 +66,8 @@ object ArtifactsTasks { .withLocation(cache) .withChecksums(artifactsChecksums) .withTtl(ttl) - .withCachePolicies(cachePolicies), + .withCachePolicies(cachePolicies) + .withCredentials(credentials), parallel = parallelDownloads ) diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala index 42492274c..4591611d3 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala @@ -5,9 +5,8 @@ import coursier.cache.FileCache import coursier.core._ import coursier.internal.Typelevel import coursier.lmcoursier._ -import coursier.lmcoursier.Inputs.withAuthenticationByHost import coursier.sbtcoursier.Keys._ -import coursier.sbtcoursiershared.InputsTasks.authenticationByHostTask +import coursier.sbtcoursiershared.InputsTasks.credentialsTask import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._ import sbt.Def import sbt.Keys._ @@ -82,8 +81,6 @@ object ResolutionTasks { val ivyProperties = ResolutionParams.defaultIvyProperties() - val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) - val (currentProject, fallbackDependencies, configGraphs) = currentProjectTask.value val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion) @@ -92,7 +89,7 @@ object ResolutionTasks { // TODO Warn about possible duplicated modules from source repositories? - val authenticationByHost = authenticationByHostTask.value + val credentials = credentialsTask.value val parentProjectCache: ProjectCache = coursierParentProjectCache.value .get(resolvers) @@ -104,11 +101,9 @@ object ResolutionTasks { FromSbt.repository( resolver, ivyProperties, - log, - authenticationByRepositoryId.get(resolver.name) + log ) } - .map(withAuthenticationByHost(_, authenticationByHost)) val resOrError = ResolutionRun.resolutions( ResolutionParams( @@ -128,7 +123,7 @@ object ResolutionTasks { .withCachePolicies(cachePolicies) .withTtl(ttl) .withChecksums(checksums) - , + .withCredentials(credentials), parallel = parallelDownloads, params = coursier.params.ResolutionParams() .withMaxIterations(maxIterations) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/build.sbt index 7ffe593d5..863b76a75 100644 --- a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/build.sbt +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/build.sbt @@ -1,7 +1,18 @@ +import java.nio.file.Files + scalaVersion := "2.11.8" 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" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/credentials b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/credentials deleted file mode 100644 index 03c71b2e5..000000000 --- a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file/credentials +++ /dev/null @@ -1,2 +0,0 @@ -user=user -password=pass diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials/build.sbt index 36d2ead16..8d8515275 100644 --- a/modules/sbt-coursier/src/sbt-test/shared-1/credentials/build.sbt +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials/build.sbt @@ -2,7 +2,8 @@ scalaVersion := "2.11.8" 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_PASSWORD") ) diff --git a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala index 857871620..0a2430764 100644 --- a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala +++ b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala @@ -2,7 +2,7 @@ package coursier.sbtlmcoursier import coursier.core.Classifier import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs} -import coursier.sbtcoursiershared.InputsTasks.authenticationByHostTask +import coursier.sbtcoursiershared.InputsTasks.credentialsTask import coursier.sbtcoursiershared.SbtCoursierShared import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey} import sbt.Project.inTask @@ -87,8 +87,7 @@ object LmCoursierPlugin extends AutoPlugin { val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion) val profiles = mavenProfiles.value - val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) - val authenticationByHost = authenticationByHostTask.value + val credentials = credentialsTask.value val createLogger = coursierLogger.value @@ -123,8 +122,7 @@ object LmCoursierPlugin extends AutoPlugin { .withMavenProfiles(profiles.toVector.sorted) .withScalaOrganization(scalaOrg) .withScalaVersion(scalaVer) - .withAuthenticationByRepositoryId(authenticationByRepositoryId.toVector.sortBy(_._1)) - .withAuthenticationByHost(authenticationByHost.toVector.sortBy(_._1)) + .withCredentials(credentials) .withLogger(createLogger) .withCache(cache) .withLog(s.log) From 2c6a6503f133415bb024993ac7ce87d6ce4f535e Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 4 Apr 2019 11:12:11 +0200 Subject: [PATCH 3/6] Add back former coursierCredentials key Not to break compatibility with former plugins --- .../lmcoursier/CoursierConfiguration.scala | 20 ++++--- .../src/main/contraband/lm-coursier.json | 6 ++ .../CoursierDependencyResolution.scala | 5 +- .../scala/coursier/lmcoursier/FromSbt.scala | 30 ++++++---- .../src/main/scala/coursier/Credentials.scala | 60 +++++++++++++++++++ .../sbtcoursiershared/SbtCoursierShared.scala | 4 ++ .../sbtcoursier/ResolutionTasks.scala | 5 +- .../credentials-from-file-legacy/build.sbt | 7 +++ .../credentials-from-file-legacy/credentials | 2 + .../project/plugins.sbt | 13 ++++ .../src/main/scala/Main.scala | 1 + .../credentials-from-file-legacy/test | 1 + .../shared-1/credentials-legacy/build.sbt | 10 ++++ .../credentials-legacy/project/plugins.sbt | 13 ++++ .../src/main/scala/Main.scala | 1 + .../sbt-test/shared-1/credentials-legacy/test | 1 + .../sbtlmcoursier/LmCoursierPlugin.scala | 2 + 17 files changed, 161 insertions(+), 20 deletions(-) create mode 100644 modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/credentials create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/project/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/src/main/scala/Main.scala create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/test create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/project/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/src/main/scala/Main.scala create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/test diff --git a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala index f968a642d..e466689ac 100644 --- a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala +++ b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala @@ -22,24 +22,25 @@ final class CoursierConfiguration private ( val mavenProfiles: Vector[String], val scalaOrganization: Option[String], val scalaVersion: Option[String], + val authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)], val credentials: Seq[coursier.credentials.Credentials], val logger: Option[coursier.cache.CacheLogger], 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, 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, Vector.empty, None, None) 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.credentials == x.credentials) && (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.authenticationByRepositoryId == x.authenticationByRepositoryId) && (this.credentials == x.credentials) && (this.logger == x.logger) && (this.cache == x.cache) case _ => false } 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 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) + fallbackDependencies.##) + autoScalaLibrary.##) + hasClassifiers.##) + classifiers.##) + mavenProfiles.##) + scalaOrganization.##) + scalaVersion.##) + credentials.##) + logger.##) + cache.##) + 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.##) + credentials.##) + logger.##) + cache.##) } override def toString: String = { - "CoursierConfiguration(" + log + ", " + resolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ", " + fallbackDependencies + ", " + autoScalaLibrary + ", " + hasClassifiers + ", " + classifiers + ", " + mavenProfiles + ", " + scalaOrganization + ", " + scalaVersion + ", " + credentials + ", " + logger + ", " + cache + ")" + "CoursierConfiguration(" + log + ", " + resolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ", " + fallbackDependencies + ", " + autoScalaLibrary + ", " + hasClassifiers + ", " + classifiers + ", " + mavenProfiles + ", " + scalaOrganization + ", " + scalaVersion + ", " + authenticationByRepositoryId + ", " + 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, 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, 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, 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, credentials, logger, cache) } def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = { copy(log = log) @@ -107,6 +108,9 @@ final class CoursierConfiguration private ( def withScalaVersion(scalaVersion: String): CoursierConfiguration = { copy(scalaVersion = Option(scalaVersion)) } + def withAuthenticationByRepositoryId(authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = { + copy(authenticationByRepositoryId = authenticationByRepositoryId) + } def withCredentials(credentials: Seq[coursier.credentials.Credentials]): CoursierConfiguration = { copy(credentials = credentials) } @@ -126,6 +130,6 @@ final class CoursierConfiguration private ( object 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], 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, 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)) + 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)], 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, authenticationByRepositoryId, 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)], 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), authenticationByRepositoryId, credentials, Option(logger), Option(cache)) } diff --git a/modules/lm-coursier/src/main/contraband/lm-coursier.json b/modules/lm-coursier/src/main/contraband/lm-coursier.json index aa72d3212..7e46fe61c 100644 --- a/modules/lm-coursier/src/main/contraband/lm-coursier.json +++ b/modules/lm-coursier/src/main/contraband/lm-coursier.json @@ -109,6 +109,12 @@ "default": "None", "since": "0.0.1" }, + { + "name": "authenticationByRepositoryId", + "type": "(String, coursier.core.Authentication)*", + "default": "Vector.empty", + "since": "0.0.1" + }, { "name": "credentials", "type": "Seq[coursier.credentials.Credentials]", diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala index 0dda8d3bc..6835bf97b 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala @@ -86,12 +86,15 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen else None + val authenticationByRepositoryId = conf.authenticationByRepositoryId.toMap + val mainRepositories = resolvers .flatMap { resolver => FromSbt.repository( resolver, ivyProperties, - log + log, + authenticationByRepositoryId.get(resolver.name) ) } diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala index 739bf4f2a..0dcbd5f82 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/FromSbt.scala @@ -195,12 +195,18 @@ object FromSbt { private def mavenRepositoryOpt( root: String, - log: Logger + log: Logger, + authentication: Option[Authentication] ): Option[MavenRepository] = try { CacheUrl.url(root) // ensure root is a URL whose protocol can be handled here val root0 = if (root.endsWith("/")) root else root + "/" - Some(MavenRepository(root0)) + Some( + MavenRepository( + root0, + authentication = authentication + ) + ) } catch { case e: MalformedURLException => log.warn( @@ -216,11 +222,12 @@ object FromSbt { def repository( resolver: Resolver, ivyProperties: Map[String, String], - log: Logger + log: Logger, + authentication: Option[Authentication] ): Option[Repository] = resolver match { case r: sbt.librarymanagement.MavenRepository => - mavenRepositoryOpt(r.root, log) + mavenRepositoryOpt(r.root, log, authentication) case r: FileRepository if r.patterns.ivyPatterns.lengthCompare(1) == 0 && @@ -236,7 +243,8 @@ object FromSbt { metadataPatternOpt = Some("file://" + r.patterns.ivyPatterns.head), changing = Some(true), properties = ivyProperties, - dropInfoAttributes = true + dropInfoAttributes = true, + authentication = authentication ) match { case Left(err) => sys.error( @@ -249,18 +257,18 @@ object FromSbt { Some(repo) case Some(mavenCompatibleBase) => - mavenRepositoryOpt("file://" + mavenCompatibleBase, log) + mavenRepositoryOpt("file://" + mavenCompatibleBase, log, authentication) } case r: URLRepository if patternMatchGuard(r.patterns) => - parseMavenCompatResolver(log, ivyProperties, r.patterns) + parseMavenCompatResolver(log, ivyProperties, authentication, r.patterns) case raw: RawRepository if raw.name == "inter-project" => // sbt.RawRepository.equals just compares names anyway None // Pattern Match resolver-type-specific RawRepositories case IBiblioRepository(p) => - parseMavenCompatResolver(log, ivyProperties, p) + parseMavenCompatResolver(log, ivyProperties, authentication, p) case other => log.warn(s"Unrecognized repository ${other.name}, ignoring it") @@ -304,6 +312,7 @@ object FromSbt { private def parseMavenCompatResolver( log: Logger, ivyProperties: Map[String, String], + authentication: Option[Authentication], patterns: Patterns ): Option[Repository] = { val mavenCompatibleBaseOpt0 = mavenCompatibleBaseOpt(patterns) @@ -316,7 +325,8 @@ object FromSbt { metadataPatternOpt = Some(patterns.ivyPatterns.head), changing = None, properties = ivyProperties, - dropInfoAttributes = true + dropInfoAttributes = true, + authentication = authentication ) match { case Left(err) => sys.error( @@ -329,7 +339,7 @@ object FromSbt { Some(repo) case Some(mavenCompatibleBase) => - mavenRepositoryOpt(mavenCompatibleBase, log) + mavenRepositoryOpt(mavenCompatibleBase, log, authentication) } } } diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala new file mode 100644 index 000000000..70223ec26 --- /dev/null +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/Credentials.scala @@ -0,0 +1,60 @@ +package coursier + +import java.io.{File, FileInputStream} +import java.util.Properties + +import coursier.core.Authentication + +@deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") +sealed abstract class Credentials extends Product with Serializable { + def user: String + def password: String + + def authentication: Authentication = + Authentication(user, password) +} + +object Credentials { + + private final case class Direct(user: String, password: String) extends Credentials { + override def toString = s"Direct($user, ******)" + } + + private 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) + } + + private object FromFile { + // from sbt.Credentials + private val fileUserKeys = Seq("user", "user.name", "username") + private val filePasswordKeys = Seq("password", "pwd", "pass", "passwd") + } + + + @deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") + def apply(user: String, password: String): Credentials = + Direct(user, password) + + @deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") + def apply(file: File): Credentials = + FromFile(file) + +} diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala index 443f854b9..55c1f78e5 100644 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala @@ -3,6 +3,7 @@ package coursier.sbtcoursiershared import java.io.File import coursier.cache.{CacheDefaults, CacheLogger} +import coursier.{Credentials => LegacyCredentials} import coursier.core.{Configuration, Project, Publication} import coursier.credentials.Credentials import coursier.lmcoursier.{FallbackDependency, SbtCoursierCache} @@ -35,6 +36,8 @@ object SbtCoursierShared extends AutoPlugin { val mavenProfiles = settingKey[Set[String]]("") val coursierUseSbtCredentials = settingKey[Boolean]("") + @deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") + val coursierCredentials = taskKey[Map[String, LegacyCredentials]]("") val coursierExtraCredentials = taskKey[Seq[Credentials]]("") val coursierLogger = taskKey[Option[CacheLogger]]("") @@ -54,6 +57,7 @@ object SbtCoursierShared extends AutoPlugin { coursierReorderResolvers := true, coursierKeepPreloaded := false, coursierUseSbtCredentials := true, + coursierCredentials := Map.empty, coursierExtraCredentials := Nil, coursierLogger := None, coursierCache := CacheDefaults.location diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala index 4591611d3..45a13eb85 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala @@ -81,6 +81,8 @@ object ResolutionTasks { val ivyProperties = ResolutionParams.defaultIvyProperties() + val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) + val (currentProject, fallbackDependencies, configGraphs) = currentProjectTask.value val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion) @@ -101,7 +103,8 @@ object ResolutionTasks { FromSbt.repository( resolver, ivyProperties, - log + log, + authenticationByRepositoryId.get(resolver.name) ) } diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/build.sbt new file mode 100644 index 000000000..7ffe593d5 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/build.sbt @@ -0,0 +1,7 @@ +scalaVersion := "2.11.8" + +resolvers += "authenticated" at sys.env("TEST_REPOSITORY") + +coursierCredentials += "authenticated" -> coursier.Credentials(file("credentials")) + +libraryDependencies += "com.abc" % "test" % "0.1" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/credentials b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/credentials new file mode 100644 index 000000000..03c71b2e5 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/credentials @@ -0,0 +1,2 @@ +user=user +password=pass diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/project/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/project/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/src/main/scala/Main.scala b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/src/main/scala/Main.scala new file mode 100644 index 000000000..86ae9e9e3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/src/main/scala/Main.scala @@ -0,0 +1 @@ +object Main extends App \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/test b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/test new file mode 100644 index 000000000..103bd8d2f --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-from-file-legacy/test @@ -0,0 +1 @@ +> update diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/build.sbt new file mode 100644 index 000000000..36d2ead16 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/build.sbt @@ -0,0 +1,10 @@ +scalaVersion := "2.11.8" + +resolvers += "authenticated" at sys.env("TEST_REPOSITORY") + +coursierCredentials += "authenticated" -> coursier.Credentials( + sys.env("TEST_REPOSITORY_USER"), + sys.env("TEST_REPOSITORY_PASSWORD") +) + +libraryDependencies += "com.abc" % "test" % "0.1" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/project/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/project/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/src/main/scala/Main.scala b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/src/main/scala/Main.scala new file mode 100644 index 000000000..86ae9e9e3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/src/main/scala/Main.scala @@ -0,0 +1 @@ +object Main extends App \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/test b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/test new file mode 100644 index 000000000..103bd8d2f --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-legacy/test @@ -0,0 +1 @@ +> update diff --git a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala index 0a2430764..1a16c37e4 100644 --- a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala +++ b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala @@ -87,6 +87,7 @@ object LmCoursierPlugin extends AutoPlugin { val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion) val profiles = mavenProfiles.value + val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) val credentials = credentialsTask.value val createLogger = coursierLogger.value @@ -122,6 +123,7 @@ object LmCoursierPlugin extends AutoPlugin { .withMavenProfiles(profiles.toVector.sorted) .withScalaOrganization(scalaOrg) .withScalaVersion(scalaVer) + .withAuthenticationByRepositoryId(authenticationByRepositoryId.toVector.sortBy(_._1)) .withCredentials(credentials) .withLogger(createLogger) .withCache(cache) From 73c5d9737d44af1a7d4a2b8f73bc2c2917f61398 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 4 Apr 2019 11:35:12 +0200 Subject: [PATCH 4/6] Handle credentials key from global settings --- .../sbtcoursiershared/SbtCoursierShared.scala | 10 +++++++--- .../sbt-test/shared-1/credentials-global/build.sbt | 5 +++++ .../shared-1/credentials-global/global/build.sbt | 5 +++++ .../credentials-global/global/plugins/plugins.sbt | 13 +++++++++++++ .../credentials-global/src/main/scala/Main.scala | 1 + .../src/sbt-test/shared-1/credentials-global/test | 1 + .../shared-1/credentials-sbt-global/build.sbt | 5 +++++ .../credentials-sbt-global/global/build.sbt | 7 +++++++ .../global/plugins/plugins.sbt | 13 +++++++++++++ .../src/main/scala/Main.scala | 1 + .../sbt-test/shared-1/credentials-sbt-global/test | 1 + 11 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/plugins/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/src/main/scala/Main.scala create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/test create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/plugins/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/src/main/scala/Main.scala create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/test diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala index 55c1f78e5..c148091d3 100644 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/SbtCoursierShared.scala @@ -52,13 +52,17 @@ object SbtCoursierShared extends AutoPlugin { def publicationsSetting(packageConfigs: Seq[(sbt.Configuration, Configuration)]): Setting[_] = coursierPublications := ArtifactsTasks.coursierPublicationsTask(packageConfigs: _*).value + override def globalSettings: Seq[Setting[_]] = + Seq( + coursierUseSbtCredentials := true, + coursierCredentials := Map.empty, + coursierExtraCredentials := Nil + ) + override def buildSettings: Seq[Setting[_]] = Seq( coursierReorderResolvers := true, coursierKeepPreloaded := false, - coursierUseSbtCredentials := true, - coursierCredentials := Map.empty, - coursierExtraCredentials := Nil, coursierLogger := None, coursierCache := CacheDefaults.location ) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/build.sbt new file mode 100644 index 000000000..50fae1992 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/build.sbt @@ -0,0 +1,5 @@ +scalaVersion := "2.11.8" + +resolvers += "authenticated" at sys.env("TEST_REPOSITORY") + +libraryDependencies += "com.abc" % "test" % "0.1" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/build.sbt new file mode 100644 index 000000000..fe5b794ca --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/build.sbt @@ -0,0 +1,5 @@ +coursierExtraCredentials += coursier.credentials.Credentials( + uri(sys.env("TEST_REPOSITORY")).getHost, + sys.env("TEST_REPOSITORY_USER"), + sys.env("TEST_REPOSITORY_PASSWORD") +) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/plugins/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/plugins/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/global/plugins/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/src/main/scala/Main.scala b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/src/main/scala/Main.scala new file mode 100644 index 000000000..86ae9e9e3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/src/main/scala/Main.scala @@ -0,0 +1 @@ +object Main extends App \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/test b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/test new file mode 100644 index 000000000..103bd8d2f --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-global/test @@ -0,0 +1 @@ +> update diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/build.sbt new file mode 100644 index 000000000..50fae1992 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/build.sbt @@ -0,0 +1,5 @@ +scalaVersion := "2.11.8" + +resolvers += "authenticated" at sys.env("TEST_REPOSITORY") + +libraryDependencies += "com.abc" % "test" % "0.1" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt new file mode 100644 index 000000000..587a2d12f --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt @@ -0,0 +1,7 @@ +coursierUseSbtCredentials := true +credentials += Credentials( + "", + sys.env("TEST_REPOSITORY_HOST"), + sys.env("TEST_REPOSITORY_USER"), + sys.env("TEST_REPOSITORY_PASSWORD") +) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/plugins/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/plugins/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/plugins/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/src/main/scala/Main.scala b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/src/main/scala/Main.scala new file mode 100644 index 000000000..86ae9e9e3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/src/main/scala/Main.scala @@ -0,0 +1 @@ +object Main extends App \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/test b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/test new file mode 100644 index 000000000..103bd8d2f --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/test @@ -0,0 +1 @@ +> update From ed38df56f54b1e9ade1b98680e41244e7bf8d169 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 4 Apr 2019 14:26:30 +0200 Subject: [PATCH 5/6] Remove unnecessary setting --- .../sbt-test/shared-1/credentials-sbt-global/global/build.sbt | 1 - .../sbt-coursier/src/sbt-test/shared-1/credentials-sbt/build.sbt | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt index 587a2d12f..7c17ab948 100644 --- a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt-global/global/build.sbt @@ -1,4 +1,3 @@ -coursierUseSbtCredentials := true credentials += Credentials( "", sys.env("TEST_REPOSITORY_HOST"), diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt/build.sbt index 38eade154..f894add79 100644 --- a/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt/build.sbt +++ b/modules/sbt-coursier/src/sbt-test/shared-1/credentials-sbt/build.sbt @@ -2,7 +2,6 @@ scalaVersion := "2.11.8" resolvers += "authenticated" at sys.env("TEST_REPOSITORY") -coursierUseSbtCredentials := true credentials += Credentials( "", sys.env("TEST_REPOSITORY_HOST"), From cf3705ff8297a8a3e5f5f137ca911b6f31087873 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Fri, 5 Apr 2019 09:07:38 +0200 Subject: [PATCH 6/6] Switch to sbt-coursier 1.1.0-M13-4 in build --- project/project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/project/plugins.sbt b/project/project/plugins.sbt index e15729c54..76801d043 100644 --- a/project/project/plugins.sbt +++ b/project/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M13-3") +addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M13-4")