Merge pull request #238 from alexarchambault/clean-up

Clean-up
This commit is contained in:
Alexandre Archambault 2020-05-21 15:20:57 +02:00 committed by GitHub
commit b82f3a2746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 49 additions and 119 deletions

View File

@ -189,7 +189,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
conf.sbtScalaJars conf.sbtScalaJars
) )
val configs = Inputs.coursierConfigurations(module0.configurations).map { val configs = Inputs.coursierConfigurationsMap(module0.configurations).map {
case (k, l) => case (k, l) =>
ToCoursier.configuration(k) -> l.map(ToCoursier.configuration) ToCoursier.configuration(k) -> l.map(ToCoursier.configuration)
} }
@ -200,7 +200,6 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
) = ) =
UpdateParams( UpdateParams(
thisModule = (ToCoursier.module(mod), ver), thisModule = (ToCoursier.module(mod), ver),
shadedConfigOpt = None,
artifacts = artifacts.collect { case (d, p, a, Some(f)) => a -> f }.toMap, artifacts = artifacts.collect { case (d, p, a, Some(f)) => a -> f }.toMap,
fullArtifacts = Some(artifacts.map { case (d, p, a, f) => (d, p, a) -> f }.toMap), fullArtifacts = Some(artifacts.map { case (d, p, a, f) => (d, p, a) -> f }.toMap),
classifiers = classifiers, classifiers = classifiers,

View File

@ -25,10 +25,11 @@ object Inputs {
.map(cfg => Configuration(cfg.name) -> cfg.extendsConfigs.map(c => Configuration(c.name))) .map(cfg => Configuration(cfg.name) -> cfg.extendsConfigs.map(c => Configuration(c.name)))
.toMap .toMap
def coursierConfigurations( @deprecated("Use coursierConfigurationsMap instead", "2.0.0-RC6-5")
configurations: Seq[sbt.librarymanagement.Configuration], def coursierConfigurations(configurations: Seq[sbt.librarymanagement.Configuration], shadedConfigOpt: Option[String] = None): Map[Configuration, Set[Configuration]] =
shadedConfig: Option[(String, Configuration)] = None coursierConfigurationsMap(configurations)
): Map[Configuration, Set[Configuration]] = {
def coursierConfigurationsMap(configurations: Seq[sbt.librarymanagement.Configuration]): Map[Configuration, Set[Configuration]] = {
val configs0 = configExtendsSeq(configurations).toMap val configs0 = configExtendsSeq(configurations).toMap
@ -45,19 +46,10 @@ object Inputs {
helper(Set(c)) helper(Set(c))
} }
val map = configs0.map { configs0.map {
case (config, _) => case (config, _) =>
config -> allExtends(config) config -> allExtends(config)
} }
map ++ shadedConfig.toSeq.flatMap {
case (baseConfig, shadedConfig0) =>
val baseConfig0 = Configuration(baseConfig)
Seq(
baseConfig0 -> (map.getOrElse(baseConfig0, Set(baseConfig0)) + shadedConfig0),
shadedConfig0 -> map.getOrElse(shadedConfig0, Set(shadedConfig0))
)
}
} }
def orderedConfigurations( def orderedConfigurations(

View File

@ -1,6 +1,5 @@
package lmcoursier package lmcoursier
import lmcoursier.Inputs
import lmcoursier.definitions.{Configuration, Project} import lmcoursier.definitions.{Configuration, Project}
import scala.xml.{Node, PrefixedAttribute} import scala.xml.{Node, PrefixedAttribute}
@ -9,8 +8,7 @@ object IvyXml {
def apply( def apply(
currentProject: Project, currentProject: Project,
exclusions: Seq[(String, String)], exclusions: Seq[(String, String)]
shadedConfigOpt: Option[Configuration]
): String = { ): String = {
// Important: width = Int.MaxValue, so that no tag gets truncated. // Important: width = Int.MaxValue, so that no tag gets truncated.
@ -22,29 +20,15 @@ object IvyXml {
val printer = new scala.xml.PrettyPrinter(Int.MaxValue, 2) val printer = new scala.xml.PrettyPrinter(Int.MaxValue, 2)
"""<?xml version="1.0" encoding="UTF-8"?>""" + '\n' + """<?xml version="1.0" encoding="UTF-8"?>""" + '\n' +
printer.format(content(currentProject, exclusions, shadedConfigOpt)) printer.format(content(currentProject, exclusions))
} }
// These are required for publish to be fine, later on. // These are required for publish to be fine, later on.
private def content( private def content(
project0: Project, project: Project,
exclusions: Seq[(String, String)], exclusions: Seq[(String, String)]
shadedConfigOpt: Option[Configuration]
): Node = { ): Node = {
val filterOutDependencies =
shadedConfigOpt.toSet[Configuration].flatMap { shadedConfig =>
project0
.dependencies
.collect { case (conf, dep) if conf.value == shadedConfig.value => dep }
}
val project = project0.withDependencies(
project0.dependencies.collect {
case p @ (_, dep) if !filterOutDependencies(dep) => p
}
)
val props = project.module.attributes.toSeq ++ project.properties val props = project.module.attributes.toSeq ++ project.properties
val infoAttrs = props.foldLeft[xml.MetaData](xml.Null) { val infoAttrs = props.foldLeft[xml.MetaData](xml.Null) {
case (acc, (k, v)) => case (acc, (k, v)) =>
@ -72,11 +56,10 @@ object IvyXml {
} % infoAttrs } % infoAttrs
val confElems = project.configurations.toVector.collect { val confElems = project.configurations.toVector.collect {
case (name, extends0) if !shadedConfigOpt.exists(_.value == name.value) => case (name, extends0) =>
val extends1 = shadedConfigOpt.fold(extends0)(c => extends0.filter(_.value != c.value))
val n = <conf name={name.value} visibility="public" description="" /> val n = <conf name={name.value} visibility="public" description="" />
if (extends1.nonEmpty) if (extends0.nonEmpty)
n % <x extends={extends1.map(_.value).mkString(",")} />.attributes n % <x extends={extends0.map(_.value).mkString(",")} />.attributes
else else
n n
} }

View File

@ -8,7 +8,6 @@ import coursier.util.Artifact
// private[coursier] // private[coursier]
final case class UpdateParams( final case class UpdateParams(
thisModule: (Module, String), thisModule: (Module, String),
shadedConfigOpt: Option[(String, Configuration)],
artifacts: Map[Artifact, File], artifacts: Map[Artifact, File],
fullArtifacts: Option[Map[(Dependency, Publication, Artifact), Option[File]]], fullArtifacts: Option[Map[(Dependency, Publication, Artifact), Option[File]]],
classifiers: Option[Seq[Classifier]], classifiers: Option[Seq[Classifier]],

View File

@ -57,15 +57,7 @@ object UpdateRun {
log: Logger log: Logger
): UpdateReport = Lock.lock.synchronized { ): UpdateReport = Lock.lock.synchronized {
val depsByConfig = grouped(params.dependencies)( val depsByConfig = grouped(params.dependencies)
config =>
params.shadedConfigOpt match {
case Some((baseConfig, `config`)) =>
Configuration(baseConfig)
case _ =>
config
}
)
if (verbosityLevel >= 2) { if (verbosityLevel >= 2) {
val finalDeps = dependenciesWithConfig( val finalDeps = dependenciesWithConfig(
@ -94,9 +86,9 @@ object UpdateRun {
) )
} }
private def grouped[K, V](map: Seq[(K, V)])(mapKey: K => K): Map[K, Seq[V]] = private def grouped[K, V](map: Seq[(K, V)]): Map[K, Seq[V]] =
map map
.groupBy(t => mapKey(t._1)) .groupBy(_._1)
.mapValues(_.map(_._2)) .mapValues(_.map(_._2))
.iterator .iterator
.toMap .toMap

View File

@ -1,9 +1,10 @@
package lmcoursier package lmcoursier
import lmcoursier.definitions.{Configuration, Info, Module, ModuleName, Organization, Project} import lmcoursier.definitions.{Configuration, Info, Module, ModuleName, Organization, Project}
import org.scalatest.{Matchers, PropSpec} import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
object IvyXmlTests extends PropSpec with Matchers { object IvyXmlTests extends AnyPropSpec with Matchers {
property("no truncation") { property("no truncation") {
val project = Project( val project = Project(
@ -19,7 +20,7 @@ object IvyXmlTests extends PropSpec with Matchers {
Info("", "", Nil, Nil, None) Info("", "", Nil, Nil, None)
) )
val content = IvyXml(project, Nil, None) val content = IvyXml(project, Nil)
assert(!content.contains("</conf>")) assert(!content.contains("</conf>"))
} }

View File

@ -1,6 +1,7 @@
package lmcoursier package lmcoursier
import org.scalatest.{Matchers, PropSpec} import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
import sbt.internal.librarymanagement.cross.CrossVersionUtil import sbt.internal.librarymanagement.cross.CrossVersionUtil
import sbt.internal.util.ConsoleLogger import sbt.internal.util.ConsoleLogger
import sbt.librarymanagement._ import sbt.librarymanagement._
@ -9,7 +10,7 @@ import sbt.librarymanagement.Resolver.{DefaultMavenRepository, JCenterRepository
import sbt.librarymanagement.{Resolver, UnresolvedWarningConfiguration, UpdateConfiguration} import sbt.librarymanagement.{Resolver, UnresolvedWarningConfiguration, UpdateConfiguration}
import sbt.librarymanagement.syntax._ import sbt.librarymanagement.syntax._
final class ResolutionSpec extends PropSpec with Matchers { final class ResolutionSpec extends AnyPropSpec with Matchers {
lazy val log = ConsoleLogger() lazy val log = ConsoleLogger()

View File

@ -5,7 +5,7 @@ import java.util.Properties
import lmcoursier.definitions.Authentication import lmcoursier.definitions.Authentication
@deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") // actually deprecated (all public ways of creating that are)
sealed abstract class Credentials extends Product with Serializable { sealed abstract class Credentials extends Product with Serializable {
def user: String def user: String
def password: String def password: String

View File

@ -18,7 +18,6 @@ object IvyXmlGeneration {
private def writeFiles( private def writeFiles(
currentProject: Project, currentProject: Project,
exclusions: Seq[(String, String)], exclusions: Seq[(String, String)],
shadedConfigOpt: Option[Configuration],
ivySbt: IvySbt, ivySbt: IvySbt,
log: sbt.util.Logger log: sbt.util.Logger
): Unit = { ): Unit = {
@ -37,7 +36,7 @@ object IvyXmlGeneration {
val cacheIvyFile = ivyCacheManager.getResolvedIvyFileInCache(ivyModule) val cacheIvyFile = ivyCacheManager.getResolvedIvyFileInCache(ivyModule)
val cacheIvyPropertiesFile = ivyCacheManager.getResolvedIvyPropertiesInCache(ivyModule) val cacheIvyPropertiesFile = ivyCacheManager.getResolvedIvyPropertiesInCache(ivyModule)
val content0 = IvyXml(currentProject, exclusions, shadedConfigOpt) val content0 = IvyXml(currentProject, exclusions)
cacheIvyFile.getParentFile.mkdirs() cacheIvyFile.getParentFile.mkdirs()
log.info(s"Writing Ivy file $cacheIvyFile") log.info(s"Writing Ivy file $cacheIvyFile")
Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8)) Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8))
@ -47,10 +46,7 @@ object IvyXmlGeneration {
Files.write(cacheIvyPropertiesFile.toPath, Array.emptyByteArray) Files.write(cacheIvyPropertiesFile.toPath, Array.emptyByteArray)
} }
private def makeIvyXmlBefore[T]( private def makeIvyXmlBefore[T](task: TaskKey[T]): Setting[Task[T]] =
task: TaskKey[T],
shadedConfigOpt: Option[Configuration]
): Setting[Task[T]] =
task := task.dependsOn { task := task.dependsOn {
Def.taskDyn { Def.taskDyn {
import SbtCoursierShared.autoImport._ import SbtCoursierShared.autoImport._
@ -70,7 +66,7 @@ object IvyXmlGeneration {
case (org, name) => case (org, name) =>
(org.value, name.value) (org.value, name.value)
} }
writeFiles(currentProject, excludeDeps, shadedConfigOpt, sbt.Keys.ivySbt.value, log) writeFiles(currentProject, excludeDeps, sbt.Keys.ivySbt.value, log)
} }
else else
Def.task(()) Def.task(())
@ -91,9 +87,7 @@ object IvyXmlGeneration {
Nil Nil
} }
def generateIvyXmlSettings( def generateIvyXmlSettings: Seq[Setting[_]] =
shadedConfigOpt: Option[Configuration] = None (needsIvyXml ++ needsIvyXmlLocal).map(makeIvyXmlBefore)
): Seq[Setting[_]] =
(needsIvyXml ++ needsIvyXmlLocal).map(makeIvyXmlBefore(_, shadedConfigOpt))
} }

View File

@ -40,9 +40,11 @@ object SbtCoursierShared extends AutoPlugin {
val mavenProfiles = settingKey[Set[String]]("") val mavenProfiles = settingKey[Set[String]]("")
val versionReconciliation = taskKey[Seq[ModuleID]]("") val versionReconciliation = taskKey[Seq[ModuleID]]("")
private[coursier] val actualCoursierCredentials = TaskKey[Map[String, LegacyCredentials]]("coursierCredentials", "")
val coursierUseSbtCredentials = settingKey[Boolean]("") val coursierUseSbtCredentials = settingKey[Boolean]("")
@deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14") @deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14")
val coursierCredentials = taskKey[Map[String, LegacyCredentials]]("") val coursierCredentials = actualCoursierCredentials
val coursierExtraCredentials = taskKey[Seq[Credentials]]("") val coursierExtraCredentials = taskKey[Seq[Credentials]]("")
val coursierLogger = taskKey[Option[CacheLogger]]("") val coursierLogger = taskKey[Option[CacheLogger]]("")
@ -60,7 +62,7 @@ object SbtCoursierShared extends AutoPlugin {
override def globalSettings: Seq[Setting[_]] = override def globalSettings: Seq[Setting[_]] =
Seq( Seq(
coursierUseSbtCredentials := true, coursierUseSbtCredentials := true,
coursierCredentials := Map.empty, actualCoursierCredentials := Map.empty,
coursierExtraCredentials := Nil coursierExtraCredentials := Nil
) )
@ -174,7 +176,7 @@ object SbtCoursierShared extends AutoPlugin {
versionReconciliation := Seq.empty versionReconciliation := Seq.empty
) ++ { ) ++ {
if (pubSettings) if (pubSettings)
IvyXmlGeneration.generateIvyXmlSettings() IvyXmlGeneration.generateIvyXmlSettings
else else
Nil Nil
} }

View File

@ -137,9 +137,7 @@ object CoursierPlugin extends AutoPlugin {
} }
) )
def coursierSettings( def coursierSettings: Seq[Setting[_]] = hackHack ++ Seq(
shadedConfigOpt: Option[(String, Configuration)] = None
): Seq[Setting[_]] = hackHack ++ Seq(
coursierArtifacts := ArtifactsTasks.artifactsTask(withClassifiers = false).value, coursierArtifacts := ArtifactsTasks.artifactsTask(withClassifiers = false).value,
coursierSignedArtifacts := ArtifactsTasks.artifactsTask(withClassifiers = false, includeSignatures = true).value, coursierSignedArtifacts := ArtifactsTasks.artifactsTask(withClassifiers = false, includeSignatures = true).value,
coursierClassifiersArtifacts := ArtifactsTasks.artifactsTask( coursierClassifiersArtifacts := ArtifactsTasks.artifactsTask(
@ -149,22 +147,12 @@ object CoursierPlugin extends AutoPlugin {
withClassifiers = true, withClassifiers = true,
sbtClassifiers = true sbtClassifiers = true
).value, ).value,
update := UpdateTasks.updateTask( update := UpdateTasks.updateTask(withClassifiers = false).value,
shadedConfigOpt, updateClassifiers := UpdateTasks.updateTask(withClassifiers = true).value,
withClassifiers = false updateSbtClassifiers.in(Defaults.TaskGlobal) := UpdateTasks.updateTask(withClassifiers = true, sbtClassifiers = true).value,
).value,
updateClassifiers := UpdateTasks.updateTask(
shadedConfigOpt,
withClassifiers = true
).value,
updateSbtClassifiers.in(Defaults.TaskGlobal) := UpdateTasks.updateTask(
shadedConfigOpt,
withClassifiers = true,
sbtClassifiers = true
).value,
coursierConfigGraphs := InputsTasks.ivyGraphsTask.value, coursierConfigGraphs := InputsTasks.ivyGraphsTask.value,
coursierSbtClassifiersModule := classifiersModule.in(updateSbtClassifiers).value, coursierSbtClassifiersModule := classifiersModule.in(updateSbtClassifiers).value,
coursierConfigurations := InputsTasks.coursierConfigurationsTask(None).value, coursierConfigurations := InputsTasks.coursierConfigurationsTask.value,
coursierParentProjectCache := InputsTasks.parentProjectCacheTask.value, coursierParentProjectCache := InputsTasks.parentProjectCacheTask.value,
coursierResolutions := (Def.taskDyn { coursierResolutions := (Def.taskDyn {
val missingOk = updateConfiguration.value.missingOk val missingOk = updateConfiguration.value.missingOk
@ -200,7 +188,7 @@ object CoursierPlugin extends AutoPlugin {
coursierVerbosity := Settings.defaultVerbosityLevel(sLog.value) coursierVerbosity := Settings.defaultVerbosityLevel(sLog.value)
) )
override lazy val projectSettings = coursierSettings() ++ override lazy val projectSettings = coursierSettings ++
inConfig(Compile)(treeSettings) ++ inConfig(Compile)(treeSettings) ++
inConfig(Test)(treeSettings) inConfig(Test)(treeSettings)

View File

@ -13,14 +13,9 @@ import sbt.Keys._
object InputsTasks { object InputsTasks {
def coursierConfigurationsTask( def coursierConfigurationsTask: Def.Initialize[sbt.Task[Map[Configuration, Set[Configuration]]]] =
shadedConfig: Option[(String, Configuration)]
): Def.Initialize[sbt.Task[Map[Configuration, Set[Configuration]]]] =
Def.task { Def.task {
Inputs.coursierConfigurations(ivyConfigurations.value, shadedConfig.map { Inputs.coursierConfigurationsMap(ivyConfigurations.value).map {
case (from, to) =>
(from, lmcoursier.definitions.Configuration(to.value))
}).map {
case (k, v) => case (k, v) =>
ToCoursier.configuration(k) -> v.map(ToCoursier.configuration) ToCoursier.configuration(k) -> v.map(ToCoursier.configuration)
} }

View File

@ -95,7 +95,7 @@ object ResolutionTasks {
val ivyProperties = ResolutionParams.defaultIvyProperties(ivyPaths.value.ivyHome) val ivyProperties = ResolutionParams.defaultIvyProperties(ivyPaths.value.ivyHome)
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) val authenticationByRepositoryId = actualCoursierCredentials.value.mapValues(_.authentication)
val (currentProject, fallbackDependencies, orderedConfigs) = currentProjectTask.value val (currentProject, fallbackDependencies, orderedConfigs) = currentProjectTask.value

View File

@ -12,7 +12,6 @@ import sbt.librarymanagement.UpdateReport
object UpdateTasks { object UpdateTasks {
def updateTask( def updateTask(
shadedConfigOpt: Option[(String, Configuration)],
withClassifiers: Boolean, withClassifiers: Boolean,
sbtClassifiers: Boolean = false, sbtClassifiers: Boolean = false,
includeSignatures: Boolean = false includeSignatures: Boolean = false
@ -57,17 +56,7 @@ object UpdateTasks {
cm.configurations.map(c => Configuration(c.name) -> Set(Configuration(c.name))).toMap cm.configurations.map(c => Configuration(c.name) -> Set(Configuration(c.name))).toMap
} }
else else
Def.task { coursierConfigurations
val configs0 = coursierConfigurations.value
shadedConfigOpt.fold(configs0) {
case (baseConfig, shadedConfig) =>
val baseConfig0 = Configuration(baseConfig)
(configs0 - shadedConfig) + (
baseConfig0 -> (configs0.getOrElse(baseConfig0, Set()) - shadedConfig)
)
}
}
val classifiersTask: sbt.Def.Initialize[sbt.Task[Option[Seq[Classifier]]]] = val classifiersTask: sbt.Def.Initialize[sbt.Task[Option[Seq[Classifier]]]] =
if (withClassifiers) { if (withClassifiers) {
@ -124,7 +113,6 @@ object UpdateTasks {
val params = UpdateParams( val params = UpdateParams(
(p.module, p.version), (p.module, p.version),
shadedConfigOpt,
artifactFilesOrErrors0, artifactFilesOrErrors0,
None, None,
classifiers, classifiers,

View File

@ -134,7 +134,7 @@ object LmCoursierPlugin extends AutoPlugin {
val userForceVersions = Inputs.forceVersions(dependencyOverrides.value, scalaVer, sbv) val userForceVersions = Inputs.forceVersions(dependencyOverrides.value, scalaVer, sbv)
val authenticationByRepositoryId = coursierCredentials.value.mapValues { c => val authenticationByRepositoryId = actualCoursierCredentials.value.mapValues { c =>
val a = c.authentication val a = c.authentication
Authentication(a.user, a.password, a.optional, a.realmOpt) Authentication(a.user, a.password, a.optional, a.realmOpt)
} }

View File

@ -5,6 +5,8 @@ import sbt.Keys._
import sbt.internal.LibraryManagement import sbt.internal.LibraryManagement
import sbt.librarymanagement.DependencyResolution import sbt.librarymanagement.DependencyResolution
import scala.language.reflectiveCalls
object Foo { object Foo {
// same implementation as update in sbt, except DependencyResolution is passed as argument // same implementation as update in sbt, except DependencyResolution is passed as argument

View File

@ -11,13 +11,7 @@ object CoursierSbtPgpPlugin extends AutoPlugin {
override def requires = com.typesafe.sbt.SbtPgp && coursier.sbtcoursier.CoursierPlugin override def requires = com.typesafe.sbt.SbtPgp && coursier.sbtcoursier.CoursierPlugin
override val projectSettings = Seq( override val projectSettings = Seq(
updatePgpSignatures := { updatePgpSignatures := UpdateTasks.updateTask(withClassifiers = false, includeSignatures = true).value
UpdateTasks.updateTask(
None,
withClassifiers = false,
includeSignatures = true
).value
}
) )
} }