Allow to tweak logger from sbt-lm-coursier too

This commit is contained in:
Alexandre Archambault 2018-11-22 14:14:35 +01:00
parent 40489f7fee
commit 3b8e2f42cd
13 changed files with 66 additions and 29 deletions

View File

@ -23,22 +23,24 @@ final class CoursierConfiguration private (
val scalaOrganization: Option[String],
val scalaVersion: Option[String],
val authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)],
val authenticationByHost: Vector[(String, coursier.core.Authentication)]) extends Serializable {
val authenticationByHost: Vector[(String, coursier.core.Authentication)],
val createLogger: Option[coursier.lmcoursier.CreateLogger],
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)
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.authenticationByRepositoryId == x.authenticationByRepositoryId) && (this.authenticationByHost == x.authenticationByHost)
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.createLogger == x.createLogger) && (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 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) + fallbackDependencies.##) + autoScalaLibrary.##) + hasClassifiers.##) + classifiers.##) + mavenProfiles.##) + scalaOrganization.##) + scalaVersion.##) + authenticationByRepositoryId.##) + authenticationByHost.##)
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.##) + createLogger.##) + 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 + ")"
"CoursierConfiguration(" + log + ", " + resolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ", " + fallbackDependencies + ", " + autoScalaLibrary + ", " + hasClassifiers + ", " + classifiers + ", " + mavenProfiles + ", " + scalaOrganization + ", " + scalaVersion + ", " + authenticationByRepositoryId + ", " + authenticationByHost + ", " + createLogger + ", " + 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): CoursierConfiguration = {
new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, authenticationByRepositoryId, authenticationByHost)
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, createLogger: Option[coursier.lmcoursier.CreateLogger] = createLogger, 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, createLogger, cache)
}
def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = {
copy(log = log)
@ -112,10 +114,22 @@ final class CoursierConfiguration private (
def withAuthenticationByHost(authenticationByHost: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = {
copy(authenticationByHost = authenticationByHost)
}
def withCreateLogger(createLogger: Option[coursier.lmcoursier.CreateLogger]): CoursierConfiguration = {
copy(createLogger = createLogger)
}
def withCreateLogger(createLogger: coursier.lmcoursier.CreateLogger): CoursierConfiguration = {
copy(createLogger = Option(createLogger))
}
def withCache(cache: Option[java.io.File]): CoursierConfiguration = {
copy(cache = cache)
}
def withCache(cache: java.io.File): CoursierConfiguration = {
copy(cache = Option(cache))
}
}
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)]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, scalaOrganization, scalaVersion, authenticationByRepositoryId, authenticationByHost)
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)]): 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)
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)], createLogger: Option[coursier.lmcoursier.CreateLogger], 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, createLogger, 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)], createLogger: coursier.lmcoursier.CreateLogger, 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(createLogger), Option(cache))
}

View File

@ -120,6 +120,18 @@
"type": "(String, coursier.core.Authentication)*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "createLogger",
"type": "coursier.lmcoursier.CreateLogger?",
"default": "None",
"since": "0.0.1"
},
{
"name": "cache",
"type": "java.io.File?",
"default": "None",
"since": "0.0.1"
}
]
}

View File

@ -69,10 +69,10 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
val verbosityLevel = 0
val ttl = Cache.defaultTtl
val createLogger = { () =>
val createLogger = conf.createLogger.map(_.create).getOrElse { () =>
new TermDisplay(new OutputStreamWriter(System.err), fallbackMode = true)
}
val cache = Cache.default
val cache = conf.cache.getOrElse(Cache.default)
val cachePolicies = CachePolicy.default
val checksums = Cache.defaultChecksums
val projectName = "" // used for logging only

View File

@ -0,0 +1,3 @@
package coursier.lmcoursier
final case class CreateLogger(create: () => coursier.Cache.Logger)

View File

@ -1,8 +1,10 @@
package coursier.sbtcoursiershared
import coursier.Credentials
import java.io.{File, OutputStreamWriter}
import coursier.{Cache, Credentials, TermDisplay}
import coursier.core.{Configuration, Project, Publication}
import coursier.lmcoursier.{FallbackDependency, SbtCoursierCache}
import coursier.lmcoursier.{CreateLogger, FallbackDependency, SbtCoursierCache}
import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey}
import sbt.Keys._
import sbt.librarymanagement.{Resolver, URLRepository}
@ -33,6 +35,13 @@ object SbtCoursierShared extends AutoPlugin {
val coursierUseSbtCredentials = settingKey[Boolean]("")
val coursierCredentials = taskKey[Map[String, Credentials]]("")
val coursierCreateLogger = taskKey[CreateLogger]("")
val coursierCache = settingKey[File]("")
type CoursierCreateLogger = coursier.lmcoursier.CreateLogger
val CoursierCreateLogger = coursier.lmcoursier.CreateLogger
}
import autoImport._
@ -45,7 +54,9 @@ object SbtCoursierShared extends AutoPlugin {
coursierReorderResolvers := true,
coursierKeepPreloaded := false,
coursierUseSbtCredentials := true,
coursierCredentials := Map.empty
coursierCredentials := Map.empty,
coursierCreateLogger := CreateLogger { () => new TermDisplay(new OutputStreamWriter(System.err)) },
coursierCache := Cache.default
)
private val pluginIvySnapshotsBase = Resolver.SbtRepositoryRoot.stripSuffix("/") + "/ivy-snapshots"

