Move out custom methods in data-classes to syntax package

These are mostly unused, so we might be able to get rid of them too eventually?
This commit is contained in:
Eugene Yokota 2022-08-12 10:17:34 -04:00
parent ca6704b6b0
commit 22bac78b34
12 changed files with 212 additions and 163 deletions

View File

@ -59,86 +59,4 @@ import java.net.URLClassLoader
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 */
}
)

View File

@ -15,16 +15,8 @@ import dataclass._
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)
}

View File

@ -22,9 +22,3 @@ import dataclass._
.productIterator
.mkString("Authentication(", ", ", ")")
}
object Authentication {
def apply(headers: Seq[(String, String)]): Authentication =
Authentication("", "").withHeaders(headers)
}

View File

@ -10,33 +10,4 @@ import dataclass.data
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
)
}
)

View File

@ -11,12 +11,3 @@ import dataclass.data
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)
}

View File

@ -7,10 +7,4 @@ import dataclass.data
`type`: Type,
ext: Extension,
classifier: Classifier
) {
def attributes: Attributes =
Attributes(`type`, classifier)
def withAttributes(attributes: Attributes): Publication =
withType(attributes.`type`)
.withClassifier(attributes.classifier)
}
)

View File

@ -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)
}
)

View File

@ -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

View File

@ -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

View File

@ -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)
}
}

View File

@ -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

View File

@ -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}