mirror of https://github.com/sbt/sbt.git
Replace most of SbtCompatibility with sbt-compat (#731)
This commit is contained in:
parent
39c7708297
commit
1bb7742d71
13
build.sbt
13
build.sbt
|
|
@ -235,7 +235,18 @@ lazy val `sbt-shared` = project
|
|||
.disablePlugins(ScriptedPlugin)
|
||||
.settings(
|
||||
plugin,
|
||||
utest
|
||||
utest,
|
||||
// addSbtPlugin("com.dwijnand" % "sbt-compat" % "1.2.0")
|
||||
libs ++= {
|
||||
val dependency = "com.dwijnand" % "sbt-compat" % "1.2.0"
|
||||
val sbtV = (sbtBinaryVersion in pluginCrossBuild).value
|
||||
val scalaV = (scalaBinaryVersion in update).value
|
||||
val m = Defaults.sbtPluginExtra(dependency, sbtV, scalaV)
|
||||
CrossVersion.partialVersion(scalaVersion.value).collect {
|
||||
case (2, 10) => m
|
||||
case (2, 12) => m
|
||||
}.toList
|
||||
}
|
||||
)
|
||||
|
||||
lazy val `sbt-coursier` = project
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package coursier
|
||||
|
||||
import sbt._
|
||||
import sbt.librarymanagement._
|
||||
import sbt.{ Configuration, Resolver, _ }
|
||||
import sbt.Keys._
|
||||
|
||||
import SbtCompatibility._
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import org.apache.ivy.core.module.id.ModuleRevisionId
|
|||
import scala.collection.JavaConverters._
|
||||
import scala.xml.{Node, PrefixedAttribute}
|
||||
|
||||
import SbtCompatibility._
|
||||
import sbt.internal.librarymanagement.IvySbt
|
||||
|
||||
object IvyXml {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@ import java.io.File
|
|||
import java.net.URL
|
||||
|
||||
import coursier.core.Publication
|
||||
import sbt.librarymanagement.GetClassifiersModule
|
||||
import sbt.{Resolver, SettingKey, TaskKey}
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
import scalaz.\/
|
||||
|
||||
import SbtCompatibility._
|
||||
|
||||
object Keys {
|
||||
val coursierParallelDownloads = SettingKey[Int]("coursier-parallel-downloads")
|
||||
val coursierMaxIterations = SettingKey[Int]("coursier-max-iterations")
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import coursier.ivy.{IvyRepository, PropertiesPattern}
|
|||
import coursier.Keys._
|
||||
import coursier.Structure._
|
||||
import coursier.util.Print
|
||||
import coursier.SbtCompatibility._
|
||||
import sbt.librarymanagement._
|
||||
import sbt.{Classpaths, Def, Resolver, UpdateReport}
|
||||
import sbt.Keys._
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ object Tasks {
|
|||
|
||||
def url(res: Resolver): Option[String] =
|
||||
res match {
|
||||
case m: SbtCompatibility.MavenRepository =>
|
||||
case m: sbt.librarymanagement.MavenRepository =>
|
||||
Some(m.root)
|
||||
case u: sbt.URLRepository =>
|
||||
u.patterns.artifactPatterns.headOption
|
||||
|
|
@ -351,11 +351,11 @@ object Tasks {
|
|||
// it puts it in all of them. See for example what happens to
|
||||
// the standalone JAR artifact of the coursier cli module.
|
||||
def allConfigsIfEmpty(configs: Iterable[ConfigRef]): Iterable[ConfigRef] =
|
||||
if (configs.isEmpty) ivyConfs.filter(_.isPublic).map(_.toConfigRef) else configs
|
||||
if (configs.isEmpty) ivyConfs.filter(_.isPublic).map(c => ConfigRef(c.name)) else configs
|
||||
|
||||
val extraSbtArtifactsPublication = for {
|
||||
artifact <- extraSbtArtifacts
|
||||
config <- allConfigsIfEmpty(artifact.configurations.map(x => x: ConfigRef))
|
||||
config <- allConfigsIfEmpty(artifact.configurations.map(x => ConfigRef(x.name)))
|
||||
// FIXME If some configurations from artifact.configurations are not public, they may leak here :\
|
||||
} yield config.name -> artifactPublication(artifact)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ package coursier
|
|||
import java.io.File
|
||||
|
||||
import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
|
||||
import sbt.librarymanagement._
|
||||
import sbt.Keys._
|
||||
import sbt.{AutoPlugin, Compile, Configuration, SettingKey, TaskKey, inConfig}
|
||||
|
||||
import SbtCompatibility._
|
||||
|
||||
object ShadingPlugin extends AutoPlugin {
|
||||
|
||||
override def trigger = noTrigger
|
||||
|
|
@ -104,7 +103,7 @@ object ShadingPlugin extends AutoPlugin {
|
|||
configuration := baseSbtConfiguration, // wuw
|
||||
ivyConfigurations := ivyConfigurations.in(baseSbtConfiguration).value
|
||||
.filter(_.name != Shaded.name)
|
||||
.map(c => c.withExtendsConfigs(c.extendsConfigs.filter(_.name != Shaded.name))),
|
||||
.map(c => c.withExtendsConfigs(c.extendsConfigs.toVector.filter(_.name != Shaded.name))),
|
||||
libraryDependencies := libraryDependencies.in(baseSbtConfiguration).value.filter { dep =>
|
||||
val isShaded = dep.configurations.exists { mappings =>
|
||||
ivyXmlMappings(mappings).exists(_._1 == Shaded.name)
|
||||
|
|
@ -156,4 +155,4 @@ object ShadingPlugin extends AutoPlugin {
|
|||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,147 +1,6 @@
|
|||
package coursier
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
object SbtCompatibility {
|
||||
|
||||
final case class ConfigRef(name: String) extends AnyVal
|
||||
implicit def configRefToString(ref: ConfigRef): String = ref.name
|
||||
|
||||
val GetClassifiersModule = sbt.GetClassifiersModule
|
||||
type GetClassifiersModule = sbt.GetClassifiersModule
|
||||
|
||||
object SbtPomExtraProperties {
|
||||
def POM_INFO_KEY_PREFIX = sbt.mavenint.SbtPomExtraProperties.POM_INFO_KEY_PREFIX
|
||||
}
|
||||
|
||||
type MavenRepository = sbt.MavenRepository
|
||||
|
||||
type IvySbt = sbt.IvySbt
|
||||
|
||||
implicit class ModuleIDOps(val id: sbt.ModuleID) extends AnyVal {
|
||||
def withConfigurations(configurations: Option[String]): sbt.ModuleID =
|
||||
id.copy(configurations = configurations)
|
||||
def withExtraAttributes(extraAttributes: Map[String, String]): sbt.ModuleID =
|
||||
id.copy(extraAttributes = extraAttributes)
|
||||
def withExclusions(exclusions: Seq[sbt.librarymanagement.InclExclRule]): sbt.ModuleID =
|
||||
exclusions.foldLeft(id)((id0, rule) => id0.exclude(rule.org, rule.name))
|
||||
def withIsTransitive(isTransitive: Boolean): sbt.ModuleID =
|
||||
id.copy(isTransitive = isTransitive)
|
||||
}
|
||||
|
||||
implicit class ArtifactOps(val artifact: sbt.Artifact) extends AnyVal {
|
||||
def withType(`type`: String): sbt.Artifact =
|
||||
artifact.copy(`type` = `type`)
|
||||
def withExtension(extension: String): sbt.Artifact =
|
||||
artifact.copy(extension = extension)
|
||||
def withClassifier(classifier: Option[String]): sbt.Artifact =
|
||||
artifact.copy(classifier = classifier)
|
||||
def withUrl(url: Option[sbt.URL]): sbt.Artifact =
|
||||
artifact.copy(url = url)
|
||||
def withExtraAttributes(extraAttributes: Map[String, String]): sbt.Artifact =
|
||||
artifact.copy(extraAttributes = extraAttributes)
|
||||
}
|
||||
|
||||
implicit def toModuleReportOps(report: sbt.ModuleReport): sbt.ModuleReportOps =
|
||||
new sbt.ModuleReportOps(report)
|
||||
|
||||
implicit class ConfigurationOps(val config: sbt.Configuration) extends AnyVal {
|
||||
def withExtendsConfigs(extendsConfigs: Vector[sbt.Configuration]): sbt.Configuration =
|
||||
config.copy(extendsConfigs = extendsConfigs.toList)
|
||||
def toConfigRef: ConfigRef =
|
||||
ConfigRef(config.name)
|
||||
}
|
||||
|
||||
implicit def configurationToConfigRef(config: sbt.Configuration): ConfigRef =
|
||||
config.toConfigRef
|
||||
|
||||
implicit class ConfigurationCompanionOps(val companion: sbt.Configuration.type) extends AnyVal {
|
||||
def of(
|
||||
id: String,
|
||||
name: String,
|
||||
description: String,
|
||||
isPublic: Boolean,
|
||||
extendsConfigs: Vector[sbt.Configuration],
|
||||
transitive: Boolean
|
||||
): sbt.Configuration =
|
||||
sbt.Configuration(name, description, isPublic, extendsConfigs.toList, transitive)
|
||||
}
|
||||
|
||||
implicit class CallerCompanionOps(val companion: sbt.Caller.type) extends AnyVal {
|
||||
def apply(
|
||||
caller: sbt.ModuleID,
|
||||
callerConfigurations: Vector[ConfigRef],
|
||||
callerExtraAttributes: Map[String, String],
|
||||
isForceDependency: Boolean,
|
||||
isChangingDependency: Boolean,
|
||||
isTransitiveDependency: Boolean,
|
||||
isDirectlyForceDependency: Boolean
|
||||
): sbt.Caller =
|
||||
new sbt.Caller(
|
||||
caller,
|
||||
callerConfigurations.map(_.name),
|
||||
callerExtraAttributes,
|
||||
isForceDependency,
|
||||
isChangingDependency,
|
||||
isTransitiveDependency,
|
||||
isDirectlyForceDependency
|
||||
)
|
||||
}
|
||||
|
||||
implicit class ConfigurationReportCompanionOps(val companion: sbt.ConfigurationReport.type) extends AnyVal {
|
||||
def apply(
|
||||
configuration: String,
|
||||
modules: Seq[sbt.ModuleReport],
|
||||
details: Seq[sbt.OrganizationArtifactReport]
|
||||
): sbt.ConfigurationReport =
|
||||
new sbt.ConfigurationReport(
|
||||
configuration,
|
||||
modules,
|
||||
details,
|
||||
Nil
|
||||
)
|
||||
}
|
||||
|
||||
implicit class UpdateReportCompanionOps(val companion: sbt.UpdateReport.type) extends AnyVal {
|
||||
def apply(
|
||||
cachedDescriptor: java.io.File,
|
||||
configurations: Seq[sbt.ConfigurationReport],
|
||||
stats: sbt.UpdateStats,
|
||||
stamps: Map[java.io.File, Long]
|
||||
): sbt.UpdateReport =
|
||||
new sbt.UpdateReport(
|
||||
cachedDescriptor,
|
||||
configurations,
|
||||
stats,
|
||||
stamps
|
||||
)
|
||||
}
|
||||
|
||||
implicit class UpdateStatsCompanionOps(val companion: sbt.UpdateStats.type) extends AnyVal {
|
||||
def apply(
|
||||
resolveTime: Long,
|
||||
downloadTime: Long,
|
||||
downloadSize: Long,
|
||||
cached: Boolean
|
||||
): sbt.UpdateStats =
|
||||
new sbt.UpdateStats(
|
||||
resolveTime,
|
||||
downloadTime,
|
||||
downloadSize,
|
||||
cached
|
||||
)
|
||||
}
|
||||
|
||||
implicit def configVectorToList(configs: Vector[sbt.Configuration]): List[sbt.Configuration] =
|
||||
configs.toList
|
||||
implicit def configListToVector(configs: List[sbt.Configuration]): Vector[sbt.Configuration] =
|
||||
configs.toVector
|
||||
|
||||
implicit class GetClassifiersModuleOps(val module: GetClassifiersModule) extends AnyVal {
|
||||
def dependencies = module.modules
|
||||
}
|
||||
|
||||
def needsIvyXmlLocal = List(sbt.Keys.deliverLocalConfiguration)
|
||||
def needsIvyXml = List(sbt.Keys.deliverConfiguration)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
package sbt
|
||||
|
||||
// put under the sbt namespace to access private[sbt] things (the copy method used below)
|
||||
|
||||
class ModuleReportOps(val report: sbt.ModuleReport) extends AnyVal {
|
||||
def withPublicationDate(publicationDate: Option[java.util.Calendar]): sbt.ModuleReport =
|
||||
report.copy(publicationDate = publicationDate.map(_.getTime))
|
||||
def withHomepage(homepage: Option[String]): sbt.ModuleReport =
|
||||
report.copy(homepage = homepage)
|
||||
def withExtraAttributes(extraAttributes: Map[String, String]): sbt.ModuleReport =
|
||||
report.copy(extraAttributes = extraAttributes)
|
||||
def withConfigurations(configurations: Vector[coursier.SbtCompatibility.ConfigRef]): sbt.ModuleReport =
|
||||
report.copy(configurations = configurations.map(_.name))
|
||||
def withLicenses(licenses: Vector[(String, Option[String])]): sbt.ModuleReport =
|
||||
report.copy(licenses = licenses)
|
||||
def withCallers(callers: Vector[sbt.Caller]): sbt.ModuleReport =
|
||||
report.copy(callers = callers)
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package sbt.librarymanagement
|
||||
|
||||
final case class InclExclRule(org: String = "*", name: String = "*") {
|
||||
def withOrganization(org: String): InclExclRule =
|
||||
copy(org = org)
|
||||
def withName(name: String): InclExclRule =
|
||||
copy(name = name)
|
||||
}
|
||||
|
|
@ -1,43 +1,19 @@
|
|||
package coursier
|
||||
|
||||
import sbt._, Keys._
|
||||
|
||||
object SbtCompatibility {
|
||||
lazy val needsIvyXmlLocal = Seq(publishLocalConfiguration) ++ getPubConf("makeIvyXmlLocalConfiguration")
|
||||
lazy val needsIvyXml = Seq(publishConfiguration) ++ getPubConf("makeIvyXmlConfiguration")
|
||||
|
||||
val ConfigRef = sbt.librarymanagement.ConfigRef
|
||||
type ConfigRef = sbt.librarymanagement.ConfigRef
|
||||
|
||||
val GetClassifiersModule = sbt.librarymanagement.GetClassifiersModule
|
||||
type GetClassifiersModule = sbt.librarymanagement.GetClassifiersModule
|
||||
|
||||
object SbtPomExtraProperties {
|
||||
def POM_INFO_KEY_PREFIX = sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties.POM_INFO_KEY_PREFIX
|
||||
}
|
||||
|
||||
type MavenRepository = sbt.librarymanagement.MavenRepository
|
||||
|
||||
type IvySbt = sbt.internal.librarymanagement.IvySbt
|
||||
|
||||
lazy val needsIvyXmlLocal = Seq(sbt.Keys.publishLocalConfiguration) ++ {
|
||||
private[this] def getPubConf(method: String) =
|
||||
try {
|
||||
val cls = sbt.Keys.getClass
|
||||
val m = cls.getMethod("makeIvyXmlLocalConfiguration")
|
||||
val task = m.invoke(sbt.Keys).asInstanceOf[sbt.TaskKey[sbt.PublishConfiguration]]
|
||||
val cls = Keys.getClass
|
||||
val m = cls.getMethod(method)
|
||||
val task = m.invoke(Keys).asInstanceOf[TaskKey[PublishConfiguration]]
|
||||
List(task)
|
||||
} catch {
|
||||
case _: Throwable => // FIXME Too wide
|
||||
Nil
|
||||
}
|
||||
}
|
||||
|
||||
lazy val needsIvyXml = Seq(sbt.Keys.publishConfiguration) ++ {
|
||||
try {
|
||||
val cls = sbt.Keys.getClass
|
||||
val m = cls.getMethod("makeIvyXmlConfiguration")
|
||||
val task = m.invoke(sbt.Keys).asInstanceOf[sbt.TaskKey[sbt.PublishConfiguration]]
|
||||
List(task)
|
||||
} catch {
|
||||
case _: Throwable => // FIXME Too wide
|
||||
Nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import coursier.ivy.IvyXml.{mappings => ivyXmlMappings}
|
|||
import java.net.{MalformedURLException, URL}
|
||||
|
||||
import coursier.core.Authentication
|
||||
import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties
|
||||
import sbt.librarymanagement._
|
||||
import sbt.{CrossVersion, ModuleID, Resolver}
|
||||
|
||||
import scalaz.{-\/, \/-}
|
||||
|
||||
import SbtCompatibility._
|
||||
|
||||
object FromSbt {
|
||||
|
||||
def sbtModuleIdName(
|
||||
|
|
@ -206,7 +206,7 @@ object FromSbt {
|
|||
authentication: Option[Authentication]
|
||||
): Option[Repository] =
|
||||
resolver match {
|
||||
case r: SbtCompatibility.MavenRepository =>
|
||||
case r: sbt.librarymanagement.MavenRepository =>
|
||||
mavenRepositoryOpt(r.root, log, authentication)
|
||||
|
||||
case r: sbt.FileRepository
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import java.io.File
|
|||
import java.util.GregorianCalendar
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
import sbt.librarymanagement._
|
||||
import coursier.maven.MavenSource
|
||||
import SbtCompatibility._
|
||||
|
||||
object ToSbt {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue