mirror of https://github.com/sbt/sbt.git
Use dataclass-scalafix for code gen
This is a prepration step for Scala 3 support. Instead of data-class, this uses https://github.com/hamnis/dataclass-scalafix. Since it cannot use `withX` method in the data class itself with this approach, I created `syntax` package object to extend some methods to the generated classes.
This commit is contained in:
parent
65e506280f
commit
58912ff8f6
64
build.sbt
64
build.sbt
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
import Settings._
|
||||
|
||||
def dataclassScalafixV = "0.1.0-M3"
|
||||
|
||||
inThisBuild(List(
|
||||
organization := "io.get-coursier",
|
||||
homepage := Some(url("https://github.com/coursier/sbt-coursier")),
|
||||
|
|
@ -12,13 +14,51 @@ inThisBuild(List(
|
|||
"",
|
||||
url("https://github.com/alexarchambault")
|
||||
)
|
||||
)
|
||||
),
|
||||
semanticdbEnabled := true,
|
||||
semanticdbVersion := "4.5.9",
|
||||
scalafixDependencies += "net.hamnaberg" %% "dataclass-scalafix" % dataclassScalafixV
|
||||
))
|
||||
|
||||
val coursierVersion0 = "2.1.0-M5"
|
||||
val lmVersion = "1.3.4"
|
||||
val lm2_13Version = "1.5.0-M3"
|
||||
|
||||
def dataclassGen(data: Reference) = Def.taskDyn {
|
||||
val root = (ThisBuild / baseDirectory).value.toURI.toString
|
||||
val from = (data / Compile / sourceDirectory).value
|
||||
val to = (Compile / sourceManaged).value
|
||||
val outFrom = from.toURI.toString.stripSuffix("/").stripPrefix(root)
|
||||
val outTo = to.toURI.toString.stripSuffix("/").stripPrefix(root)
|
||||
(data / Compile / compile).value
|
||||
Def.task {
|
||||
(data / Compile / scalafix)
|
||||
.toTask(s" --rules GenerateDataClass --out-from=$outFrom --out-to=$outTo")
|
||||
.value
|
||||
(to ** "*.scala").get
|
||||
}
|
||||
}
|
||||
|
||||
def lmIvy = Def.setting {
|
||||
"org.scala-sbt" %% "librarymanagement-ivy" % {
|
||||
if (scalaBinaryVersion.value == "2.12") lmVersion
|
||||
else lm2_13Version
|
||||
}
|
||||
}
|
||||
|
||||
lazy val definitions = project
|
||||
.in(file("modules/definitions"))
|
||||
.disablePlugins(MimaPlugin)
|
||||
.settings(
|
||||
crossScalaVersions := Seq(scala212, scala213),
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"net.hamnaberg" %% "dataclass-annotation" % dataclassScalafixV % Provided,
|
||||
lmIvy.value,
|
||||
),
|
||||
dontPublish,
|
||||
)
|
||||
|
||||
lazy val `lm-coursier` = project
|
||||
.in(file("modules/lm-coursier"))
|
||||
.settings(
|
||||
|
|
@ -28,16 +68,14 @@ lazy val `lm-coursier` = project
|
|||
Mima.lmCoursierFilters,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"io.github.alexarchambault" %% "data-class" % "0.2.5" % Provided,
|
||||
"net.hamnaberg" %% "dataclass-annotation" % dataclassScalafixV % Provided,
|
||||
|
||||
// We depend on librarymanagement-ivy rather than just
|
||||
// librarymanagement-core to handle the ModuleDescriptor passed
|
||||
// to DependencyResolutionInterface.update, which is an
|
||||
// IvySbt#Module (seems DependencyResolutionInterface.moduleDescriptor
|
||||
// is ignored).
|
||||
"org.scala-sbt" %% "librarymanagement-ivy" % {
|
||||
if (scalaBinaryVersion.value == "2.12") lmVersion
|
||||
else lm2_13Version
|
||||
},
|
||||
lmIvy.value,
|
||||
"org.scalatest" %% "scalatest" % "3.2.13" % Test
|
||||
),
|
||||
Test / test := {
|
||||
|
|
@ -51,7 +89,8 @@ lazy val `lm-coursier` = project
|
|||
(publishLocal in customProtocolForTest213).value
|
||||
(publishLocal in customProtocolJavaForTest).value
|
||||
(Test / testOnly).evaluated
|
||||
}
|
||||
},
|
||||
Compile / sourceGenerators += dataclassGen(definitions).taskValue,
|
||||
)
|
||||
|
||||
lazy val `lm-coursier-shaded` = project
|
||||
|
|
@ -63,7 +102,7 @@ lazy val `lm-coursier-shaded` = project
|
|||
Mima.settings,
|
||||
Mima.lmCoursierFilters,
|
||||
Mima.lmCoursierShadedFilters,
|
||||
unmanagedSourceDirectories.in(Compile) := unmanagedSourceDirectories.in(Compile).in(`lm-coursier`).value,
|
||||
Compile / sources := (`lm-coursier` / Compile / sources).value,
|
||||
shadedModules += "io.get-coursier" %% "coursier",
|
||||
validNamespaces += "lmcoursier",
|
||||
validEntries ++= Set(
|
||||
|
|
@ -98,13 +137,10 @@ lazy val `lm-coursier-shaded` = project
|
|||
},
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"io.github.alexarchambault" %% "data-class" % "0.2.5" % Provided,
|
||||
"net.hamnaberg" %% "dataclass-annotation" % dataclassScalafixV % Provided,
|
||||
"org.scala-lang.modules" %% "scala-collection-compat" % "2.8.1",
|
||||
"org.scala-lang.modules" %% "scala-xml" % "2.1.0", // depending on that one so that it doesn't get shaded
|
||||
"org.scala-sbt" %% "librarymanagement-ivy" % {
|
||||
if (scalaBinaryVersion.value == "2.12") lmVersion
|
||||
else lm2_13Version
|
||||
},
|
||||
// "org.scala-lang.modules" %% "scala-xml" % "2.1.0", // depending on that one so that it doesn't get shaded
|
||||
lmIvy.value,
|
||||
"org.scalatest" %% "scalatest" % "3.2.13" % Test
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package lmcoursier
|
||||
|
||||
import java.io.File
|
||||
|
||||
import dataclass.data
|
||||
import dataclass.since
|
||||
import coursier.cache.CacheDefaults
|
||||
import lmcoursier.credentials.Credentials
|
||||
import lmcoursier.definitions.{Authentication, CacheLogger, CachePolicy, FromCoursier, Module, ModuleMatchers, Project, Reconciliation, Strict}
|
||||
import sbt.librarymanagement.{Resolver, UpdateConfiguration, ModuleID, CrossVersion, ModuleInfo, ModuleDescriptorConfiguration}
|
||||
import xsbti.Logger
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
|
||||
@data class CoursierConfiguration(
|
||||
log: Option[Logger] = None,
|
||||
resolvers: Vector[Resolver] = Resolver.defaults,
|
||||
parallelDownloads: Int = 6,
|
||||
maxIterations: Int = 100,
|
||||
sbtScalaOrganization: Option[String] = None,
|
||||
sbtScalaVersion: Option[String] = None,
|
||||
sbtScalaJars: Vector[File] = Vector.empty,
|
||||
interProjectDependencies: Vector[Project] = Vector.empty,
|
||||
excludeDependencies: Vector[(String, String)] = Vector.empty,
|
||||
fallbackDependencies: Vector[FallbackDependency] = Vector.empty,
|
||||
autoScalaLibrary: Boolean = true,
|
||||
hasClassifiers: Boolean = false,
|
||||
classifiers: Vector[String] = Vector.empty,
|
||||
mavenProfiles: Vector[String] = Vector.empty,
|
||||
scalaOrganization: Option[String] = None,
|
||||
scalaVersion: Option[String] = None,
|
||||
authenticationByRepositoryId: Vector[(String, Authentication)] = Vector.empty,
|
||||
credentials: Seq[Credentials] = Vector.empty,
|
||||
logger: Option[CacheLogger] = None,
|
||||
cache: Option[File] = None,
|
||||
@since
|
||||
ivyHome: Option[File] = None,
|
||||
@since
|
||||
followHttpToHttpsRedirections: Option[Boolean] = None,
|
||||
@since
|
||||
strict: Option[Strict] = None,
|
||||
extraProjects: Vector[Project] = Vector.empty,
|
||||
forceVersions: Vector[(Module, String)] = Vector.empty,
|
||||
@since
|
||||
reconciliation: Vector[(ModuleMatchers, Reconciliation)] = Vector.empty,
|
||||
@since
|
||||
classpathOrder: Boolean = true,
|
||||
@since
|
||||
verbosityLevel: Int = 0,
|
||||
ttl: Option[Duration] = CacheDefaults.ttl,
|
||||
checksums: Vector[Option[String]] = CacheDefaults.checksums.toVector,
|
||||
cachePolicies: Vector[CachePolicy] = CacheDefaults.cachePolicies.toVector.map(FromCoursier.cachePolicy),
|
||||
@since
|
||||
missingOk: Boolean = false,
|
||||
@since
|
||||
sbtClassifiers: Boolean = false,
|
||||
@since
|
||||
providedInCompile: Boolean = false, // unused, kept for binary compatibility
|
||||
@since
|
||||
protocolHandlerDependencies: Seq[ModuleID] = Vector.empty,
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/credentials/Credentials.scala
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package lmcoursier.credentials
|
||||
|
||||
import dataclass._
|
||||
|
||||
@data class DirectCredentials(
|
||||
host: String = "",
|
||||
username: String = "",
|
||||
password: String = "",
|
||||
@since("1.0")
|
||||
realm: Option[String] = None,
|
||||
@since("1.1")
|
||||
optional: Boolean = true,
|
||||
@since("1.1")
|
||||
matchHost: Boolean = false,
|
||||
@since("1.2")
|
||||
httpsOnly: Boolean = true
|
||||
) extends Credentials {
|
||||
override def toString(): String = s"DirectCredentials(host=$host, username=$username)"
|
||||
}
|
||||
|
|
@ -13,18 +13,5 @@ import dataclass._
|
|||
passOnRedirect: Boolean = false
|
||||
) {
|
||||
override def toString(): String =
|
||||
withPassword("****")
|
||||
.withHeaders(
|
||||
headers.map {
|
||||
case (k, v) => (k, "****")
|
||||
}
|
||||
)
|
||||
.productIterator
|
||||
.mkString("Authentication(", ", ", ")")
|
||||
}
|
||||
|
||||
object Authentication {
|
||||
|
||||
def apply(headers: Seq[(String, String)]): Authentication =
|
||||
Authentication("", "").withHeaders(headers)
|
||||
s"Authentication(user=$user)"
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/definitions/CacheLogger.scala
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/definitions/CachePolicy.scala
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/definitions/Definitions.scala
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
@data class Dependency(
|
||||
module: Module,
|
||||
version: String,
|
||||
configuration: Configuration,
|
||||
exclusions: Set[(Organization, ModuleName)],
|
||||
publication: Publication,
|
||||
optional: Boolean,
|
||||
transitive: Boolean
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/definitions/FromCoursier.scala
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
/**
|
||||
* @param exclude Use "*" in either organization or name to match any.
|
||||
* @param include Use "*" in either organization or name to match any.
|
||||
*/
|
||||
@data class ModuleMatchers(
|
||||
exclude: Set[Module],
|
||||
include: Set[Module],
|
||||
includeByDefault: Boolean = true
|
||||
)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
@data class Publication(
|
||||
name: String,
|
||||
`type`: Type,
|
||||
ext: Extension,
|
||||
classifier: Classifier
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/definitions/Reconciliation.scala
|
||||
|
|
@ -9,9 +9,4 @@ import dataclass._
|
|||
@since
|
||||
includeByDefault: Boolean = false,
|
||||
semVer: Boolean = false
|
||||
) {
|
||||
def addInclude(include: (String, String)*): Strict =
|
||||
withInclude(this.include ++ include)
|
||||
def addExclude(exclude: (String, String)*): Strict =
|
||||
withExclude(this.exclude ++ exclude)
|
||||
}
|
||||
)
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
package lmcoursier
|
||||
|
||||
import java.io.File
|
||||
|
||||
import dataclass.data
|
||||
import coursier.cache.CacheDefaults
|
||||
import lmcoursier.credentials.Credentials
|
||||
import lmcoursier.definitions.{Authentication, CacheLogger, CachePolicy, FromCoursier, Module, ModuleMatchers, Project, Reconciliation, Strict}
|
||||
import sbt.librarymanagement.{Resolver, UpdateConfiguration, ModuleID, CrossVersion, ModuleInfo, ModuleDescriptorConfiguration}
|
||||
import xsbti.Logger
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
|
||||
@data class CoursierConfiguration(
|
||||
log: Option[Logger] = None,
|
||||
resolvers: Vector[Resolver] = Resolver.defaults,
|
||||
parallelDownloads: Int = 6,
|
||||
maxIterations: Int = 100,
|
||||
sbtScalaOrganization: Option[String] = None,
|
||||
sbtScalaVersion: Option[String] = None,
|
||||
sbtScalaJars: Vector[File] = Vector.empty,
|
||||
interProjectDependencies: Vector[Project] = Vector.empty,
|
||||
excludeDependencies: Vector[(String, String)] = Vector.empty,
|
||||
fallbackDependencies: Vector[FallbackDependency] = Vector.empty,
|
||||
autoScalaLibrary: Boolean = true,
|
||||
hasClassifiers: Boolean = false,
|
||||
classifiers: Vector[String] = Vector.empty,
|
||||
mavenProfiles: Vector[String] = Vector.empty,
|
||||
scalaOrganization: Option[String] = None,
|
||||
scalaVersion: Option[String] = None,
|
||||
authenticationByRepositoryId: Vector[(String, Authentication)] = Vector.empty,
|
||||
credentials: Seq[Credentials] = Vector.empty,
|
||||
logger: Option[CacheLogger] = None,
|
||||
cache: Option[File] = None,
|
||||
@since
|
||||
ivyHome: Option[File] = None,
|
||||
@since
|
||||
followHttpToHttpsRedirections: Option[Boolean] = None,
|
||||
@since
|
||||
strict: Option[Strict] = None,
|
||||
extraProjects: Vector[Project] = Vector.empty,
|
||||
forceVersions: Vector[(Module, String)] = Vector.empty,
|
||||
@since
|
||||
reconciliation: Vector[(ModuleMatchers, Reconciliation)] = Vector.empty,
|
||||
@since
|
||||
classpathOrder: Boolean = true,
|
||||
@since
|
||||
verbosityLevel: Int = 0,
|
||||
ttl: Option[Duration] = CacheDefaults.ttl,
|
||||
checksums: Vector[Option[String]] = CacheDefaults.checksums.toVector,
|
||||
cachePolicies: Vector[CachePolicy] = CacheDefaults.cachePolicies.toVector.map(FromCoursier.cachePolicy),
|
||||
@since
|
||||
missingOk: Boolean = false,
|
||||
@since
|
||||
sbtClassifiers: Boolean = false,
|
||||
@since
|
||||
providedInCompile: Boolean = false, // unused, kept for binary compatibility
|
||||
@since
|
||||
protocolHandlerDependencies: Seq[ModuleID] = Vector.empty,
|
||||
) {
|
||||
|
||||
def withLog(log: Logger): CoursierConfiguration =
|
||||
withLog(Option(log))
|
||||
def withSbtScalaOrganization(sbtScalaOrganization: String): CoursierConfiguration =
|
||||
withSbtScalaOrganization(Option(sbtScalaOrganization))
|
||||
def withSbtScalaVersion(sbtScalaVersion: String): CoursierConfiguration =
|
||||
withSbtScalaVersion(Option(sbtScalaVersion))
|
||||
def withScalaOrganization(scalaOrganization: String): CoursierConfiguration =
|
||||
withScalaOrganization(Option(scalaOrganization))
|
||||
def withScalaVersion(scalaVersion: String): CoursierConfiguration =
|
||||
withScalaVersion(Option(scalaVersion))
|
||||
def withLogger(logger: CacheLogger): CoursierConfiguration =
|
||||
withLogger(Option(logger))
|
||||
def withCache(cache: File): CoursierConfiguration =
|
||||
withCache(Option(cache))
|
||||
def withIvyHome(ivyHome: File): CoursierConfiguration =
|
||||
withIvyHome(Option(ivyHome))
|
||||
def withFollowHttpToHttpsRedirections(followHttpToHttpsRedirections: Boolean): CoursierConfiguration =
|
||||
withFollowHttpToHttpsRedirections(Some(followHttpToHttpsRedirections))
|
||||
def withFollowHttpToHttpsRedirections(): CoursierConfiguration =
|
||||
withFollowHttpToHttpsRedirections(Some(true))
|
||||
def withStrict(strict: Strict): CoursierConfiguration =
|
||||
withStrict(Some(strict))
|
||||
def withTtl(ttl: Duration): CoursierConfiguration =
|
||||
withTtl(Some(ttl))
|
||||
def addRepositoryAuthentication(repositoryId: String, authentication: Authentication): CoursierConfiguration =
|
||||
withAuthenticationByRepositoryId(authenticationByRepositoryId :+ (repositoryId, authentication))
|
||||
|
||||
def withUpdateConfiguration(conf: UpdateConfiguration): CoursierConfiguration =
|
||||
withMissingOk(conf.missingOk)
|
||||
}
|
||||
|
||||
object CoursierConfiguration {
|
||||
|
||||
@deprecated("Legacy cache location support was dropped, this method does nothing.", "2.0.0-RC6-10")
|
||||
def checkLegacyCache(): Unit = ()
|
||||
|
||||
def apply(
|
||||
log: Logger,
|
||||
resolvers: Vector[Resolver],
|
||||
parallelDownloads: Int,
|
||||
maxIterations: Int,
|
||||
sbtScalaOrganization: String,
|
||||
sbtScalaVersion: String,
|
||||
sbtScalaJars: Vector[File],
|
||||
interProjectDependencies: Vector[Project],
|
||||
excludeDependencies: Vector[(String, String)],
|
||||
fallbackDependencies: Vector[FallbackDependency],
|
||||
autoScalaLibrary: Boolean,
|
||||
hasClassifiers: Boolean,
|
||||
classifiers: Vector[String],
|
||||
mavenProfiles: Vector[String],
|
||||
scalaOrganization: String,
|
||||
scalaVersion: String,
|
||||
authenticationByRepositoryId: Vector[(String, Authentication)],
|
||||
credentials: Seq[Credentials],
|
||||
logger: CacheLogger,
|
||||
cache: File
|
||||
): CoursierConfiguration =
|
||||
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)
|
||||
) /* no need to touch this 'apply'; @data above is doing the hard work */
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import coursier.util.Artifact
|
|||
import coursier.internal.Typelevel
|
||||
import lmcoursier.definitions.ToCoursier
|
||||
import lmcoursier.internal.{ArtifactsParams, ArtifactsRun, CoursierModuleDescriptor, InterProjectRepository, ResolutionParams, ResolutionRun, Resolvers, SbtBootJars, UpdateParams, UpdateRun}
|
||||
import lmcoursier.syntax._
|
||||
import sbt.internal.librarymanagement.IvySbt
|
||||
import sbt.librarymanagement._
|
||||
import sbt.util.Logger
|
||||
|
|
@ -31,8 +32,6 @@ class CoursierDependencyResolution(
|
|||
bootstrappingProtocolHandler = true
|
||||
)
|
||||
|
||||
lmcoursier.CoursierConfiguration.checkLegacyCache()
|
||||
|
||||
private var protocolHandlerClassLoader: Option[ClassLoader] = None
|
||||
private val protocolHandlerClassLoaderLock = new Object
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,4 @@ import java.io.File
|
|||
|
||||
abstract class Credentials extends Serializable
|
||||
|
||||
object Credentials {
|
||||
|
||||
def apply(): DirectCredentials = DirectCredentials()
|
||||
def apply(host: String, username: String, password: String): DirectCredentials = DirectCredentials(host, username, password)
|
||||
def apply(host: String, username: String, password: String, realm: Option[String]): DirectCredentials = DirectCredentials(host, username, password, realm)
|
||||
def apply(host: String, username: String, password: String, realm: String): DirectCredentials = DirectCredentials(host, username, password, Option(realm))
|
||||
def apply(host: String, username: String, password: String, realm: Option[String], optional: Boolean): DirectCredentials = DirectCredentials(host, username, password, realm, optional)
|
||||
def apply(host: String, username: String, password: String, realm: String, optional: Boolean): DirectCredentials = DirectCredentials(host, username, password, Option(realm), optional)
|
||||
|
||||
def apply(f: File): FileCredentials =
|
||||
FileCredentials(f.getAbsolutePath)
|
||||
def apply(f: File, optional: Boolean): FileCredentials =
|
||||
FileCredentials(f.getAbsolutePath, optional)
|
||||
}
|
||||
object Credentials
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
package lmcoursier.credentials
|
||||
|
||||
import dataclass._
|
||||
|
||||
@data class DirectCredentials(
|
||||
host: String = "",
|
||||
username: String = "",
|
||||
password: String = "",
|
||||
@since
|
||||
realm: Option[String] = None,
|
||||
@since
|
||||
optional: Boolean = true,
|
||||
@since
|
||||
matchHost: Boolean = false,
|
||||
httpsOnly: Boolean = true
|
||||
) extends Credentials {
|
||||
|
||||
def withRealm(realm: String): DirectCredentials =
|
||||
withRealm(Option(realm))
|
||||
|
||||
override def toString(): String =
|
||||
withPassword("****")
|
||||
.productIterator
|
||||
.mkString("DirectCredentials(", ", ", ")")
|
||||
}
|
||||
|
||||
object DirectCredentials {
|
||||
def apply(host: String, username: String, password: String, realm: String): DirectCredentials = DirectCredentials(host, username, password, Option(realm))
|
||||
def apply(host: String, username: String, password: String, realm: String, optional: Boolean): DirectCredentials = DirectCredentials(host, username, password, Option(realm), optional)
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ object CachePolicy {
|
|||
/* NOTE: the following comments are copied from coursier.cache.CachePolicy for the benefit of users within an IDE
|
||||
that reads the javadocs. Please keep in sync from the original ADT.
|
||||
*/
|
||||
|
||||
|
||||
/** Only pick local files, possibly from the cache. Don't try to download anything. */
|
||||
case object LocalOnly extends CachePolicy
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
@data class Dependency(
|
||||
module: Module,
|
||||
version: String,
|
||||
configuration: Configuration,
|
||||
exclusions: Set[(Organization, ModuleName)],
|
||||
publication: Publication,
|
||||
optional: Boolean,
|
||||
transitive: Boolean
|
||||
) {
|
||||
def attributes: Attributes = publication.attributes
|
||||
def withAttributes(attributes: Attributes): Dependency =
|
||||
withPublication(
|
||||
publication
|
||||
.withType(attributes.`type`)
|
||||
.withClassifier(attributes.classifier)
|
||||
)
|
||||
}
|
||||
|
||||
object Dependency {
|
||||
def apply(
|
||||
module: Module,
|
||||
version: String,
|
||||
configuration: Configuration,
|
||||
exclusions: Set[(Organization, ModuleName)],
|
||||
attributes: Attributes,
|
||||
optional: Boolean,
|
||||
transitive: Boolean
|
||||
): Dependency =
|
||||
Dependency(
|
||||
module,
|
||||
version,
|
||||
configuration,
|
||||
exclusions,
|
||||
Publication("", attributes.`type`, Extension(""), attributes.classifier),
|
||||
optional,
|
||||
transitive
|
||||
)
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
/**
|
||||
* @param exclude Use "*" in either organization or name to match any.
|
||||
* @param include Use "*" in either organization or name to match any.
|
||||
*/
|
||||
@data class ModuleMatchers(
|
||||
exclude: Set[Module],
|
||||
include: Set[Module],
|
||||
includeByDefault: Boolean = true
|
||||
)
|
||||
|
||||
object ModuleMatchers {
|
||||
def all: ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set.empty)
|
||||
def only(organization: String, moduleName: String): ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set(Module(Organization(organization), ModuleName(moduleName), Map())), includeByDefault = false)
|
||||
def only(mod: Module): ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set(mod), includeByDefault = false)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package lmcoursier.definitions
|
||||
|
||||
import dataclass.data
|
||||
|
||||
@data class Publication(
|
||||
name: String,
|
||||
`type`: Type,
|
||||
ext: Extension,
|
||||
classifier: Classifier
|
||||
) {
|
||||
def attributes: Attributes =
|
||||
Attributes(`type`, classifier)
|
||||
def withAttributes(attributes: Attributes): Publication =
|
||||
withType(attributes.`type`)
|
||||
.withClassifier(attributes.classifier)
|
||||
}
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
package lmcoursier
|
||||
|
||||
import coursier.cache.CacheDefaults
|
||||
import lmcoursier.credentials._
|
||||
import lmcoursier.definitions._
|
||||
import sbt.librarymanagement.{Resolver, UpdateConfiguration, ModuleID, CrossVersion, ModuleInfo, ModuleDescriptorConfiguration}
|
||||
import xsbti.Logger
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
|
||||
package object syntax {
|
||||
implicit class CoursierConfigurationModule(value: CoursierConfiguration.type) {
|
||||
@deprecated("Legacy cache location support was dropped, this method does nothing.", "2.0.0-RC6-10")
|
||||
def checkLegacyCache(): Unit = ()
|
||||
|
||||
def apply(
|
||||
log: Logger,
|
||||
resolvers: Vector[Resolver],
|
||||
parallelDownloads: Int,
|
||||
maxIterations: Int,
|
||||
sbtScalaOrganization: String,
|
||||
sbtScalaVersion: String,
|
||||
sbtScalaJars: Vector[File],
|
||||
interProjectDependencies: Vector[Project],
|
||||
excludeDependencies: Vector[(String, String)],
|
||||
fallbackDependencies: Vector[FallbackDependency],
|
||||
autoScalaLibrary: Boolean,
|
||||
hasClassifiers: Boolean,
|
||||
classifiers: Vector[String],
|
||||
mavenProfiles: Vector[String],
|
||||
scalaOrganization: String,
|
||||
scalaVersion: String,
|
||||
authenticationByRepositoryId: Vector[(String, Authentication)],
|
||||
credentials: Seq[Credentials],
|
||||
logger: CacheLogger,
|
||||
cache: File
|
||||
): CoursierConfiguration =
|
||||
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),
|
||||
ivyHome = None,
|
||||
followHttpToHttpsRedirections = None,
|
||||
strict = None,
|
||||
extraProjects = Vector.empty,
|
||||
forceVersions = Vector.empty,
|
||||
reconciliation = Vector.empty,
|
||||
classpathOrder = true,
|
||||
verbosityLevel = 0,
|
||||
ttl = CacheDefaults.ttl,
|
||||
checksums = CacheDefaults.checksums.toVector,
|
||||
cachePolicies = CacheDefaults.cachePolicies.toVector.map(FromCoursier.cachePolicy),
|
||||
missingOk = false,
|
||||
sbtClassifiers = false,
|
||||
providedInCompile = false,
|
||||
protocolHandlerDependencies = Vector.empty,
|
||||
)
|
||||
}
|
||||
|
||||
implicit class CoursierConfigurationOp(value: CoursierConfiguration) {
|
||||
def withLog(log: Logger): CoursierConfiguration =
|
||||
value.withLog(Option(log))
|
||||
def withSbtScalaOrganization(sbtScalaOrganization: String): CoursierConfiguration =
|
||||
value.withSbtScalaOrganization(Option(sbtScalaOrganization))
|
||||
def withSbtScalaVersion(sbtScalaVersion: String): CoursierConfiguration =
|
||||
value.withSbtScalaVersion(Option(sbtScalaVersion))
|
||||
def withScalaOrganization(scalaOrganization: String): CoursierConfiguration =
|
||||
value.withScalaOrganization(Option(scalaOrganization))
|
||||
def withScalaVersion(scalaVersion: String): CoursierConfiguration =
|
||||
value.withScalaVersion(Option(scalaVersion))
|
||||
def withLogger(logger: CacheLogger): CoursierConfiguration =
|
||||
value.withLogger(Option(logger))
|
||||
def withCache(cache: File): CoursierConfiguration =
|
||||
value.withCache(Option(cache))
|
||||
def withIvyHome(ivyHome: File): CoursierConfiguration =
|
||||
value.withIvyHome(Option(ivyHome))
|
||||
def withFollowHttpToHttpsRedirections(followHttpToHttpsRedirections: Boolean): CoursierConfiguration =
|
||||
value.withFollowHttpToHttpsRedirections(Some(followHttpToHttpsRedirections))
|
||||
def withFollowHttpToHttpsRedirections(): CoursierConfiguration =
|
||||
value.withFollowHttpToHttpsRedirections(Some(true))
|
||||
def withStrict(strict: Strict): CoursierConfiguration =
|
||||
value.withStrict(Some(strict))
|
||||
def withTtl(ttl: Duration): CoursierConfiguration =
|
||||
value.withTtl(Some(ttl))
|
||||
def addRepositoryAuthentication(repositoryId: String, authentication: Authentication): CoursierConfiguration =
|
||||
value.withAuthenticationByRepositoryId(value.authenticationByRepositoryId :+ (repositoryId, authentication))
|
||||
|
||||
def withUpdateConfiguration(conf: UpdateConfiguration): CoursierConfiguration =
|
||||
value.withMissingOk(conf.missingOk)
|
||||
}
|
||||
|
||||
implicit class PublicationOp(value: Publication) {
|
||||
def attributes: Attributes =
|
||||
Attributes(value.`type`, value.classifier)
|
||||
|
||||
def withAttributes(attributes: Attributes): Publication =
|
||||
value.withType(attributes.`type`)
|
||||
.withClassifier(attributes.classifier)
|
||||
}
|
||||
|
||||
implicit class DependencyModule(value: Dependency.type) {
|
||||
def apply(
|
||||
module: Module,
|
||||
version: String,
|
||||
configuration: Configuration,
|
||||
exclusions: Set[(Organization, ModuleName)],
|
||||
attributes: Attributes,
|
||||
optional: Boolean,
|
||||
transitive: Boolean
|
||||
): Dependency =
|
||||
Dependency(
|
||||
module,
|
||||
version,
|
||||
configuration,
|
||||
exclusions,
|
||||
Publication("", attributes.`type`, Extension(""), attributes.classifier),
|
||||
optional,
|
||||
transitive
|
||||
)
|
||||
}
|
||||
|
||||
implicit class DependencyOp(value: Dependency) {
|
||||
def attributes: Attributes = value.publication.attributes
|
||||
|
||||
def withAttributes(attributes: Attributes): Dependency =
|
||||
value.withPublication(
|
||||
value.publication
|
||||
.withType(attributes.`type`)
|
||||
.withClassifier(attributes.classifier)
|
||||
)
|
||||
}
|
||||
|
||||
implicit class ModuleMatchersModule(value: ModuleMatchers.type) {
|
||||
def all: ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set.empty)
|
||||
def only(organization: String, moduleName: String): ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set(Module(Organization(organization), ModuleName(moduleName), Map())), includeByDefault = false)
|
||||
def only(mod: Module): ModuleMatchers =
|
||||
ModuleMatchers(Set.empty, Set(mod), includeByDefault = false)
|
||||
}
|
||||
|
||||
implicit class StrictOp(value: Strict) {
|
||||
def addInclude(include: (String, String)*): Strict =
|
||||
value.withInclude(value.include ++ include)
|
||||
def addExclude(exclude: (String, String)*): Strict =
|
||||
value.withExclude(value.exclude ++ exclude)
|
||||
}
|
||||
|
||||
implicit class AuthenticationModule(value: Authentication.type) {
|
||||
def apply(headers: Seq[(String, String)]): Authentication =
|
||||
Authentication("", "").withHeaders(headers)
|
||||
}
|
||||
|
||||
implicit class DirectCredentialsModule(value: DirectCredentials.type) {
|
||||
def apply(host: String, username: String, password: String, realm: String): DirectCredentials =
|
||||
DirectCredentials(host, username, password, Option(realm))
|
||||
def apply(host: String, username: String, password: String, realm: String, optional: Boolean): DirectCredentials =
|
||||
DirectCredentials(host, username, password, Option(realm))
|
||||
}
|
||||
|
||||
implicit class DirectCredentialsOp(value: DirectCredentials) {
|
||||
def withRealm(realm: String): DirectCredentials =
|
||||
value.withRealm(Option(realm))
|
||||
}
|
||||
|
||||
implicit class CredentialsModule(value: Credentials.type) {
|
||||
def apply(): DirectCredentials = DirectCredentials()
|
||||
def apply(host: String, username: String, password: String): DirectCredentials =
|
||||
DirectCredentials(host, username, password)
|
||||
def apply(host: String, username: String, password: String, realm: Option[String]): DirectCredentials =
|
||||
DirectCredentials(host, username, password, realm)
|
||||
def apply(host: String, username: String, password: String, realm: String): DirectCredentials =
|
||||
DirectCredentials(host, username, password, Option(realm))
|
||||
def apply(host: String, username: String, password: String, realm: Option[String], optional: Boolean): DirectCredentials =
|
||||
DirectCredentials(host, username, password, realm, optional, matchHost = false, httpsOnly = true)
|
||||
def apply(host: String, username: String, password: String, realm: String, optional: Boolean): DirectCredentials =
|
||||
DirectCredentials(host, username, password, Option(realm), optional, matchHost = false, httpsOnly = true)
|
||||
|
||||
def apply(f: File): FileCredentials =
|
||||
FileCredentials(f.getAbsolutePath)
|
||||
def apply(f: File, optional: Boolean): FileCredentials =
|
||||
FileCredentials(f.getAbsolutePath, optional)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import lmcoursier.credentials.Credentials
|
|||
import lmcoursier.{CoursierDependencyResolution, FallbackDependency}
|
||||
import lmcoursier.definitions.{CacheLogger, Configuration, Project, Publication}
|
||||
import lmcoursier.internal.SbtCoursierCache
|
||||
import lmcoursier.syntax._
|
||||
import sbt.{AutoPlugin, Classpaths, Compile, Setting, TaskKey, Test, settingKey, taskKey}
|
||||
import sbt.Keys._
|
||||
import sbt.librarymanagement.DependencyBuilders.OrganizationArtifactName
|
||||
|
|
@ -14,8 +15,6 @@ import sbt.librarymanagement.{ModuleID, Resolver, URLRepository}
|
|||
|
||||
object SbtCoursierShared extends AutoPlugin {
|
||||
|
||||
lmcoursier.CoursierConfiguration.checkLegacyCache()
|
||||
|
||||
override def trigger = allRequirements
|
||||
|
||||
override def requires = sbt.plugins.JvmPlugin
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package coursier.sbtlmcoursier
|
|||
|
||||
import lmcoursier.definitions.{Authentication, ModuleMatchers, Reconciliation}
|
||||
import lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs}
|
||||
import lmcoursier.syntax._
|
||||
import coursier.sbtcoursiershared.InputsTasks.{credentialsTask, strictTask}
|
||||
import coursier.sbtcoursiershared.{InputsTasks, SbtCoursierShared}
|
||||
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
|
||||
|
|
@ -152,7 +153,7 @@ object LmCoursierPlugin extends AutoPlugin {
|
|||
|
||||
val authenticationByRepositoryId = actualCoursierCredentials.value.mapValues { c =>
|
||||
val a = c.authentication
|
||||
Authentication(a.user, a.password, a.optional, a.realmOpt)
|
||||
Authentication(a.user, a.password, a.optional, a.realmOpt, headers = Nil, httpsOnly = true, passOnRedirect = false)
|
||||
}
|
||||
val credentials = credentialsTask.value
|
||||
val strict = strictTask.value
|
||||
|
|
|
|||
|
|
@ -90,7 +90,8 @@ object Settings {
|
|||
}
|
||||
|
||||
lazy val dontPublish = Seq(
|
||||
publish := {}
|
||||
publish := {},
|
||||
publish / skip := true,
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
|
||||
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.0")
|
||||
addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.0.1")
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
|
||||
|
||||
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
|
||||
|
|
|
|||
Loading…
Reference in New Issue