mirror of https://github.com/sbt/sbt.git
Use dataclass-scalafix for code gen
This uses https://github.com/hamnis/dataclass-scalafix.
This commit is contained in:
parent
25ea593d42
commit
e8b2a198fb
32
build.sbt
32
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,10 +14,29 @@ inThisBuild(List(
|
|||
"",
|
||||
url("https://github.com/alexarchambault")
|
||||
)
|
||||
)
|
||||
),
|
||||
semanticdbEnabled := true,
|
||||
semanticdbVersion := "4.5.9",
|
||||
scalafixDependencies += "net.hamnaberg" %% "dataclass-scalafix" % dataclassScalafixV
|
||||
))
|
||||
|
||||
val coursierVersion0 = "2.1.0-M6-49-gff26f8e39"
|
||||
|
||||
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" % {
|
||||
scalaBinaryVersion.value match {
|
||||
|
|
@ -36,7 +57,7 @@ lazy val definitions = project
|
|||
crossScalaVersions := Seq(scala212, scala213),
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"io.github.alexarchambault" %% "data-class" % "0.2.5" % Provided,
|
||||
"net.hamnaberg" %% "dataclass-annotation" % dataclassScalafixV % Provided,
|
||||
lmIvy.value,
|
||||
),
|
||||
dontPublish,
|
||||
|
|
@ -44,7 +65,6 @@ lazy val definitions = project
|
|||
|
||||
lazy val `lm-coursier` = project
|
||||
.in(file("modules/lm-coursier"))
|
||||
.dependsOn(definitions)
|
||||
.settings(
|
||||
shared,
|
||||
crossScalaVersions := Seq(scala212, scala213),
|
||||
|
|
@ -52,6 +72,7 @@ lazy val `lm-coursier` = project
|
|||
Mima.lmCoursierFilters,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"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
|
||||
|
|
@ -75,14 +96,13 @@ lazy val `lm-coursier` = project
|
|||
lazy val `lm-coursier-shaded` = project
|
||||
.in(file("modules/lm-coursier/target/shaded-module"))
|
||||
.enablePlugins(ShadingPlugin)
|
||||
.dependsOn(definitions)
|
||||
.settings(
|
||||
shared,
|
||||
crossScalaVersions := Seq(scala212, scala213),
|
||||
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(
|
||||
|
|
@ -116,6 +136,7 @@ lazy val `lm-coursier-shaded` = project
|
|||
},
|
||||
libraryDependencies ++= Seq(
|
||||
"io.get-coursier" %% "coursier" % coursierVersion0,
|
||||
"net.hamnaberg" %% "dataclass-annotation" % dataclassScalafixV % Provided,
|
||||
"org.scala-lang.modules" %% "scala-collection-compat" % "2.8.1",
|
||||
"org.scala-lang.modules" %% "scala-xml" % "1.3.0", // depending on that one so that it doesn't get shaded
|
||||
lmIvy.value,
|
||||
|
|
@ -215,6 +236,7 @@ lazy val `sbt-coursier-root` = project
|
|||
.in(file("."))
|
||||
.disablePlugins(MimaPlugin)
|
||||
.aggregate(
|
||||
definitions,
|
||||
`lm-coursier`,
|
||||
`lm-coursier-shaded`,
|
||||
`sbt-coursier`,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package lmcoursier
|
|||
|
||||
import java.io.File
|
||||
|
||||
import dataclass.data
|
||||
import dataclass.{ data, since }
|
||||
import coursier.cache.CacheDefaults
|
||||
import lmcoursier.credentials.Credentials
|
||||
import lmcoursier.definitions.{Authentication, CacheLogger, CachePolicy, FromCoursier, Module, ModuleMatchers, Project, Reconciliation, Strict}
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
../../../../../../lm-coursier/src/main/scala/lmcoursier/credentials/Credentials.scala
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package lmcoursier.credentials
|
||||
|
||||
import java.io.File
|
||||
|
||||
abstract class Credentials extends Serializable
|
||||
|
||||
object Credentials
|
||||
|
|
@ -6,17 +6,15 @@ import dataclass._
|
|||
host: String = "",
|
||||
username: String = "",
|
||||
password: String = "",
|
||||
@since
|
||||
@since("1.0")
|
||||
realm: Option[String] = None,
|
||||
@since
|
||||
@since("1.1")
|
||||
optional: Boolean = true,
|
||||
@since
|
||||
@since("1.2")
|
||||
matchHost: Boolean = false,
|
||||
@since("1.3")
|
||||
httpsOnly: Boolean = true
|
||||
) extends Credentials {
|
||||
|
||||
override def toString(): String =
|
||||
withPassword("****")
|
||||
.productIterator
|
||||
.mkString("DirectCredentials(", ", ", ")")
|
||||
override def toString(): String = s"DirectCredentials(host=$host, username=$username)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,18 +7,13 @@ import dataclass._
|
|||
password: String,
|
||||
optional: Boolean = false,
|
||||
realmOpt: Option[String] = None,
|
||||
@since
|
||||
@since("1.0")
|
||||
headers: Seq[(String,String)] = Nil,
|
||||
@since("1.1")
|
||||
httpsOnly: Boolean = true,
|
||||
@since("1.2")
|
||||
passOnRedirect: Boolean = false
|
||||
) {
|
||||
override def toString(): String =
|
||||
withPassword("****")
|
||||
.withHeaders(
|
||||
headers.map {
|
||||
case (k, v) => (k, "****")
|
||||
}
|
||||
)
|
||||
.productIterator
|
||||
.mkString("Authentication(", ", ", ")")
|
||||
s"Authentication(user=$user)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,21 @@ import java.io.File
|
|||
|
||||
abstract class Credentials extends Serializable
|
||||
|
||||
object Credentials
|
||||
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, 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,23 +182,4 @@ package object syntax {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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