View File

@ -6,6 +6,7 @@ import coursier.{Artifact, FileError}
import coursier.core._
import coursier.lmcoursier._
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport.{coursierCache, coursierCreateLogger}
import sbt.Def
import sbt.Keys._
@ -56,7 +57,7 @@ object ArtifactsTasks {
res,
includeSignatures,
parallelDownloads,
createLogger,
createLogger.create,
cache,
artifactsChecksums,
ttl,

View File

@ -1,8 +1,6 @@
package coursier.sbtcoursier
import java.io.OutputStreamWriter
import coursier.{Cache, CachePolicy, TermDisplay}
import coursier.{Cache, CachePolicy}
import coursier.core.{Configuration, ResolutionProcess}
import coursier.sbtcoursiershared.SbtCoursierShared
import sbt.{Cache => _, Configuration => _, _}
@ -22,7 +20,6 @@ object CoursierPlugin extends AutoPlugin {
val coursierCachePolicies = Keys.coursierCachePolicies
val coursierTtl = Keys.coursierTtl
val coursierVerbosity = Keys.coursierVerbosity
val coursierCache = Keys.coursierCache
val coursierConfigGraphs = Keys.coursierConfigGraphs
val coursierSbtClassifiersModule = Keys.coursierSbtClassifiersModule
@ -42,8 +39,6 @@ object CoursierPlugin extends AutoPlugin {
val coursierClassifiersArtifacts = Keys.coursierClassifiersArtifacts
val coursierSbtClassifiersArtifacts = Keys.coursierSbtClassifiersArtifacts
val coursierCreateLogger = Keys.coursierCreateLogger
val coursierVersion = coursier.util.Properties.version
val addSbtCoursier = {
addSbtPlugin("io.get-coursier" % "sbt-coursier" % coursierVersion)
@ -191,9 +186,7 @@ object CoursierPlugin extends AutoPlugin {
coursierArtifactsChecksums := Seq(None),
coursierCachePolicies := CachePolicy.default,
coursierTtl := Cache.defaultTtl,
coursierVerbosity := Settings.defaultVerbosityLevel(sLog.value),
coursierCache := Cache.default,
coursierCreateLogger := { () => new TermDisplay(new OutputStreamWriter(System.err)) }
coursierVerbosity := Settings.defaultVerbosityLevel(sLog.value)
)
override lazy val projectSettings = coursierSettings() ++

View File

@ -17,12 +17,9 @@ object Keys {
val coursierArtifactsChecksums = SettingKey[Seq[Option[String]]]("coursier-artifacts-checksums")
val coursierCachePolicies = SettingKey[Seq[CachePolicy]]("coursier-cache-policies")
val coursierTtl = SettingKey[Option[Duration]]("coursier-ttl")
val coursierCreateLogger = TaskKey[() => Cache.Logger]("coursier-create-logger")
val coursierVerbosity = SettingKey[Int]("coursier-verbosity")
val coursierCache = SettingKey[File]("coursier-cache")
val coursierConfigGraphs = TaskKey[Seq[Set[Configuration]]]("coursier-config-graphs")
val coursierSbtClassifiersModule = TaskKey[GetClassifiersModule]("coursier-sbt-classifiers-module")

View File

@ -140,7 +140,7 @@ object ResolutionTasks {
parallelDownloads,
projectName,
maxIterations,
createLogger,
createLogger.create,
cache,
cachePolicies,
ttl,

View File

@ -13,7 +13,7 @@ coursierCreateLogger := {
logStream.println(msg)
}
val cacheFile = coursierCache.value
;{ () =>
;CoursierCreateLogger { () =>
new coursier.Cache.Logger {
override def init(beforeOutput: => Unit): Unit = {
beforeOutput

View File

@ -80,6 +80,10 @@ object LmCoursierPlugin extends AutoPlugin {
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication)
val authenticationByHost = authenticationByHostTask.value
val createLogger = coursierCreateLogger.value
val cache = coursierCache.value
val internalSbtScalaProvider = appConfiguration.value.provider.scalaProvider
val sbtBootJars = internalSbtScalaProvider.jars()
val sbtScalaVersion = internalSbtScalaProvider.version()
@ -111,6 +115,8 @@ object LmCoursierPlugin extends AutoPlugin {
.withScalaVersion(scalaVer)
.withAuthenticationByRepositoryId(authenticationByRepositoryId.toVector.sortBy(_._1))
.withAuthenticationByHost(authenticationByHost.toVector.sortBy(_._1))
.withCreateLogger(createLogger)
.withCache(cache)
.withLog(s.log)
}
}