Vendor more stuff in lmcoursier, shade coursier in it

Along with shapeless, argonaut, argonaut-shapeless that coursier depends
on now.
This commit is contained in:
Alexandre Archambault 2019-04-24 18:20:32 +02:00
parent d6858b4857
commit 6bdd0f985a
57 changed files with 548 additions and 492 deletions

View File

@ -17,7 +17,6 @@ inThisBuild(List(
lazy val `lm-coursier` = project
.in(file("modules/lm-coursier"))
.enablePlugins(ContrabandPlugin)
.settings(
shared,
libraryDependencies ++= Seq(
@ -29,11 +28,28 @@ lazy val `lm-coursier` = project
// is ignored).
"org.scala-sbt" %% "librarymanagement-ivy" % "1.2.4",
"org.scalatest" %% "scalatest" % "3.0.7" % Test
)
)
lazy val `lm-coursier-shaded` = project
.in(file("modules/lm-coursier/target/shaded-module"))
.enablePlugins(ShadingPlugin)
.settings(
shared,
unmanagedSourceDirectories.in(Compile) := unmanagedSourceDirectories.in(Compile).in(`lm-coursier`).value,
shading,
shadingNamespace := "lmcoursier.internal.shaded",
shadeNamespaces ++= Set(
"coursier",
"shapeless",
"argonaut"
),
managedSourceDirectories in Compile +=
baseDirectory.value / "src" / "main" / "contraband-scala",
sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala",
contrabandFormatsForType in generateContrabands in Compile := DatatypeConfig.getFormats
libraryDependencies ++= Seq(
"io.get-coursier" %% "coursier" % "1.1.0-M14-1" % "shaded",
"org.scala-lang.modules" %% "scala-xml" % "1.1.1", // depending on that one so that it doesn't get shaded
"org.scala-sbt" %% "librarymanagement-ivy" % "1.2.4",
"org.scalatest" %% "scalatest" % "3.0.7" % Test
)
)
lazy val `sbt-coursier-shared` = project
@ -125,6 +141,7 @@ lazy val `sbt-coursier-root` = project
.in(file("."))
.aggregate(
`lm-coursier`,
`lm-coursier-shaded`,
`sbt-coursier`,
`sbt-coursier-shared`,
`sbt-lm-coursier`,

View File

@ -1,133 +0,0 @@
{
"codecNamespace": "coursier.lmcoursier",
"types": [
{
"name": "CoursierConfiguration",
"namespace": "coursier.lmcoursier",
"target": "Scala",
"type": "record",
"fields": [
{
"name": "log",
"type": "xsbti.Logger?",
"default": "None",
"since": "0.0.1"
},
{
"name": "resolvers",
"type": "sbt.librarymanagement.Resolver*",
"default": "sbt.librarymanagement.Resolver.defaults",
"since": "0.0.1"
},
{
"name": "parallelDownloads",
"type": "Int",
"default": "6",
"since": "0.0.1"
},
{
"name": "maxIterations",
"type": "Int",
"default": "100",
"since": "0.0.1"
},
{
"name": "sbtScalaOrganization",
"type": "String?",
"default": "None",
"since": "0.0.1"
},
{
"name": "sbtScalaVersion",
"type": "String?",
"default": "None",
"since": "0.0.1"
},
{
"name": "sbtScalaJars",
"type": "java.io.File*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "interProjectDependencies",
"type": "coursier.core.Project*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "excludeDependencies",
"type": "(String, String)*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "fallbackDependencies",
"type": "coursier.lmcoursier.FallbackDependency*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "autoScalaLibrary",
"type": "Boolean",
"default": "true",
"since": "0.0.1"
},
{
"name": "hasClassifiers",
"type": "Boolean",
"default": "false",
"since": "0.0.1"
},
{
"name": "classifiers",
"type": "String*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "mavenProfiles",
"type": "String*",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "scalaOrganization",
"type": "String?",
"default": "None",
"since": "0.0.1"
},
{
"name": "scalaVersion",
"type": "String?",
"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]",
"default": "Vector.empty",
"since": "0.0.1"
},
{
"name": "logger",
"type": "coursier.cache.CacheLogger?",
"default": "None",
"since": "0.0.1"
},
{
"name": "cache",
"type": "java.io.File?",
"default": "None",
"since": "0.0.1"
}
]
}
]
}

View File

@ -3,7 +3,7 @@
*/
// DO NOT EDIT MANUALLY
package coursier.lmcoursier
package lmcoursier
final class CoursierConfiguration private (
val log: Option[xsbti.Logger],
val resolvers: Vector[sbt.librarymanagement.Resolver],
@ -12,16 +12,16 @@ final class CoursierConfiguration private (
val sbtScalaOrganization: Option[String],
val sbtScalaVersion: Option[String],
val sbtScalaJars: Vector[java.io.File],
val interProjectDependencies: Vector[coursier.core.Project],
val interProjectDependencies: Vector[lmcoursier.definitions.Project],
val excludeDependencies: Vector[(String, String)],
val fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency],
val fallbackDependencies: Vector[lmcoursier.FallbackDependency],
val autoScalaLibrary: Boolean,
val hasClassifiers: Boolean,
val classifiers: Vector[String],
val mavenProfiles: Vector[String],
val scalaOrganization: Option[String],
val scalaVersion: Option[String],
val authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)],
val authenticationByRepositoryId: Vector[(String, lmcoursier.definitions.Authentication)],
val credentials: Seq[coursier.credentials.Credentials],
val logger: Option[coursier.cache.CacheLogger],
val cache: Option[java.io.File]) extends Serializable {
@ -33,12 +33,12 @@ final class CoursierConfiguration private (
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.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) + fallbackDependencies.##) + autoScalaLibrary.##) + hasClassifiers.##) + classifiers.##) + mavenProfiles.##) + scalaOrganization.##) + scalaVersion.##) + authenticationByRepositoryId.##) + credentials.##) + logger.##) + cache.##)
37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + 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 + ", " + 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, 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 = {
private[this] def copy(log: Option[xsbti.Logger] = log, resolvers: Vector[sbt.librarymanagement.Resolver] = resolvers, parallelDownloads: Int = parallelDownloads, maxIterations: Int = maxIterations, sbtScalaOrganization: Option[String] = sbtScalaOrganization, sbtScalaVersion: Option[String] = sbtScalaVersion, sbtScalaJars: Vector[java.io.File] = sbtScalaJars, interProjectDependencies: Vector[lmcoursier.definitions.Project] = interProjectDependencies, excludeDependencies: Vector[(String, String)] = excludeDependencies, fallbackDependencies: Vector[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, lmcoursier.definitions.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, 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 = {
@ -71,13 +71,13 @@ final class CoursierConfiguration private (
def withSbtScalaJars(sbtScalaJars: Vector[java.io.File]): CoursierConfiguration = {
copy(sbtScalaJars = sbtScalaJars)
}
def withInterProjectDependencies(interProjectDependencies: Vector[coursier.core.Project]): CoursierConfiguration = {
def withInterProjectDependencies(interProjectDependencies: Vector[lmcoursier.definitions.Project]): CoursierConfiguration = {
copy(interProjectDependencies = interProjectDependencies)
}
def withExcludeDependencies(excludeDependencies: Vector[(String, String)]): CoursierConfiguration = {
copy(excludeDependencies = excludeDependencies)
}
def withFallbackDependencies(fallbackDependencies: Vector[coursier.lmcoursier.FallbackDependency]): CoursierConfiguration = {
def withFallbackDependencies(fallbackDependencies: Vector[lmcoursier.FallbackDependency]): CoursierConfiguration = {
copy(fallbackDependencies = fallbackDependencies)
}
def withAutoScalaLibrary(autoScalaLibrary: Boolean): CoursierConfiguration = {
@ -104,7 +104,7 @@ final class CoursierConfiguration private (
def withScalaVersion(scalaVersion: String): CoursierConfiguration = {
copy(scalaVersion = Option(scalaVersion))
}
def withAuthenticationByRepositoryId(authenticationByRepositoryId: Vector[(String, coursier.core.Authentication)]): CoursierConfiguration = {
def withAuthenticationByRepositoryId(authenticationByRepositoryId: Vector[(String, lmcoursier.definitions.Authentication)]): CoursierConfiguration = {
copy(authenticationByRepositoryId = authenticationByRepositoryId)
}
def withCredentials(credentials: Seq[coursier.credentials.Credentials]): CoursierConfiguration = {
@ -126,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], 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, 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], 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, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, Option(scalaOrganization), Option(scalaVersion), authenticationByRepositoryId, credentials, Option(logger), Option(cache))
def apply(log: Option[xsbti.Logger], resolvers: Vector[sbt.librarymanagement.Resolver], parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: Option[String], sbtScalaVersion: Option[String], sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[lmcoursier.definitions.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: Option[String], scalaVersion: Option[String], authenticationByRepositoryId: Vector[(String, lmcoursier.definitions.Authentication)], credentials: Seq[coursier.credentials.Credentials], logger: Option[coursier.cache.CacheLogger], cache: Option[java.io.File]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, 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], parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: String, sbtScalaVersion: String, sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[lmcoursier.definitions.Project], excludeDependencies: Vector[(String, String)], fallbackDependencies: Vector[lmcoursier.FallbackDependency], autoScalaLibrary: Boolean, hasClassifiers: Boolean, classifiers: Vector[String], mavenProfiles: Vector[String], scalaOrganization: String, scalaVersion: String, authenticationByRepositoryId: Vector[(String, lmcoursier.definitions.Authentication)], credentials: Seq[coursier.credentials.Credentials], logger: coursier.cache.CacheLogger, cache: java.io.File): CoursierConfiguration = new CoursierConfiguration(Option(log), resolvers, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies, excludeDependencies, fallbackDependencies, autoScalaLibrary, hasClassifiers, classifiers, mavenProfiles, Option(scalaOrganization), Option(scalaVersion), authenticationByRepositoryId, credentials, Option(logger), Option(cache))
}

View File

@ -1,12 +1,13 @@
package coursier.lmcoursier
package lmcoursier
import java.io.File
import _root_.coursier.{Artifact, Organization, Resolution, organizationString}
import _root_.coursier.core.{Classifier, Configuration, ModuleName}
import _root_.coursier.core.{Classifier, Configuration}
import coursier.cache.CacheDefaults
import coursier.internal.Typelevel
import coursier.lmcoursier.internal.{ArtifactsParams, ArtifactsRun, CoursierModuleDescriptor, InterProjectRepository, ResolutionParams, ResolutionRun, SbtBootJars, UpdateParams, UpdateRun}
import lmcoursier.definitions.ToCoursier
import lmcoursier.internal.{ArtifactsParams, ArtifactsRun, CoursierModuleDescriptor, InterProjectRepository, ResolutionParams, ResolutionRun, Resolvers, SbtBootJars, UpdateParams, UpdateRun}
import sbt.internal.librarymanagement.IvySbt
import sbt.librarymanagement._
import sbt.util.Logger
@ -23,7 +24,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
.excludeDependencies
.map {
case (strOrg, strName) =>
(Organization(strOrg), ModuleName(strName))
(lmcoursier.definitions.Organization(strOrg), lmcoursier.definitions.ModuleName(strName))
}
.toSet
@ -86,15 +87,15 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
val mainRepositories = conf
.resolvers
.flatMap { resolver =>
FromSbt.repository(
Resolvers.repository(
resolver,
ivyProperties,
log,
authenticationByRepositoryId.get(resolver.name)
authenticationByRepositoryId.get(resolver.name).map(ToCoursier.authentication)
)
}
val interProjectRepo = InterProjectRepository(conf.interProjectDependencies)
val interProjectRepo = InterProjectRepository(conf.interProjectDependencies.map(ToCoursier.project))
val dependencies = module0
.dependencies
@ -108,12 +109,12 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
val dep0 = dep.copy(
exclusions = dep.exclusions ++ excludeDependencies
)
(config, dep0)
(ToCoursier.configuration(config), ToCoursier.dependency(dep0))
}
val configGraphs = Inputs.ivyGraphs(
Inputs.configExtends(module0.configurations)
)
).map(_.map(ToCoursier.configuration))
val typelevel = so == Typelevel.typelevelOrg
@ -131,7 +132,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
autoScalaLibOpt = if (conf.autoScalaLibrary) Some((so, sv)) else None,
mainRepositories = mainRepositories,
parentProjectCache = Map.empty,
interProjectDependencies = conf.interProjectDependencies,
interProjectDependencies = conf.interProjectDependencies.map(ToCoursier.project),
internalRepositories = Seq(interProjectRepo),
sbtClassifiers = false,
projectName = projectName,
@ -163,7 +164,10 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
conf.sbtScalaJars
)
val configs = Inputs.coursierConfigurations(module0.configurations)
val configs = Inputs.coursierConfigurations(module0.configurations).map {
case (k, l) =>
ToCoursier.configuration(k) -> l.map(ToCoursier.configuration)
}
def updateParams(
resolutions: Map[Set[Configuration], Resolution],

View File

@ -1,8 +1,8 @@
package coursier.lmcoursier
package lmcoursier
import java.net.URL
import coursier.core.Module
import lmcoursier.definitions.Module
// FIXME Handle that via the contraband thing?
final case class FallbackDependency(

View File

@ -0,0 +1,147 @@
package lmcoursier
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
import lmcoursier.definitions.{Attributes, Classifier, Configuration, Dependency, Info, Module, ModuleName, Organization, Project, Type}
import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties
import sbt.librarymanagement.{Configuration => _, MavenRepository => _, _}
object FromSbt {
private def sbtModuleIdName(
moduleId: ModuleID,
scalaVersion: => String,
scalaBinaryVersion: => String,
optionalCrossVer: Boolean = false
): String = {
val name0 = moduleId.name
val updatedName = CrossVersion(moduleId.crossVersion, scalaVersion, scalaBinaryVersion)
.fold(name0)(_(name0))
if (!optionalCrossVer || updatedName.length <= name0.length)
updatedName
else {
val suffix = updatedName.substring(name0.length)
if (name0.endsWith(suffix))
name0
else
updatedName
}
}
private def attributes(attr: Map[String, String]): Map[String, String] =
attr.map { case (k, v) =>
k.stripPrefix("e:") -> v
}.filter { case (k, _) =>
!k.startsWith(SbtPomExtraProperties.POM_INFO_KEY_PREFIX)
}
private def moduleVersion(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String,
optionalCrossVer: Boolean
): (Module, String) = {
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val module0 = Module(Organization(module.organization), ModuleName(fullName), attributes(module.extraDependencyAttributes))
val version = module.revision
(module0, version)
}
def moduleVersion(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String
): (Module, String) =
moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer = false)
def dependencies(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String,
optionalCrossVer: Boolean = false
): Seq[(Configuration, Dependency)] = {
// TODO Warn about unsupported properties in `module`
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val dep = Dependency(
module0,
version,
Configuration(""),
exclusions = module.exclusions.map { rule =>
// FIXME Other `rule` fields are ignored here
(Organization(rule.organization), ModuleName(rule.name))
}.toSet,
Attributes(Type(""), Classifier("")),
optional = false,
transitive = module.isTransitive
)
val mapping = module.configurations.getOrElse("compile")
// FIXME Don't call this from here
val allMappings = ivyXmlMappings(mapping).map {
case (from, to) =>
(Configuration(from.value), Configuration(to.value))
}
val attributes =
if (module.explicitArtifacts.isEmpty)
Seq(Attributes(Type(""), Classifier("")))
else
module.explicitArtifacts.map { a =>
Attributes(
`type` = Type(a.`type`),
classifier = a.classifier.fold(Classifier(""))(Classifier(_))
)
}
for {
(from, to) <- allMappings
attr <- attributes
} yield from -> dep.copy(configuration = to, attributes = attr)
}
def fallbackDependencies(
allDependencies: Seq[ModuleID],
scalaVersion: String,
scalaBinaryVersion: String
): Seq[FallbackDependency] =
for {
module <- allDependencies
artifact <- module.explicitArtifacts
url <- artifact.url.toSeq
} yield {
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion)
FallbackDependency(module0, version, url, module.isChanging)
}
def project(
projectID: ModuleID,
allDependencies: Seq[ModuleID],
ivyConfigurations: Map[Configuration, Seq[Configuration]],
scalaVersion: String,
scalaBinaryVersion: String
): Project = {
val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion))
Project(
Module(
Organization(projectID.organization),
ModuleName(sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion)),
attributes(projectID.extraDependencyAttributes)
),
projectID.revision,
deps,
ivyConfigurations,
Nil,
None,
Nil,
Info("", "", Nil, Nil, None)
)
}
}

View File

@ -1,6 +1,6 @@
package coursier.lmcoursier
package lmcoursier
import coursier.core.{Configuration, ModuleName, Organization}
import lmcoursier.definitions.{Configuration, ModuleName, Organization}
import sbt.librarymanagement.{CrossVersion, InclExclRule}
import sbt.util.Logger

View File

@ -0,0 +1,6 @@
package lmcoursier.definitions
final case class Attributes(
`type`: Type,
classifier: Classifier
)

View File

@ -0,0 +1,11 @@
package lmcoursier.definitions
final case class Authentication(
user: String,
password: String,
optional: Boolean = false,
realmOpt: Option[String] = None
) {
override def toString: String =
s"Authentication($user, *******, $optional, $realmOpt)"
}

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class Classifier(value: String) extends AnyVal

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class Configuration(value: String) extends AnyVal

View File

@ -0,0 +1,14 @@
package lmcoursier.definitions
final case class Dependency(
module: Module,
version: String,
configuration: Configuration,
exclusions: Set[(Organization, ModuleName)],
// Maven-specific
attributes: Attributes,
optional: Boolean,
transitive: Boolean
)

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class Extension(value: String) extends AnyVal

View File

@ -0,0 +1,26 @@
package lmcoursier.definitions
final case class Info(
description: String,
homePage: String,
licenses: Seq[(String, Option[String])],
developers: Seq[Info.Developer],
publication: Option[Info.DateTime]
)
object Info {
final case class Developer(
id: String,
name: String,
url: String
)
final case class DateTime(
year: Int,
month: Int,
day: Int,
hour: Int,
minute: Int,
second: Int
)
}

View File

@ -0,0 +1,7 @@
package lmcoursier.definitions
final case class Module(
organization: Organization,
name: ModuleName,
attributes: Map[String, String]
)

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class ModuleName(value: String) extends AnyVal

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class Organization(value: String) extends AnyVal

View File

@ -0,0 +1,12 @@
package lmcoursier.definitions
final case class Project(
module: Module,
version: String,
dependencies: Seq[(Configuration, Dependency)],
configurations: Map[Configuration, Seq[Configuration]],
properties: Seq[(String, String)],
packagingOpt: Option[Type],
publications: Seq[(Configuration, Publication)],
info: Info
)

View File

@ -0,0 +1,8 @@
package lmcoursier.definitions
final case class Publication(
name: String,
`type`: Type,
ext: Extension,
classifier: Classifier
)

View File

@ -0,0 +1,102 @@
package lmcoursier.definitions
// TODO Make private[lmcoursier]
// private[coursier]
object ToCoursier {
def configuration(configuration: Configuration): coursier.core.Configuration =
coursier.core.Configuration(configuration.value)
private def attributes(attributes: Attributes): coursier.core.Attributes =
coursier.core.Attributes(
coursier.core.Type(attributes.`type`.value),
coursier.core.Classifier(attributes.classifier.value)
)
def publication(publication: Publication): coursier.core.Publication =
coursier.core.Publication(
publication.name,
coursier.core.Type(publication.`type`.value),
coursier.core.Extension(publication.ext.value),
coursier.core.Classifier(publication.classifier.value)
)
def authentication(authentication: Authentication): coursier.core.Authentication =
coursier.core.Authentication(
authentication.user,
authentication.password,
authentication.optional,
authentication.realmOpt
)
def module(module: Module): coursier.core.Module =
coursier.core.Module(
coursier.core.Organization(module.organization.value),
coursier.core.ModuleName(module.name.value),
module.attributes
)
def dependency(dependency: Dependency): coursier.core.Dependency =
coursier.core.Dependency(
module(dependency.module),
dependency.version,
configuration(dependency.configuration),
dependency.exclusions.map {
case (org, name) =>
(coursier.core.Organization(org.value), coursier.core.ModuleName(name.value))
},
attributes(dependency.attributes),
dependency.optional,
dependency.transitive
)
def project(project: Project): coursier.core.Project =
coursier.core.Project(
module(project.module),
project.version,
project.dependencies.map {
case (conf, dep) =>
configuration(conf) -> dependency(dep)
},
project.configurations.map {
case (k, l) =>
configuration(k) -> l.map(configuration)
},
None,
Nil,
project.properties,
Nil,
None,
None,
project.packagingOpt.map(t => coursier.core.Type(t.value)),
relocated = false,
None,
project.publications.map {
case (conf, pub) =>
configuration(conf) -> publication(pub)
},
coursier.core.Info(
project.info.description,
project.info.homePage,
project.info.licenses,
project.info.developers.map { dev =>
coursier.core.Info.Developer(
dev.id,
dev.name,
dev.url
)
},
project.info.publication.map { dt =>
coursier.core.Versions.DateTime(
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second
)
}
)
)
}

View File

@ -0,0 +1,3 @@
package lmcoursier.definitions
final case class Type(value: String) extends AnyVal

View File

@ -1,10 +1,11 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import coursier.cache.{CacheLogger, FileCache}
import coursier.core.{Classifier, Resolution}
import coursier.util.Task
private[coursier] final case class ArtifactsParams(
// private[coursier]
final case class ArtifactsParams(
classifiers: Option[Seq[Classifier]],
resolutions: Seq[Resolution],
includeSignatures: Boolean,

View File

@ -1,14 +1,15 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.io.File
import coursier.Artifact
import coursier.cache.internal.ThreadUtil
import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay, RefreshLogger}
import coursier.core.Type
import coursier.util.Sync
import sbt.util.Logger
private[coursier] object ArtifactsRun {
// private[coursier]
object ArtifactsRun {
def artifacts(
params: ArtifactsParams,
@ -28,7 +29,7 @@ private[coursier] object ArtifactsRun {
else
""
Sync.withFixedThreadPool(params.parallel) { pool =>
ThreadUtil.withFixedThreadPool(params.parallel) { pool =>
coursier.Artifacts()
.withResolutions(params.resolutions)

View File

@ -1,6 +1,6 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import coursier.lmcoursier.CoursierConfiguration
import lmcoursier.CoursierConfiguration
import sbt.librarymanagement._
private[lmcoursier] final case class CoursierModuleDescriptor(

View File

@ -1,4 +1,4 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import sbt.librarymanagement.ModuleSettings

View File

@ -1,9 +1,10 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import coursier.core._
import coursier.util.{EitherT, Monad}
private[coursier] final case class InterProjectRepository(projects: Seq[Project]) extends Repository {
// private[coursier]
final case class InterProjectRepository(projects: Seq[Project]) extends Repository {
private val map = projects
.map(proj => proj.moduleVersion -> proj)

View File

@ -1,4 +1,4 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
private[lmcoursier] object Lock {

View File

@ -1,14 +1,16 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.io.File
import coursier.cache.{CacheLogger, FileCache}
import coursier.ProjectCache
import coursier.core._
import coursier.lmcoursier.FallbackDependency
import lmcoursier.FallbackDependency
import lmcoursier.definitions.ToCoursier
import coursier.util.{InMemoryRepository, Task}
private[coursier] final case class ResolutionParams(
// private[coursier]
final case class ResolutionParams(
dependencies: Seq[(Configuration, Dependency)],
fallbackDependencies: Seq[FallbackDependency],
configGraphs: Seq[Set[Configuration]],
@ -31,7 +33,7 @@ private[coursier] final case class ResolutionParams(
else {
val map = fallbackDependencies.map {
case FallbackDependency(mod, ver, url, changing) =>
(mod, ver) -> ((url, changing))
(ToCoursier.module(mod), ver) -> ((url, changing))
}.toMap
Seq(
@ -67,7 +69,8 @@ private[coursier] final case class ResolutionParams(
}
private[coursier] object ResolutionParams {
// private[coursier]
object ResolutionParams {
private lazy val m = {
val cls = classOf[FileCache[Task]]

View File

@ -1,14 +1,15 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import coursier.cache.internal.ThreadUtil
import coursier.{Resolution, Resolve}
import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay, RefreshLogger}
import coursier.core._
import coursier.ivy.IvyRepository
import coursier.maven.MavenRepository
import coursier.util.Sync
import sbt.util.Logger
private[coursier] object ResolutionRun {
// private[coursier]
object ResolutionRun {
private def resolution(
params: ResolutionParams,
@ -63,7 +64,7 @@ private[coursier] object ResolutionRun {
if (verbosityLevel >= 2)
log.info(initialMessage)
Sync.withFixedThreadPool(params.parallel) { pool =>
ThreadUtil.withFixedThreadPool(params.parallel) { pool =>
Resolve()
.withDependencies(

View File

@ -1,156 +1,18 @@
package coursier.lmcoursier
package lmcoursier.internal
import coursier.ivy.IvyRepository
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
import java.net.MalformedURLException
import coursier.cache.CacheUrl
import coursier.{Attributes, Dependency, Module}
import coursier.core._
import coursier.core.{Authentication, Repository}
import coursier.maven.MavenRepository
import org.apache.ivy.plugins.resolver.IBiblioResolver
import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties
import sbt.librarymanagement.{Configuration => _, MavenRepository => _, _}
import sbt.util.Logger
import scala.collection.JavaConverters._
object FromSbt {
private def sbtModuleIdName(
moduleId: ModuleID,
scalaVersion: => String,
scalaBinaryVersion: => String,
optionalCrossVer: Boolean = false
): String = {
val name0 = moduleId.name
val updatedName = CrossVersion(moduleId.crossVersion, scalaVersion, scalaBinaryVersion)
.fold(name0)(_(name0))
if (!optionalCrossVer || updatedName.length <= name0.length)
updatedName
else {
val suffix = updatedName.substring(name0.length)
if (name0.endsWith(suffix))
name0
else
updatedName
}
}
private def attributes(attr: Map[String, String]): Map[String, String] =
attr.map { case (k, v) =>
k.stripPrefix("e:") -> v
}.filter { case (k, _) =>
!k.startsWith(SbtPomExtraProperties.POM_INFO_KEY_PREFIX)
}
private def moduleVersion(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String,
optionalCrossVer: Boolean
): (Module, String) = {
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val module0 = Module(Organization(module.organization), ModuleName(fullName), attributes(module.extraDependencyAttributes))
val version = module.revision
(module0, version)
}
def moduleVersion(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String
): (Module, String) =
moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer = false)
def dependencies(
module: ModuleID,
scalaVersion: String,
scalaBinaryVersion: String,
optionalCrossVer: Boolean = false
): Seq[(Configuration, Dependency)] = {
// TODO Warn about unsupported properties in `module`
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer)
val dep = Dependency(
module0,
version,
exclusions = module.exclusions.map { rule =>
// FIXME Other `rule` fields are ignored here
(Organization(rule.organization), ModuleName(rule.name))
}.toSet,
transitive = module.isTransitive
)
val mapping = module.configurations.getOrElse("compile")
val allMappings = ivyXmlMappings(mapping)
val attributes =
if (module.explicitArtifacts.isEmpty)
Seq(Attributes(Type.empty, Classifier.empty))
else
module.explicitArtifacts.map { a =>
Attributes(
`type` = Type(a.`type`),
classifier = a.classifier.fold(Classifier.empty)(Classifier(_))
)
}
for {
(from, to) <- allMappings
attr <- attributes
} yield from -> dep.copy(configuration = to, attributes = attr)
}
def fallbackDependencies(
allDependencies: Seq[ModuleID],
scalaVersion: String,
scalaBinaryVersion: String
): Seq[FallbackDependency] =
for {
module <- allDependencies
artifact <- module.explicitArtifacts
url <- artifact.url.toSeq
} yield {
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion)
FallbackDependency(module0, version, url, module.isChanging)
}
def project(
projectID: ModuleID,
allDependencies: Seq[ModuleID],
ivyConfigurations: Map[Configuration, Seq[Configuration]],
scalaVersion: String,
scalaBinaryVersion: String
): Project = {
val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion))
Project(
Module(
Organization(projectID.organization),
ModuleName(sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion)),
attributes(projectID.extraDependencyAttributes)
),
projectID.revision,
deps,
ivyConfigurations,
None,
Nil,
Nil,
Nil,
None,
None,
None,
relocated = false,
None,
Nil,
Info.empty
)
}
object Resolvers {
private def mavenCompatibleBaseOpt(patterns: Patterns): Option[String] =
if (patterns.isMavenCompatible) {

View File

@ -1,10 +1,11 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.io.File
import coursier.core.{Module, ModuleName, Organization}
private[coursier] object SbtBootJars {
// private[coursier]
object SbtBootJars {
def apply(
scalaOrg: Organization,
scalaVersion: String,

View File

@ -1,11 +1,12 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.util.concurrent.ConcurrentHashMap
import coursier.core._
import sbt.librarymanagement.UpdateReport
private[coursier] class SbtCoursierCache {
// private[coursier]
class SbtCoursierCache {
import SbtCoursierCache._
@ -35,7 +36,8 @@ private[coursier] class SbtCoursierCache {
}
private[coursier] object SbtCoursierCache {
// private[coursier]
object SbtCoursierCache {
final case class ResolutionKey(
dependencies: Seq[(Configuration, Dependency)],
@ -53,6 +55,7 @@ private[coursier] object SbtCoursierCache {
)
private[coursier] val default = new SbtCoursierCache
// private[coursier]
val default = new SbtCoursierCache
}

View File

@ -1,4 +1,4 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.io.File
import java.net.URL

View File

@ -1,10 +1,11 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import java.io.File
import coursier.core._
private[coursier] final case class UpdateParams(
// private[coursier]
final case class UpdateParams(
shadedConfigOpt: Option[(String, Configuration)],
artifacts: Map[Artifact, File],
classifiers: Option[Seq[Classifier]],

View File

@ -1,4 +1,4 @@
package coursier.lmcoursier.internal
package lmcoursier.internal
import coursier.core.Resolution.ModuleVersion
import coursier.core._
@ -6,7 +6,8 @@ import coursier.util.Print
import sbt.librarymanagement.UpdateReport
import sbt.util.Logger
private[coursier] object UpdateRun {
// private[coursier]
object UpdateRun {
// Move back to coursier.util (in core module) after 1.0?
private def allDependenciesByConfig(

View File

@ -1,4 +1,4 @@
package coursier.lmcoursier
package lmcoursier
import org.scalatest.{Matchers, PropSpec}
import sbt.internal.librarymanagement.cross.CrossVersionUtil

View File

@ -3,7 +3,7 @@ package coursier
import java.io.{File, FileInputStream}
import java.util.Properties
import coursier.core.Authentication
import lmcoursier.definitions.Authentication
@deprecated("Use coursierExtraCredentials rather than coursierCredentials", "1.1.0-M14")
sealed abstract class Credentials extends Product with Serializable {

View File

@ -1,12 +1,12 @@
package coursier.sbtcoursiershared
import coursier.core.{Classifier, Configuration, Extension, Publication, Type}
import lmcoursier.definitions.{Classifier, Configuration, Extension, Publication, Type}
import coursier.sbtcoursiershared.Structure._
import sbt.librarymanagement.{Artifact => _, Configuration => _, _}
import sbt.Def
import sbt.Keys._
object ArtifactsTasks {
private[sbtcoursiershared] object ArtifactsTasks {
def coursierPublicationsTask(
configsMap: (sbt.librarymanagement.Configuration, Configuration)*
@ -103,7 +103,7 @@ object ArtifactsTasks {
name,
Type(artifact.`type`),
Extension(artifact.extension),
artifact.classifier.fold(Classifier.empty)(Classifier(_))
artifact.classifier.fold(Classifier(""))(Classifier(_))
)
}

View File

@ -1,8 +1,8 @@
package coursier.sbtcoursiershared
import coursier.core.{Attributes, Classifier, Configuration, Dependency, Info, Module, ModuleName, Organization, Project, Type}
import coursier.credentials.DirectCredentials
import coursier.lmcoursier.{FallbackDependency, FromSbt, Inputs}
import lmcoursier.definitions.{Attributes, Classifier, Configuration, Dependency, Info, Module, ModuleName, Organization, Project, Type}
import lmcoursier.{FallbackDependency, FromSbt, Inputs}
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
import coursier.sbtcoursiershared.Structure._
import sbt.Def
@ -44,7 +44,7 @@ object InputsTasks {
)
}
def coursierProjectTask: Def.Initialize[sbt.Task[Project]] =
private[sbtcoursiershared] def coursierProjectTask: Def.Initialize[sbt.Task[Project]] =
Def.taskDyn {
val state = sbt.Keys.state.value
@ -95,7 +95,13 @@ object InputsTasks {
val configurations = desc
.getModuleConfigurations
.toVector
.flatMap(s => coursier.ivy.IvyXml.mappings(s))
.flatMap { s =>
// FIXME Don't call this from here
coursier.ivy.IvyXml.mappings(s).map {
case (from, to) =>
(Configuration(from.value), Configuration(to.value))
}
}
def dependency(conf: Configuration, attr: Attributes) = Dependency(
module,
@ -112,13 +118,13 @@ object InputsTasks {
val artifacts = desc.getAllDependencyArtifacts
val m = artifacts.toVector.flatMap { art =>
val attr = Attributes(Type(art.getType), Classifier.empty)
val attr = Attributes(Type(art.getType), Classifier(""))
art.getConfigurations.map(Configuration(_)).toVector.map { conf =>
conf -> attr
}
}.toMap
c => m.getOrElse(c, Attributes.empty)
c => m.getOrElse(c, Attributes(Type(""), Classifier("")))
}
configurations.map {
@ -127,7 +133,7 @@ object InputsTasks {
}
}
def coursierInterProjectDependenciesTask: Def.Initialize[sbt.Task[Seq[Project]]] =
private[sbtcoursiershared] def coursierInterProjectDependenciesTask: Def.Initialize[sbt.Task[Seq[Project]]] =
Def.taskDyn {
val state = sbt.Keys.state.value
@ -173,17 +179,10 @@ object InputsTasks {
v.getModuleRevisionId.getRevision,
deps,
configurations,
None,
Nil,
Nil,
Nil,
None,
None,
None,
relocated = false,
None,
Nil,
Info.empty
Info("", "", Nil, Nil, None)
)
}
@ -191,7 +190,7 @@ object InputsTasks {
}
}
def coursierFallbackDependenciesTask: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
private[sbtcoursiershared] def coursierFallbackDependenciesTask: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
Def.taskDyn {
val state = sbt.Keys.state.value

View File

@ -3,7 +3,7 @@ package coursier.sbtcoursiershared
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.Files
import coursier.core.{Configuration, Project}
import lmcoursier.definitions.{Configuration, Project}
import org.apache.ivy.core.module.id.ModuleRevisionId
import sbt.{Def, Setting, Task, TaskKey}
import sbt.internal.librarymanagement.IvySbt
@ -14,7 +14,7 @@ import scala.xml.{Node, PrefixedAttribute}
object IvyXml {
def rawContent(
private[sbtcoursiershared] def rawContent(
currentProject: Project,
shadedConfigOpt: Option[Configuration]
): String = {
@ -32,7 +32,7 @@ object IvyXml {
}
// These are required for publish to be fine, later on.
def writeFiles(
private def writeFiles(
currentProject: Project,
shadedConfigOpt: Option[Configuration],
ivySbt: IvySbt,
@ -63,13 +63,13 @@ object IvyXml {
Files.write(cacheIvyPropertiesFile.toPath, Array.emptyByteArray)
}
def content(project0: Project, shadedConfigOpt: Option[Configuration]): Node = {
private def content(project0: Project, shadedConfigOpt: Option[Configuration]): Node = {
val filterOutDependencies =
shadedConfigOpt.toSet[Configuration].flatMap { shadedConfig =>
project0
.dependencies
.collect { case (`shadedConfig`, dep) => dep }
.collect { case (conf, dep) if conf.value == shadedConfig.value => dep }
}
val project: Project = project0.copy(
@ -104,8 +104,8 @@ object IvyXml {
} % infoAttrs
val confElems = project.configurations.toVector.collect {
case (name, extends0) if !shadedConfigOpt.contains(name) =>
val extends1 = shadedConfigOpt.fold(extends0)(c => extends0.filter(_ != c))
case (name, extends0) if !shadedConfigOpt.exists(_.value == name.value) =>
val extends1 = shadedConfigOpt.fold(extends0)(c => extends0.filter(_.value != c.value))
val n = <conf name={name.value} visibility="public" description="" />
if (extends1.nonEmpty)
n % <x extends={extends1.map(_.value).mkString(",")} />.attributes
@ -122,7 +122,7 @@ object IvyXml {
case (pub, configs) =>
val n = <artifact name={pub.name} type={pub.`type`.value} ext={pub.ext.value} conf={configs.map(_.value).mkString(",")} />
if (pub.classifier.nonEmpty)
if (pub.classifier.value.nonEmpty)
n % <x e:classifier={pub.classifier.value} />.attributes
else
n
@ -155,7 +155,7 @@ object IvyXml {
</ivy-module>
}
def makeIvyXmlBefore[T](
private def makeIvyXmlBefore[T](
task: TaskKey[T],
shadedConfigOpt: Option[Configuration]
): Setting[Task[T]] =
@ -170,7 +170,7 @@ object IvyXml {
val publications = coursierPublications.value
proj.copy(publications = publications)
}
IvyXml.writeFiles(currentProject, shadedConfigOpt, sbt.Keys.ivySbt.value, sbt.Keys.streams.value.log)
writeFiles(currentProject, shadedConfigOpt, sbt.Keys.ivySbt.value, sbt.Keys.streams.value.log)
}
else
Def.task(())
@ -194,6 +194,6 @@ object IvyXml {
def generateIvyXmlSettings(
shadedConfigOpt: Option[Configuration] = None
): Seq[Setting[_]] =
(needsIvyXml ++ needsIvyXmlLocal).map(IvyXml.makeIvyXmlBefore(_, shadedConfigOpt))
(needsIvyXml ++ needsIvyXmlLocal).map(makeIvyXmlBefore(_, shadedConfigOpt))
}

View File

@ -6,7 +6,7 @@ import sbt.{Classpaths, Def}
import sbt.Keys._
import sbt.librarymanagement.{Resolver, URLRepository}
object RepositoriesTasks {
private[sbtcoursiershared] object RepositoriesTasks {
private object Resolvers {

View File

@ -4,10 +4,10 @@ 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
import coursier.lmcoursier.internal.SbtCoursierCache
import lmcoursier.FallbackDependency
import lmcoursier.definitions.{Configuration, Project, Publication}
import lmcoursier.internal.SbtCoursierCache
import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey}
import sbt.Keys._
import sbt.librarymanagement.{Resolver, URLRepository}

View File

@ -1,7 +1,6 @@
package coursier.sbtcoursiershared
import coursier.core.Configuration
import coursier.{Info, Module, Project, moduleNameString, organizationString}
import lmcoursier.definitions.{Configuration, Info, Module, ModuleName, Organization, Project}
import utest._
object IvyXmlTests extends TestSuite {
@ -10,23 +9,16 @@ object IvyXmlTests extends TestSuite {
"no truncation" - {
val project = Project(
Module(org"org", name"name"),
Module(Organization("org"), ModuleName("name"), Map()),
"ver",
Nil,
Map(
Configuration("foo") -> (1 to 80).map(n => Configuration("bar" + n)) // long list of configurations -> no truncation any way
),
None,
Nil,
Nil,
Nil,
None,
None,
None,
relocated = false,
None,
Nil,
Info.empty
Info("", "", Nil, Nil, None)
)
val content = IvyXml.rawContent(project, None)

View File

@ -5,8 +5,7 @@ import java.io.File
import coursier.Artifact
import coursier.cache.FileCache
import coursier.core._
import coursier.lmcoursier._
import coursier.lmcoursier.internal.{ArtifactsParams, ArtifactsRun}
import lmcoursier.internal.{ArtifactsParams, ArtifactsRun}
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport.{coursierCache, coursierLogger}

View File

@ -1,6 +1,6 @@
package coursier.sbtcoursier
import coursier.cache.{CacheDefaults, CachePolicy}
import coursier.cache.CacheDefaults
import coursier.core.{Configuration, ResolutionProcess}
import coursier.sbtcoursiershared.SbtCoursierShared
import sbt.{Cache => _, Configuration => _, _}

View File

@ -1,6 +1,7 @@
package coursier.sbtcoursier
import coursier.core._
import lmcoursier.definitions.ToCoursier
import coursier.parse.ModuleParser
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
@ -39,14 +40,14 @@ object DisplayTasks {
Def.task {
val currentProject = currentProjectTask.value
val classifiersRes = coursierSbtClassifiersResolution.value
Map(currentProject.configurations.keySet -> classifiersRes)
Map(currentProject.configurations.keySet.map(ToCoursier.configuration) -> classifiersRes)
}
else
Def.task(coursierResolutions.value)
Def.task {
val currentProject = currentProjectTask.value
val currentProject = ToCoursier.project(currentProjectTask.value)
val config = Configuration(configuration.value.name)
val configs = coursierConfigurations.value

View File

@ -2,7 +2,8 @@ package coursier.sbtcoursier
import coursier.ProjectCache
import coursier.core._
import coursier.lmcoursier._
import lmcoursier._
import lmcoursier.definitions.ToCoursier
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
import coursier.sbtcoursiershared.Structure._
@ -16,13 +17,19 @@ object InputsTasks {
shadedConfig: Option[(String, Configuration)]
): Def.Initialize[sbt.Task[Map[Configuration, Set[Configuration]]]] =
Def.task {
Inputs.coursierConfigurations(ivyConfigurations.value, shadedConfig)
Inputs.coursierConfigurations(ivyConfigurations.value, shadedConfig.map {
case (from, to) =>
(from, lmcoursier.definitions.Configuration(to.value))
}).map {
case (k, v) =>
ToCoursier.configuration(k) -> v.map(ToCoursier.configuration)
}
}
def ivyGraphsTask: Def.Initialize[sbt.Task[Seq[Set[Configuration]]]] =
Def.task {
val p = coursierProject.value
Inputs.ivyGraphs(p.configurations)
Inputs.ivyGraphs(p.configurations).map(_.map(ToCoursier.configuration))
}
def parentProjectCacheTask: Def.Initialize[sbt.Task[Map[Seq[sbt.librarymanagement.Resolver], Seq[coursier.ProjectCache]]]] =

View File

@ -4,8 +4,9 @@ import coursier.ProjectCache
import coursier.cache.FileCache
import coursier.core._
import coursier.internal.Typelevel
import coursier.lmcoursier.{FallbackDependency, FromSbt}
import coursier.lmcoursier.internal.{InterProjectRepository, ResolutionParams, ResolutionRun}
import lmcoursier.definitions.ToCoursier
import lmcoursier.{FallbackDependency, FromSbt}
import lmcoursier.internal.{InterProjectRepository, ResolutionParams, ResolutionRun, Resolvers}
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
@ -24,7 +25,7 @@ object ResolutionTasks {
val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value
val cm = coursierSbtClassifiersModule.value
val proj = SbtCoursierFromSbt.sbtClassifiersProject(cm, sv, sbv)
val proj = ToCoursier.project(SbtCoursierFromSbt.sbtClassifiersProject(cm, sv, sbv))
val fallbackDeps = FromSbt.fallbackDependencies(
cm.dependencies,
@ -37,7 +38,8 @@ object ResolutionTasks {
else
Def.task {
val baseConfigGraphs = coursierConfigGraphs.value
(coursierProject.value.copy(publications = coursierPublications.value), coursierFallbackDependencies.value, baseConfigGraphs)
val publications = coursierPublications.value
(ToCoursier.project(coursierProject.value.copy(publications = publications)), coursierFallbackDependencies.value, baseConfigGraphs)
}
val resolversTask =
@ -52,7 +54,7 @@ object ResolutionTasks {
val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value
val interProjectDependencies = coursierInterProjectDependencies.value
val interProjectDependencies = coursierInterProjectDependencies.value.map(ToCoursier.project)
val parallelDownloads = coursierParallelDownloads.value
val checksums = coursierChecksums.value
@ -70,6 +72,10 @@ object ResolutionTasks {
val userForceVersions = dependencyOverrides
.value
.map(FromSbt.moduleVersion(_, sv, sbv))
.map {
case (k, v) =>
ToCoursier.module(k) -> v
}
.toMap
val verbosityLevel = coursierVerbosity.value
@ -101,11 +107,18 @@ object ResolutionTasks {
val mainRepositories = resolvers
.flatMap { resolver =>
FromSbt.repository(
Resolvers.repository(
resolver,
ivyProperties,
log,
authenticationByRepositoryId.get(resolver.name)
authenticationByRepositoryId.get(resolver.name).map { a =>
Authentication(
a.user,
a.password,
a.optional,
a.realmOpt
)
}
)
}

View File

@ -1,7 +1,7 @@
package coursier.sbtcoursier
import coursier.core.Configuration
import coursier.lmcoursier.FromSbt
import lmcoursier.FromSbt
import lmcoursier.definitions.Configuration
import sbt.librarymanagement.GetClassifiersModule
object SbtCoursierFromSbt {

View File

@ -1,7 +1,8 @@
package coursier.sbtcoursier
import coursier.core._
import coursier.lmcoursier.internal.{SbtBootJars, SbtCoursierCache, UpdateParams, UpdateRun}
import lmcoursier.definitions.ToCoursier
import lmcoursier.internal.{SbtBootJars, SbtCoursierCache, UpdateParams, UpdateRun}
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
import sbt.Def
@ -28,7 +29,6 @@ object UpdateTasks {
Def.task {
val proj = coursierProject.value
val publications = coursierPublications.value
proj.copy(publications = publications)
}
@ -103,7 +103,7 @@ object UpdateTasks {
val verbosityLevel = coursierVerbosity.value
val dependencies = currentProjectTask.value.dependencies
val dependencies = ToCoursier.project(currentProjectTask.value).dependencies
val res = resTask.value
val key = SbtCoursierCache.ReportKey(

View File

@ -3,6 +3,6 @@ package coursier
object Helper {
def checkEmpty(): Boolean =
coursier.lmcoursier.internal.SbtCoursierCache.default.isEmpty
lmcoursier.internal.SbtCoursierCache.default.isEmpty
}

View File

@ -23,9 +23,9 @@ check := {
// Have Coursier SBT Plugin Parse the SBT Resolvers
val parsedCoursierResolvers: Seq[coursier.core.Repository] =
sbtResolvers.flatMap{ sbtResolver: sbt.librarymanagement.Resolver =>
coursier.lmcoursier.FromSbt.repository(
lmcoursier.internal.Resolvers.repository(
resolver = sbtResolver,
ivyProperties = coursier.lmcoursier.internal.ResolutionParams.defaultIvyProperties(),
ivyProperties = lmcoursier.internal.ResolutionParams.defaultIvyProperties(),
log = s.log,
authentication = None,
)

View File

@ -1,6 +1,7 @@
package coursier.sbtlmcoursier
import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs}
import lmcoursier.definitions.Authentication
import lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs}
import coursier.sbtcoursiershared.InputsTasks.credentialsTask
import coursier.sbtcoursiershared.SbtCoursierShared
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
@ -86,7 +87,10 @@ object LmCoursierPlugin extends AutoPlugin {
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
val profiles = mavenProfiles.value
val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication)
val authenticationByRepositoryId = coursierCredentials.value.mapValues { c =>
val a = c.authentication
Authentication(a.user, a.password, a.optional, a.realmOpt)
}
val credentials = credentialsTask.value
val createLogger = coursierLogger.value
@ -107,11 +111,11 @@ object LmCoursierPlugin extends AutoPlugin {
.withExcludeDependencies(
excludeDeps
.toVector
.sorted
.map {
case (o, n) =>
(o.value, n.value)
}
.sorted
)
.withAutoScalaLibrary(autoScalaLib)
.withSbtScalaJars(sbtBootJars.toVector)

View File

@ -4,6 +4,7 @@ import java.io.File
import coursier.core.Configuration
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
import lmcoursier.definitions.{ToCoursier, Configuration => DConfiguration}
import coursier.sbtcoursier.{CoursierPlugin, InputsTasks, Keys}
import coursier.sbtcoursiershared.{IvyXml, SbtCoursierShared}
import sbt.Keys._
@ -25,7 +26,7 @@ object ShadingPlugin extends AutoPlugin {
transitive = true
)
private val baseDependencyConfiguration = Configuration.compile
private val baseDependencyConfiguration = Configuration("compile")
val Shaded = sbt.Configuration.of(
id = "Shaded",
name = "shaded",
@ -101,8 +102,8 @@ object ShadingPlugin extends AutoPlugin {
CoursierPlugin.coursierSettings(
Some(baseDependencyConfiguration.value -> Configuration(Shaded.name))
) ++
IvyXml.generateIvyXmlSettings(Some(Configuration(Shaded.name))) ++
Seq(SbtCoursierShared.publicationsSetting(Seq(Shading -> Configuration.compile))) ++
IvyXml.generateIvyXmlSettings(Some(lmcoursier.definitions.Configuration(Shaded.name))) ++
Seq(SbtCoursierShared.publicationsSetting(Seq(Shading -> DConfiguration("compile")))) ++
CoursierPlugin.treeSettings ++
Seq(
configuration := baseSbtConfiguration, // wuw
@ -120,7 +121,7 @@ object ShadingPlugin extends AutoPlugin {
unmanagedSourceDirectories := (unmanagedSourceDirectories in Compile).value,
toShadeJars := {
coursier.Shading.toShadeJars(
coursierProject.in(baseSbtConfiguration).value,
ToCoursier.project(coursierProject.in(baseSbtConfiguration).value),
coursierResolutions
.in(baseSbtConfiguration)
.value

View File

@ -1,75 +0,0 @@
// from https://github.com/sbt/librarymanagement/blob/4a0a6c77bc24f9db139698cab0a6da78d0893a88/project/DatatypeConfig.scala
import sbt.contraband.ast._
import sbt.contraband.CodecCodeGen
object DatatypeConfig {
/** Extract the only type parameter from a TpeRef */
def oneArg(tpe: Type): Type = {
val pat = s"""${tpe.removeTypeParameters.name}[<\\[](.+?)[>\\]]""".r
val pat(arg0) = tpe.name
NamedType(arg0 split '.' toList)
}
/** Extract the two type parameters from a TpeRef */
def twoArgs(tpe: Type): List[Type] = {
val pat = s"""${tpe.removeTypeParameters.name}[<\\[](.+?), (.+?)[>\\]]""".r
val pat(arg0, arg1) = tpe.name
NamedType(arg0 split '.' toList) :: NamedType(arg1 split '.' toList) :: Nil
}
/** Codecs that were manually written. */
val myCodecs: PartialFunction[String, Type => List[String]] = {
case "scala.xml.NodeSeq" => { _ =>
"sbt.internal.librarymanagement.formats.NodeSeqFormat" :: Nil
}
case "org.apache.ivy.plugins.resolver.DependencyResolver" => { _ =>
"sbt.internal.librarymanagement.formats.DependencyResolverFormat" :: Nil
}
case "xsbti.GlobalLock" => { _ =>
"sbt.internal.librarymanagement.formats.GlobalLockFormat" :: Nil
}
case "xsbti.Logger" => { _ =>
"sbt.internal.librarymanagement.formats.LoggerFormat" :: Nil
}
case "sbt.librarymanagement.ivy.UpdateOptions" => { _ =>
"sbt.librarymanagement.ivy.formats.UpdateOptionsFormat" :: Nil
}
case "sbt.librarymanagement.LogicalClock" => { _ =>
"sbt.internal.librarymanagement.formats.LogicalClockFormats" :: Nil
}
// TODO: These are handled by BasicJsonProtocol, and sbt-datatype should handle them by default, imo
case "Option" | "Set" | "scala.Vector" => { tpe =>
getFormats(oneArg(tpe))
}
case "Map" | "Tuple2" | "scala.Tuple2" => { tpe =>
twoArgs(tpe).flatMap(getFormats)
}
case "Int" | "Long" => { _ =>
Nil
}
}
/** Types for which we don't include the format -- they're just aliases to InclExclRule */
val excluded = Set("sbt.librarymanagement.InclusionRule", "sbt.librarymanagement.ExclusionRule")
/** Returns the list of formats required to encode the given `TpeRef`. */
val getFormats: Type => List[String] =
CodecCodeGen.extensibleFormatsForType {
case NamedType(List("sbt", "internal", "librarymanagement", "RetrieveConfiguration"), _) =>
"sbt.librarymanagement.RetrieveConfigurationFormats" :: Nil
case tpe: Type if myCodecs isDefinedAt tpe.removeTypeParameters.name =>
myCodecs(tpe.removeTypeParameters.name)(tpe)
case tpe: Type if excluded contains tpe.removeTypeParameters.name =>
Nil
case other =>
CodecCodeGen.formatsForType(other)
}
}

View File

@ -1,7 +1,6 @@
plugins_(
"com.geirsson" % "sbt-ci-release" % "1.2.1",
"org.scala-sbt" % "sbt-contraband" % "0.4.3",
"io.get-coursier" % "sbt-coursier" % sbtCoursierVersion,
"com.typesafe" % "sbt-mima-plugin" % "0.3.0",
"com.jsuereth" % "sbt-pgp" % "1.1.2",

View File

@ -14,8 +14,10 @@ sbtShading() {
}
runLmCoursierTests() {
# publishing locally to ensure shading runs fine
./metadata/scripts/with-test-repo.sh sbt \
++$TRAVIS_SCALA_VERSION \
lm-coursier-shaded/publishLocal \
lm-coursier/test \
"sbt-lm-coursier/scripted shared-$TEST_GROUP/*"
}