From c5b7038f3a5bae98644927b6fc65df626e9a68b4 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sun, 17 Nov 2024 08:28:38 +0900 Subject: [PATCH] use `given` instead of `implicit val` --- .../sbt/internal/parser/NewFormatSpec.scala | 2 +- .../formats/GlobalLockFormat.scala | 4 ++-- .../formats/LoggerFormat.scala | 4 ++-- .../formats/LogicalClockFormats.scala | 2 +- .../formats/NodeSeqFormat.scala | 2 +- .../librarymanagement/ConfigRefFormats.scala | 2 +- .../ConfigurationFormats.scala | 2 +- .../sbt/librarymanagement/CrossVersion.scala | 18 +++++++++--------- .../librarymanagement/EvictionWarning.scala | 2 +- .../librarymanagement/UnresolvedWarning.scala | 2 +- .../sbt/internal/librarymanagement/Ivy.scala | 10 ++++------ .../ivy/formats/UpdateOptionsFormat.scala | 4 ++-- .../DMSerializationSpec.scala | 4 ++-- .../src/test/scala/sbt/CacheIvyTest.scala | 10 +++++----- .../src/main/scala/sbt/Reference.scala | 6 +++--- .../main/scala/sbt/internal/Continuous.scala | 4 ++-- .../main/scala/sbt/internal/DynamicInput.scala | 2 +- .../scala/sbt/internal/FileChangesMacro.scala | 2 +- .../scala/sbt/internal/LibraryManagement.scala | 6 +++--- .../scala/sbt/internal/server/Definition.scala | 2 +- .../sbt/internal/server/NetworkChannel.scala | 2 +- main/src/main/scala/sbt/nio/FileStamp.scala | 14 +++++++------- main/src/main/scala/sbt/nio/Settings.scala | 2 +- .../scala/sbt/internal/FileStampJsonSpec.scala | 4 ++-- .../JsonRpcNotificationMessageFormats.scala | 2 +- .../codec/JsonRpcRequestMessageFormats.scala | 3 +-- .../codec/JsonRpcResponseErrorFormats.scala | 3 +-- .../codec/JsonRpcResponseMessageFormats.scala | 3 +-- .../scala/sbt/protocol/Serialization.scala | 8 ++++---- sbt-app/src/main/scala/package.scala | 10 +++++----- .../test/scala/testpkg/BuildServerTest.scala | 4 ++-- .../sbt/internal/testing/StatusFormats.scala | 2 +- .../sbt/internal/testing/TestLogger.scala | 12 ++++++------ .../util/codec/ByteBufferFormats.scala | 2 +- .../util/codec/HashedVirtualRefFormats.scala | 2 +- .../scala/sbt/util/BasicCacheImplicits.scala | 2 +- .../src/main/scala/sbt/util/CacheStore.scala | 6 ++---- .../src/main/scala/sbt/util/FileInfo.scala | 18 +++++++++--------- .../src/test/scala/SingletonCacheSpec.scala | 2 +- .../src/test/scala/sbt/util/TrackedSpec.scala | 4 ++-- 40 files changed, 94 insertions(+), 101 deletions(-) diff --git a/buildfile/src/test/scala/sbt/internal/parser/NewFormatSpec.scala b/buildfile/src/test/scala/sbt/internal/parser/NewFormatSpec.scala index 4fd3c0e50..659734bb5 100644 --- a/buildfile/src/test/scala/sbt/internal/parser/NewFormatSpec.scala +++ b/buildfile/src/test/scala/sbt/internal/parser/NewFormatSpec.scala @@ -17,7 +17,7 @@ import sbt.internal.inc.PlainVirtualFileConverter object NewFormatSpec extends AbstractSpec { val converter = PlainVirtualFileConverter.converter - implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions + given splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions test("New Format should handle lines") { val rootPath = getClass.getResource("/new-format").getPath diff --git a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/GlobalLockFormat.scala b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/GlobalLockFormat.scala index ce9f556af..659284a4e 100644 --- a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/GlobalLockFormat.scala +++ b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/GlobalLockFormat.scala @@ -12,10 +12,10 @@ import java.util.concurrent.Callable trait GlobalLockFormat { self: BasicJsonProtocol => import GlobalLockFormats._ - implicit lazy val globalLockIsoString: IsoString[GlobalLock] = + given globalLockIsoString: IsoString[GlobalLock] = IsoString.iso(_ => "", _ => NoGlobalLock) - implicit lazy val GlobalLockFormat: JsonFormat[GlobalLock] = isoStringFormat(using + given GlobalLockFormat: JsonFormat[GlobalLock] = isoStringFormat(using globalLockIsoString ) } diff --git a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LoggerFormat.scala b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LoggerFormat.scala index 2335589e1..63e5c67c1 100644 --- a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LoggerFormat.scala +++ b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LoggerFormat.scala @@ -9,8 +9,8 @@ import sbt.util.Logger.Null * This is mostly for making IvyConfiguration serializable to JSON. */ trait LoggerFormat { self: BasicJsonProtocol => - implicit lazy val xsbtiLoggerIsoString: IsoString[Logger] = + given xsbtiLoggerIsoString: IsoString[Logger] = IsoString.iso(_ => "", _ => Null) - implicit lazy val LoggerFormat: JsonFormat[Logger] = isoStringFormat(using implicitly) + given LoggerFormat: JsonFormat[Logger] = isoStringFormat(using implicitly) } diff --git a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LogicalClockFormats.scala b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LogicalClockFormats.scala index 9daca4a93..f48b7e763 100644 --- a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LogicalClockFormats.scala +++ b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/LogicalClockFormats.scala @@ -5,7 +5,7 @@ import sjsonnew._ import sbt.librarymanagement.LogicalClock trait LogicalClockFormats { self: BasicJsonProtocol => - implicit lazy val LogicalClockFormat: JsonFormat[LogicalClock] = + given LogicalClockFormat: JsonFormat[LogicalClock] = projectFormat[LogicalClock, String]( cl => cl.toString, str => LogicalClock(str) diff --git a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/NodeSeqFormat.scala b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/NodeSeqFormat.scala index 45704dfa6..ab7290ae7 100644 --- a/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/NodeSeqFormat.scala +++ b/lm-core/src/main/scala/sbt/internal/librarymanagement/formats/NodeSeqFormat.scala @@ -4,7 +4,7 @@ import sjsonnew._ import scala.xml._ trait NodeSeqFormat { self: BasicJsonProtocol => - implicit lazy val NodeSeqFormat: JsonFormat[NodeSeq] = projectFormat[NodeSeq, String]( + given NodeSeqFormat: JsonFormat[NodeSeq] = projectFormat[NodeSeq, String]( xml => {xml}.toString, str => XML.loadString(str).child ) diff --git a/lm-core/src/main/scala/sbt/librarymanagement/ConfigRefFormats.scala b/lm-core/src/main/scala/sbt/librarymanagement/ConfigRefFormats.scala index b7d8d0b05..f18ebc73e 100644 --- a/lm-core/src/main/scala/sbt/librarymanagement/ConfigRefFormats.scala +++ b/lm-core/src/main/scala/sbt/librarymanagement/ConfigRefFormats.scala @@ -6,7 +6,7 @@ package sbt.librarymanagement import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError } trait ConfigRefFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val ConfigRefFormat: JsonFormat[sbt.librarymanagement.ConfigRef] = + given ConfigRefFormat: JsonFormat[sbt.librarymanagement.ConfigRef] = new JsonFormat[sbt.librarymanagement.ConfigRef] { override def read[J]( __jsOpt: Option[J], diff --git a/lm-core/src/main/scala/sbt/librarymanagement/ConfigurationFormats.scala b/lm-core/src/main/scala/sbt/librarymanagement/ConfigurationFormats.scala index b498b8fc0..0fc97c39a 100644 --- a/lm-core/src/main/scala/sbt/librarymanagement/ConfigurationFormats.scala +++ b/lm-core/src/main/scala/sbt/librarymanagement/ConfigurationFormats.scala @@ -8,7 +8,7 @@ import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder } trait ConfigurationFormats { self: sbt.librarymanagement.ConfigurationFormats & sjsonnew.BasicJsonProtocol => - implicit lazy val ConfigurationFormat: JsonFormat[sbt.librarymanagement.Configuration] = + given ConfigurationFormat: JsonFormat[sbt.librarymanagement.Configuration] = new JsonFormat[sbt.librarymanagement.Configuration] { override def read[J]( jsOpt: Option[J], diff --git a/lm-core/src/main/scala/sbt/librarymanagement/CrossVersion.scala b/lm-core/src/main/scala/sbt/librarymanagement/CrossVersion.scala index 71130476e..75a1c1584 100644 --- a/lm-core/src/main/scala/sbt/librarymanagement/CrossVersion.scala +++ b/lm-core/src/main/scala/sbt/librarymanagement/CrossVersion.scala @@ -249,7 +249,7 @@ object For2_13Use3 { } trait DisabledFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val DisabledFormat: JsonFormat[sbt.librarymanagement.Disabled] = + given DisabledFormat: JsonFormat[sbt.librarymanagement.Disabled] = new JsonFormat[sbt.librarymanagement.Disabled] { override def read[J]( jsOpt: Option[J], @@ -272,7 +272,7 @@ trait DisabledFormats { self: sjsonnew.BasicJsonProtocol => } } - implicit lazy val DisabledObjectFormat: JsonFormat[sbt.librarymanagement.Disabled.type] = + given DisabledObjectFormat: JsonFormat[sbt.librarymanagement.Disabled.type] = new JsonFormat[sbt.librarymanagement.Disabled.type] { override def read[J]( jsOpt: Option[J], @@ -297,7 +297,7 @@ trait DisabledFormats { self: sjsonnew.BasicJsonProtocol => } trait BinaryFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val BinaryFormat: JsonFormat[sbt.librarymanagement.Binary] = + given BinaryFormat: JsonFormat[sbt.librarymanagement.Binary] = new JsonFormat[sbt.librarymanagement.Binary] { override def read[J]( jsOpt: Option[J], @@ -324,7 +324,7 @@ trait BinaryFormats { self: sjsonnew.BasicJsonProtocol => } trait ConstantFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val ConstantFormat: JsonFormat[sbt.librarymanagement.Constant] = + given ConstantFormat: JsonFormat[sbt.librarymanagement.Constant] = new JsonFormat[sbt.librarymanagement.Constant] { override def read[J]( jsOpt: Option[J], @@ -349,7 +349,7 @@ trait ConstantFormats { self: sjsonnew.BasicJsonProtocol => } trait PatchFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val PatchFormat: JsonFormat[sbt.librarymanagement.Patch] = + given PatchFormat: JsonFormat[sbt.librarymanagement.Patch] = new JsonFormat[sbt.librarymanagement.Patch] { override def read[J]( jsOpt: Option[J], @@ -374,7 +374,7 @@ trait PatchFormats { self: sjsonnew.BasicJsonProtocol => } trait FullFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val FullFormat: JsonFormat[sbt.librarymanagement.Full] = + given FullFormat: JsonFormat[sbt.librarymanagement.Full] = new JsonFormat[sbt.librarymanagement.Full] { override def read[J]( jsOpt: Option[J], @@ -401,7 +401,7 @@ trait FullFormats { self: sjsonnew.BasicJsonProtocol => } trait For3Use2_13Formats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val For3Use2_13Format: JsonFormat[sbt.librarymanagement.For3Use2_13] = + given For3Use2_13Format: JsonFormat[sbt.librarymanagement.For3Use2_13] = new JsonFormat[sbt.librarymanagement.For3Use2_13] { override def read[J]( jsOpt: Option[J], @@ -428,7 +428,7 @@ trait For3Use2_13Formats { self: sjsonnew.BasicJsonProtocol => } trait For2_13Use3Formats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val For2_13Use3Format: JsonFormat[sbt.librarymanagement.For2_13Use3] = + given For2_13Use3Format: JsonFormat[sbt.librarymanagement.For2_13Use3] = new JsonFormat[sbt.librarymanagement.For2_13Use3] { override def read[J]( jsOpt: Option[J], @@ -459,7 +459,7 @@ trait CrossVersionFormats { sbt.librarymanagement.BinaryFormats & sbt.librarymanagement.ConstantFormats & sbt.librarymanagement.PatchFormats & sbt.librarymanagement.FullFormats & sbt.librarymanagement.For3Use2_13Formats & sbt.librarymanagement.For2_13Use3Formats => - implicit lazy val CrossVersionFormat: JsonFormat[CrossVersion] = { + given CrossVersionFormat: JsonFormat[CrossVersion] = { val format = flatUnionFormat8[ CrossVersion, Disabled, diff --git a/lm-core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala b/lm-core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala index b3ac16fb0..4a62f31b2 100644 --- a/lm-core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala +++ b/lm-core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala @@ -213,7 +213,7 @@ final class EvictionPair private[sbt] ( } object EvictionPair { - implicit val evictionPairLines: ShowLines[EvictionPair] = ShowLines { (a: EvictionPair) => + given evictionPairLines: ShowLines[EvictionPair] = ShowLines { (a: EvictionPair) => val seen: mutable.Set[ModuleID] = mutable.Set() val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r => val rev = r.module.revision diff --git a/lm-core/src/main/scala/sbt/librarymanagement/UnresolvedWarning.scala b/lm-core/src/main/scala/sbt/librarymanagement/UnresolvedWarning.scala index 88a36918e..1bad15d5e 100644 --- a/lm-core/src/main/scala/sbt/librarymanagement/UnresolvedWarning.scala +++ b/lm-core/src/main/scala/sbt/librarymanagement/UnresolvedWarning.scala @@ -55,7 +55,7 @@ object UnresolvedWarning { case Some(RangePosition(path, LineRange(start, end))) => s" ($path#L$start-$end)" case _ => "" } - implicit val unresolvedWarningLines: ShowLines[UnresolvedWarning] = ShowLines { a => + given unresolvedWarningLines: ShowLines[UnresolvedWarning] = ShowLines { a => val withExtra = a.resolveException.failed.filter(_.extraDependencyAttributes.nonEmpty) val buffer = mutable.ListBuffer[String]() if (withExtra.nonEmpty) { diff --git a/lm-ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala b/lm-ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala index 4721604cd..a6557e142 100644 --- a/lm-ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala +++ b/lm-ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala @@ -408,8 +408,7 @@ final class IvySbt( ) // Redefine to use a subset of properties, that are serialisable - override implicit lazy val InlineIvyConfigurationFormat - : JsonFormat[InlineIvyConfiguration] = { + override given InlineIvyConfigurationFormat: JsonFormat[InlineIvyConfiguration] = { def hlToInlineIvy(i: InlineIvyHL): InlineIvyConfiguration = { val ( paths, @@ -431,8 +430,7 @@ final class IvySbt( } // Redefine to use a subset of properties, that are serialisable - override implicit lazy val ExternalIvyConfigurationFormat - : JsonFormat[ExternalIvyConfiguration] = { + override given ExternalIvyConfigurationFormat: JsonFormat[ExternalIvyConfiguration] = { def hlToExternalIvy(e: ExternalIvyHL): ExternalIvyConfiguration = { val (baseDirectory, _) = e ExternalIvyConfiguration( @@ -448,7 +446,7 @@ final class IvySbt( } // Redefine to switch to unionFormat - override implicit lazy val IvyConfigurationFormat: JsonFormat[IvyConfiguration] = + override given IvyConfigurationFormat: JsonFormat[IvyConfiguration] = unionFormat2[IvyConfiguration, InlineIvyConfiguration, ExternalIvyConfiguration] object NullLogger extends sbt.internal.util.BasicLogger { @@ -461,7 +459,7 @@ final class IvySbt( } def extraInputHash: Long = { - import AltLibraryManagementCodec._ + import AltLibraryManagementCodec.given Hasher.hash(owner.configuration) match { case Success(keyHash) => keyHash.toLong case Failure(_) => 0L diff --git a/lm-ivy/src/main/scala/sbt/librarymanagement/ivy/formats/UpdateOptionsFormat.scala b/lm-ivy/src/main/scala/sbt/librarymanagement/ivy/formats/UpdateOptionsFormat.scala index 94bdc2138..52561bd5d 100644 --- a/lm-ivy/src/main/scala/sbt/librarymanagement/ivy/formats/UpdateOptionsFormat.scala +++ b/lm-ivy/src/main/scala/sbt/librarymanagement/ivy/formats/UpdateOptionsFormat.scala @@ -21,7 +21,7 @@ trait UpdateOptionsFormat { sbt.librarymanagement.PasswordAuthenticationFormats & sbt.librarymanagement.KeyFileAuthenticationFormats => /* This is necessary to serialize/deserialize `directResolvers`. */ - private implicit val moduleIdJsonKeyFormat: sjsonnew.JsonKeyFormat[ModuleID] = { + private given moduleIdJsonKeyFormat: sjsonnew.JsonKeyFormat[ModuleID] = { new sjsonnew.JsonKeyFormat[ModuleID] { import sjsonnew.support.scalajson.unsafe._ val moduleIdFormat: JsonFormat[ModuleID] = implicitly[JsonFormat[ModuleID]] @@ -32,7 +32,7 @@ trait UpdateOptionsFormat { } } - implicit lazy val UpdateOptionsFormat: JsonFormat[UpdateOptions] = + given UpdateOptionsFormat: JsonFormat[UpdateOptions] = projectFormat( (uo: UpdateOptions) => ( diff --git a/lm-ivy/src/test/scala/sbt/internal/librarymanagement/DMSerializationSpec.scala b/lm-ivy/src/test/scala/sbt/internal/librarymanagement/DMSerializationSpec.scala index b380800fc..b9ea8f53a 100644 --- a/lm-ivy/src/test/scala/sbt/internal/librarymanagement/DMSerializationSpec.scala +++ b/lm-ivy/src/test/scala/sbt/internal/librarymanagement/DMSerializationSpec.scala @@ -6,7 +6,7 @@ import java.io.File import sbt.librarymanagement._ import sjsonnew.shaded.scalajson.ast.unsafe._ import sjsonnew._, support.scalajson.unsafe._ -import LibraryManagementCodec._ +import LibraryManagementCodec.given import verify.BasicTestSuite object DMSerializationSpec extends BasicTestSuite { @@ -105,6 +105,6 @@ object DMSerializationSpec extends BasicTestSuite { f(a, obj) } - implicit val isoString: IsoString[JValue] = + given isoString: IsoString[JValue] = IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe) } diff --git a/main-actions/src/test/scala/sbt/CacheIvyTest.scala b/main-actions/src/test/scala/sbt/CacheIvyTest.scala index 759eab2e3..a250ea8b5 100644 --- a/main-actions/src/test/scala/sbt/CacheIvyTest.scala +++ b/main-actions/src/test/scala/sbt/CacheIvyTest.scala @@ -55,13 +55,13 @@ class CacheIvyTest extends Properties("CacheIvy") { eq(out, m) :| s"Expected: ${str(m)}" :| s"Got: ${str(out)}" } - implicit val arbConfigRef: Arbitrary[ConfigRef] = Arbitrary( + given arbConfigRef: Arbitrary[ConfigRef] = Arbitrary( for { n <- Gen.alphaStr } yield ConfigRef(n) ) - implicit val arbExclusionRule: Arbitrary[InclExclRule] = Arbitrary( + given arbExclusionRule: Arbitrary[InclExclRule] = Arbitrary( for { o <- Gen.alphaStr n <- Gen.alphaStr @@ -71,18 +71,18 @@ class CacheIvyTest extends Properties("CacheIvy") { } yield InclExclRule(o, n, a, cs.toVector, v) ) - implicit val arbCrossVersion: Arbitrary[CrossVersion] = Arbitrary { + given arbCrossVersion: Arbitrary[CrossVersion] = Arbitrary { // Actual functions don't matter, just Disabled vs Binary vs Full Gen.oneOf(Disabled(), Binary(), Full()) } - implicit val arbArtifact: Arbitrary[Artifact] = Arbitrary { + given arbArtifact: Arbitrary[Artifact] = Arbitrary { for { (n, t, e, cls) <- arbitrary[(String, String, String, String)] } yield Artifact(n, t, e, cls) // keep it simple } - implicit val arbModuleID: Arbitrary[ModuleID] = Arbitrary { + given arbModuleID: Arbitrary[ModuleID] = Arbitrary { for { o <- Gen.identifier n <- Gen.identifier diff --git a/main-settings/src/main/scala/sbt/Reference.scala b/main-settings/src/main/scala/sbt/Reference.scala index 6bbaf449e..6439f641a 100644 --- a/main-settings/src/main/scala/sbt/Reference.scala +++ b/main-settings/src/main/scala/sbt/Reference.scala @@ -79,15 +79,15 @@ object RootProject { def apply(base: File): RootProject = RootProject(IO toURI base) } object Reference { - implicit val resolvedReferenceOrdering: Ordering[ResolvedReference] = { + given resolvedReferenceOrdering: Ordering[ResolvedReference] = { case (ba: BuildRef, bb: BuildRef) => buildRefOrdering.compare(ba, bb) case (pa: ProjectRef, pb: ProjectRef) => projectRefOrdering.compare(pa, pb) case (_: BuildRef, _: ProjectRef) => -1 case (_: ProjectRef, _: BuildRef) => 1 } - implicit val buildRefOrdering: Ordering[BuildRef] = (a, b) => a.build.compareTo(b.build) + given buildRefOrdering: Ordering[BuildRef] = (a, b) => a.build.compareTo(b.build) - implicit val projectRefOrdering: Ordering[ProjectRef] = (a, b) => { + given projectRefOrdering: Ordering[ProjectRef] = (a, b) => { val bc = a.build.compareTo(b.build) if bc == 0 then a.project.compareTo(b.project) else bc } diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index a72035368..7b76d2a6d 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -269,8 +269,8 @@ private[sbt] object Continuous extends DeprecatedContinuous { dynamicInputs: mutable.Set[DynamicInput], context: LoggerContext ): Callbacks = { - implicit val extracted: Extracted = Project.extract(s) - implicit val logger: Logger = + given extracted: Extracted = Project.extract(s) + given logger: Logger = context.logger(channel.name + "-watch", None, None) validateCommands(s, commands) val configs = getAllConfigs(s, commands, dynamicInputs) diff --git a/main/src/main/scala/sbt/internal/DynamicInput.scala b/main/src/main/scala/sbt/internal/DynamicInput.scala index e2e4619cb..abe2fdf86 100644 --- a/main/src/main/scala/sbt/internal/DynamicInput.scala +++ b/main/src/main/scala/sbt/internal/DynamicInput.scala @@ -21,7 +21,7 @@ private[sbt] final case class DynamicInput( ) private[sbt] object DynamicInput { implicit object ordering extends Ordering[DynamicInput] { - private implicit val globOrdering: Ordering[Glob] = Glob.ordering + private given globOrdering: Ordering[Glob] = Glob.ordering private implicit object fileStamperOrdering extends Ordering[FileStamper] { override def compare(left: FileStamper, right: FileStamper): Int = left match { case FileStamper.Hash => diff --git a/main/src/main/scala/sbt/internal/FileChangesMacro.scala b/main/src/main/scala/sbt/internal/FileChangesMacro.scala index 3fb58627e..7efb97353 100644 --- a/main/src/main/scala/sbt/internal/FileChangesMacro.scala +++ b/main/src/main/scala/sbt/internal/FileChangesMacro.scala @@ -83,7 +83,7 @@ object FileChangesMacro: val ts: Scope = $taskScope val changes = rescope[Seq[(NioPath, FileStamp)] => FileChanges](ts, $changeKey).value val current = rescope[Seq[NioPath]](ts, $currentKey).value - import sbt.nio.FileStamp.Formats.* + import sbt.nio.FileStamp.Formats.given val previous = Previous.runtimeInEnclosingTask(rescope[Seq[(NioPath, FileStamp)]](ts, $mapKey)).value previous.map(changes).getOrElse(FileChanges.noPrevious(current)) diff --git a/main/src/main/scala/sbt/internal/LibraryManagement.scala b/main/src/main/scala/sbt/internal/LibraryManagement.scala index b96974548..c6f8c10df 100644 --- a/main/src/main/scala/sbt/internal/LibraryManagement.scala +++ b/main/src/main/scala/sbt/internal/LibraryManagement.scala @@ -25,7 +25,7 @@ import scala.concurrent.duration.FiniteDuration import scala.annotation.nowarn private[sbt] object LibraryManagement { - implicit val linter: sbt.dsl.LinterLevel.Ignore.type = sbt.dsl.LinterLevel.Ignore + given linter: sbt.dsl.LinterLevel.Ignore.type = sbt.dsl.LinterLevel.Ignore private type UpdateInputs = (Long, ModuleSettings, UpdateConfiguration) @@ -382,7 +382,7 @@ private[sbt] object LibraryManagement { def withExcludes(out: File, classifiers: Seq[String], lock: xsbti.GlobalLock)( f: Map[ModuleID, Vector[ConfigRef]] => UpdateReport ): UpdateReport = { - import sbt.librarymanagement.LibraryManagementCodec._ + import sbt.librarymanagement.LibraryManagementCodec.given import sbt.util.FileBasedStore val exclName = "exclude_classifiers" val file = out / exclName @@ -391,7 +391,7 @@ private[sbt] object LibraryManagement { out / (exclName + ".lock"), new Callable[UpdateReport] { def call = { - implicit val midJsonKeyFmt: sjsonnew.JsonKeyFormat[ModuleID] = moduleIdJsonKeyFormat + given midJsonKeyFmt: sjsonnew.JsonKeyFormat[ModuleID] = moduleIdJsonKeyFormat val excludes = store .read[Map[ModuleID, Vector[ConfigRef]]]( diff --git a/main/src/main/scala/sbt/internal/server/Definition.scala b/main/src/main/scala/sbt/internal/server/Definition.scala index 860bc82d7..fee491723 100644 --- a/main/src/main/scala/sbt/internal/server/Definition.scala +++ b/main/src/main/scala/sbt/internal/server/Definition.scala @@ -313,7 +313,7 @@ private[sbt] object Definition { "Problem with processing analyses.", None, ) - import JsonRPCProtocol._ + import JsonRPCProtocol.given send(commandSource, requestId)(rsp) } () diff --git a/main/src/main/scala/sbt/internal/server/NetworkChannel.scala b/main/src/main/scala/sbt/internal/server/NetworkChannel.scala index 73b559350..13cfb77cc 100644 --- a/main/src/main/scala/sbt/internal/server/NetworkChannel.scala +++ b/main/src/main/scala/sbt/internal/server/NetworkChannel.scala @@ -263,7 +263,7 @@ final class NetworkChannel( pendingRequests -= request.id jsonRpcRespondError(request.id, err) case _ => - import sbt.internal.protocol.codec.JsonRPCProtocol._ + import sbt.internal.protocol.codec.JsonRPCProtocol.given val msg = s"unmatched json error for requestId $execId: ${CompactPrinter(Converter.toJsonUnsafe(err))}" log.debug(msg) diff --git a/main/src/main/scala/sbt/nio/FileStamp.scala b/main/src/main/scala/sbt/nio/FileStamp.scala index a2a066456..986142230 100644 --- a/main/src/main/scala/sbt/nio/FileStamp.scala +++ b/main/src/main/scala/sbt/nio/FileStamp.scala @@ -115,16 +115,16 @@ object FileStamp { case FileStamp.LastModified(_) => Digest.sha256Hash(path) object Formats { - implicit val seqPathJsonFormatter: JsonFormat[Seq[Path]] = + given seqPathJsonFormatter: JsonFormat[Seq[Path]] = asStringArray(_.toString, Paths.get(_)) - implicit val seqFileJsonFormatter: JsonFormat[Seq[File]] = + given seqFileJsonFormatter: JsonFormat[Seq[File]] = asStringArray(_.toString, new File(_)) - implicit val seqVirtualFileRefJsonFormatter: JsonFormat[Seq[VirtualFileRef]] = + given seqVirtualFileRefJsonFormatter: JsonFormat[Seq[VirtualFileRef]] = asStringArray(_.id, VirtualFileRef.of) - implicit val fileJsonFormatter: JsonFormat[File] = fromSeqJsonFormat[File] - implicit val pathJsonFormatter: JsonFormat[Path] = fromSeqJsonFormat[Path] - implicit val virtualFileRefJsonFormatter: JsonFormat[VirtualFileRef] = + given fileJsonFormatter: JsonFormat[File] = fromSeqJsonFormat[File] + given pathJsonFormatter: JsonFormat[Path] = fromSeqJsonFormat[Path] + given virtualFileRefJsonFormatter: JsonFormat[VirtualFileRef] = fromSeqJsonFormat[VirtualFileRef] private def asStringArray[T](toStr: T => String, fromStr: String => T): JsonFormat[Seq[T]] = @@ -158,7 +158,7 @@ object FileStamp { seqJsonFormat.write(obj :: Nil, builder) } - implicit val seqPathFileStampJsonFormatter: JsonFormat[Seq[(Path, FileStamp)]] = + given seqPathFileStampJsonFormatter: JsonFormat[Seq[(Path, FileStamp)]] = new JsonFormat[Seq[(Path, FileStamp)]] { override def write[J](obj: Seq[(Path, FileStamp)], builder: Builder[J]): Unit = { val (hashes, lastModifiedTimes) = obj.partition(_._2.isInstanceOf[Hash]) diff --git a/main/src/main/scala/sbt/nio/Settings.scala b/main/src/main/scala/sbt/nio/Settings.scala index eff12b903..506f0b797 100644 --- a/main/src/main/scala/sbt/nio/Settings.scala +++ b/main/src/main/scala/sbt/nio/Settings.scala @@ -18,7 +18,7 @@ import sbt.internal.Clean.ToSeqPath import sbt.internal.Continuous.FileStampRepository import sbt.internal.util.KeyTag import sbt.internal.{ Clean, Continuous, DynamicInput, WatchTransitiveDependencies } -import sbt.nio.FileStamp.Formats._ +import sbt.nio.FileStamp.Formats.given import sbt.nio.FileStamper.{ Hash, LastModified } import sbt.nio.Keys._ import sbt.nio.file.{ AllPass, FileAttributes, Glob, RecursiveGlob } diff --git a/main/src/test/scala/sbt/internal/FileStampJsonSpec.scala b/main/src/test/scala/sbt/internal/FileStampJsonSpec.scala index ab6a8e192..6e082cf23 100644 --- a/main/src/test/scala/sbt/internal/FileStampJsonSpec.scala +++ b/main/src/test/scala/sbt/internal/FileStampJsonSpec.scala @@ -22,7 +22,7 @@ class FileStampJsonSpec extends AnyFlatSpec { Paths.get("foo") -> FileStamp.hash("bar"), Paths.get("bar") -> FileStamp.hash("buzz") ) - implicit val formatter: JsonFormat[Seq[(Path, FileStamp.Hash)]] = + given formatter: JsonFormat[Seq[(Path, FileStamp.Hash)]] = Formats.seqPathHashJsonFormatter val json = Converter.toJsonUnsafe(hashes) val deserialized = Converter.fromJsonUnsafe(json) @@ -33,7 +33,7 @@ class FileStampJsonSpec extends AnyFlatSpec { Paths.get("foo") -> FileStamp.LastModified(1234), Paths.get("bar") -> FileStamp.LastModified(5678) ) - implicit val formatter: JsonFormat[Seq[(Path, FileStamp.LastModified)]] = + given formatter: JsonFormat[Seq[(Path, FileStamp.LastModified)]] = Formats.seqPathLastModifiedJsonFormatter val json = Converter.toJsonUnsafe(lastModifiedTimes) val deserialized = Converter.fromJsonUnsafe(json) diff --git a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcNotificationMessageFormats.scala b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcNotificationMessageFormats.scala index f5f3dcd66..ea7a9b3d2 100644 --- a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcNotificationMessageFormats.scala +++ b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcNotificationMessageFormats.scala @@ -13,7 +13,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe.JValue trait JsonRpcNotificationMessageFormats { self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol => - implicit lazy val JsonRpcNotificationMessageFormat + given JsonRpcNotificationMessageFormat : JsonFormat[sbt.internal.protocol.JsonRpcNotificationMessage] = new JsonFormat[sbt.internal.protocol.JsonRpcNotificationMessage] { override def read[J]( diff --git a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcRequestMessageFormats.scala b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcRequestMessageFormats.scala index 63d6f47e7..a25d17ef3 100644 --- a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcRequestMessageFormats.scala +++ b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcRequestMessageFormats.scala @@ -13,8 +13,7 @@ import sjsonnew.{ Builder, DeserializationException, JsonFormat, Unbuilder, dese trait JsonRpcRequestMessageFormats { self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol => - implicit lazy val JsonRpcRequestMessageFormat - : JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] = + given JsonRpcRequestMessageFormat: JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] = new JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] { override def read[J]( jsOpt: Option[J], diff --git a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseErrorFormats.scala b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseErrorFormats.scala index 2a6c1e579..5d00d4be0 100644 --- a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseErrorFormats.scala +++ b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseErrorFormats.scala @@ -13,8 +13,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe.JValue trait JsonRpcResponseErrorFormats { self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol => - implicit lazy val JsonRpcResponseErrorFormat - : JsonFormat[sbt.internal.protocol.JsonRpcResponseError] = + given JsonRpcResponseErrorFormat: JsonFormat[sbt.internal.protocol.JsonRpcResponseError] = new JsonFormat[sbt.internal.protocol.JsonRpcResponseError] { override def read[J]( jsOpt: Option[J], diff --git a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseMessageFormats.scala b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseMessageFormats.scala index 852ade796..73d7e19ba 100644 --- a/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseMessageFormats.scala +++ b/protocol/src/main/scala/sbt/internal/protocol/codec/JsonRpcResponseMessageFormats.scala @@ -20,8 +20,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe._ trait JsonRpcResponseMessageFormats { self: sbt.internal.util.codec.JValueFormats & sbt.internal.protocol.codec.JsonRpcResponseErrorFormats & sjsonnew.BasicJsonProtocol => - implicit lazy val JsonRpcResponseMessageFormat - : JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] = + given JsonRpcResponseMessageFormat: JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] = new JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] { override def read[J]( jsOpt: Option[J], diff --git a/protocol/src/main/scala/sbt/protocol/Serialization.scala b/protocol/src/main/scala/sbt/protocol/Serialization.scala index 71bf7fb31..8772ef530 100644 --- a/protocol/src/main/scala/sbt/protocol/Serialization.scala +++ b/protocol/src/main/scala/sbt/protocol/Serialization.scala @@ -104,13 +104,13 @@ object Serialization { /** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */ private[sbt] def serializeResponseMessage(message: JsonRpcResponseMessage): Array[Byte] = { - import sbt.internal.protocol.codec.JsonRPCProtocol._ + import sbt.internal.protocol.codec.JsonRPCProtocol.given serializeResponse(message) } /** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */ private[sbt] def serializeRequestMessage(message: JsonRpcRequestMessage): Array[Byte] = { - import sbt.internal.protocol.codec.JsonRPCProtocol._ + import sbt.internal.protocol.codec.JsonRPCProtocol.given serializeResponse(message) } @@ -118,7 +118,7 @@ object Serialization { private[sbt] def serializeNotificationMessage( message: JsonRpcNotificationMessage, ): Array[Byte] = { - import sbt.internal.protocol.codec.JsonRPCProtocol._ + import sbt.internal.protocol.codec.JsonRPCProtocol.given serializeResponse(message) } @@ -215,7 +215,7 @@ object Serialization { val buffer = ByteBuffer.wrap(bytes.toArray) Parser.parseFromByteBuffer(buffer) match { case Success(json @ JObject(fields)) => - import sbt.internal.protocol.codec.JsonRPCProtocol._ + import sbt.internal.protocol.codec.JsonRPCProtocol.given if ((fields find { _.field == "method" }).isDefined) { if ((fields find { _.field == "id" }).isDefined) Converter.fromJson[JsonRpcRequestMessage](json) match { diff --git a/sbt-app/src/main/scala/package.scala b/sbt-app/src/main/scala/package.scala index 1d26d38b8..630c38d82 100644 --- a/sbt-app/src/main/scala/package.scala +++ b/sbt-app/src/main/scala/package.scala @@ -49,12 +49,12 @@ package object sbt * of FileChangesMacro.TaskOps is ever made which is why it is ok to use `???`. */ // implicit def taskToTaskOpts[T](t: TaskKey[T]): FileChangesMacro.TaskOps[T] = ??? - implicit val fileStampJsonFormatter: JsonFormat[Seq[(NioPath, FileStamp)]] = + given fileStampJsonFormatter: JsonFormat[Seq[(NioPath, FileStamp)]] = FileStamp.Formats.seqPathFileStampJsonFormatter - implicit val pathJsonFormatter: JsonFormat[Seq[NioPath]] = FileStamp.Formats.seqPathJsonFormatter - implicit val fileJsonFormatter: JsonFormat[Seq[File]] = FileStamp.Formats.seqFileJsonFormatter - implicit val singlePathJsonFormatter: JsonFormat[NioPath] = FileStamp.Formats.pathJsonFormatter - implicit val singleFileJsonFormatter: JsonFormat[File] = FileStamp.Formats.fileJsonFormatter + given pathJsonFormatter: JsonFormat[Seq[NioPath]] = FileStamp.Formats.seqPathJsonFormatter + given fileJsonFormatter: JsonFormat[Seq[File]] = FileStamp.Formats.seqFileJsonFormatter + given singlePathJsonFormatter: JsonFormat[NioPath] = FileStamp.Formats.pathJsonFormatter + given singleFileJsonFormatter: JsonFormat[File] = FileStamp.Formats.fileJsonFormatter // others object CompileOrder { diff --git a/server-test/src/test/scala/testpkg/BuildServerTest.scala b/server-test/src/test/scala/testpkg/BuildServerTest.scala index 857d3b25d..bdb06fa22 100644 --- a/server-test/src/test/scala/testpkg/BuildServerTest.scala +++ b/server-test/src/test/scala/testpkg/BuildServerTest.scala @@ -11,7 +11,7 @@ import sbt.internal.bsp.* import sbt.internal.langserver.ErrorCodes import sbt.IO import sbt.internal.protocol.JsonRpcRequestMessage -import sbt.internal.protocol.codec.JsonRPCProtocol.* +import sbt.internal.protocol.codec.JsonRPCProtocol.given import sjsonnew.JsonWriter import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter } @@ -24,7 +24,7 @@ import scala.concurrent.duration.* // starts svr using server-test/buildserver and perform custom server tests class BuildServerTest extends AbstractServerTest { - import sbt.internal.bsp.codec.JsonProtocol._ + import sbt.internal.bsp.codec.JsonProtocol.given override val testDirectory: String = "buildserver" private val idGen: AtomicInteger = new AtomicInteger(0) diff --git a/testing/src/main/scala/sbt/internal/testing/StatusFormats.scala b/testing/src/main/scala/sbt/internal/testing/StatusFormats.scala index a73ee9dab..b75bfef0d 100644 --- a/testing/src/main/scala/sbt/internal/testing/StatusFormats.scala +++ b/testing/src/main/scala/sbt/internal/testing/StatusFormats.scala @@ -13,7 +13,7 @@ import sbt.testing.Status import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder } trait StatusFormats { self: sjsonnew.BasicJsonProtocol => - implicit lazy val StatusFormat: JsonFormat[Status] = new JsonFormat[Status] { + given StatusFormat: JsonFormat[Status] = new JsonFormat[Status] { override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Status = { jsOpt match { case Some(js) => diff --git a/testing/src/main/scala/sbt/internal/testing/TestLogger.scala b/testing/src/main/scala/sbt/internal/testing/TestLogger.scala index 6e80abbc2..267849535 100644 --- a/testing/src/main/scala/sbt/internal/testing/TestLogger.scala +++ b/testing/src/main/scala/sbt/internal/testing/TestLogger.scala @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger object TestLogger { import sbt.protocol.testing.codec.JsonProtocol._ - implicit val testStringEventShowLines: ShowLines[TestStringEvent] = + given testStringEventShowLines: ShowLines[TestStringEvent] = ShowLines[TestStringEvent]({ case a: TestStringEvent => List(a.value) }) @@ -74,11 +74,11 @@ object TestLogger { global.registerStringCodec[TestStringEvent] def showNoLines[A] = ShowLines[A](_ => Nil) - implicit val showNoLinesTestInitEvent = showNoLines[TestInitEvent] - implicit val showNoLinesStartTestGroupEvent = showNoLines[StartTestGroupEvent] - implicit val showNoLinesTestItemEvent = showNoLines[TestItemEvent] - implicit val showNoLinesEndTestGroupEvent = showNoLines[EndTestGroupEvent] - implicit val showNoLinesTestCompleteEvent = showNoLines[TestCompleteEvent] + given ShowLines[TestInitEvent] = showNoLines[TestInitEvent] + given ShowLines[StartTestGroupEvent] = showNoLines[StartTestGroupEvent] + given ShowLines[TestItemEvent] = showNoLines[TestItemEvent] + given ShowLines[EndTestGroupEvent] = showNoLines[EndTestGroupEvent] + given ShowLines[TestCompleteEvent] = showNoLines[TestCompleteEvent] global.registerStringCodec[TestInitEvent] global.registerStringCodec[StartTestGroupEvent] global.registerStringCodec[TestItemEvent] diff --git a/util-cache/src/main/scala/sbt/internal/util/codec/ByteBufferFormats.scala b/util-cache/src/main/scala/sbt/internal/util/codec/ByteBufferFormats.scala index 7f7893742..a7dc8e641 100644 --- a/util-cache/src/main/scala/sbt/internal/util/codec/ByteBufferFormats.scala +++ b/util-cache/src/main/scala/sbt/internal/util/codec/ByteBufferFormats.scala @@ -17,6 +17,6 @@ trait ByteBufferFormats { self: BasicJsonProtocol => def strToByteBuffer(s: String): ByteBuffer = ByteBuffer.wrap(BUtil.fromHex(s)) - implicit lazy val byteBufferIsoString: IsoString[ByteBuffer] = + given byteBufferIsoString: IsoString[ByteBuffer] = IsoString.iso(byteBufferToStr, strToByteBuffer) } diff --git a/util-cache/src/main/scala/sbt/internal/util/codec/HashedVirtualRefFormats.scala b/util-cache/src/main/scala/sbt/internal/util/codec/HashedVirtualRefFormats.scala index d672f18dd..ad260098b 100644 --- a/util-cache/src/main/scala/sbt/internal/util/codec/HashedVirtualRefFormats.scala +++ b/util-cache/src/main/scala/sbt/internal/util/codec/HashedVirtualRefFormats.scala @@ -24,6 +24,6 @@ trait HashedVirtualFileRefFormats { self: BasicJsonProtocol => case _ => throw new RuntimeException(s"invalid HashedVirtualFileRefIsoString $s") } - implicit lazy val hashedVirtualFileRefIsoString: IsoString[HashedVirtualFileRef] = + given hashedVirtualFileRefIsoString: IsoString[HashedVirtualFileRef] = IsoString.iso(hashedVirtualFileRefToStr, strToHashedVirtualFileRef) } diff --git a/util-cache/src/main/scala/sbt/util/BasicCacheImplicits.scala b/util-cache/src/main/scala/sbt/util/BasicCacheImplicits.scala index c3101507d..8f8991258 100644 --- a/util-cache/src/main/scala/sbt/util/BasicCacheImplicits.scala +++ b/util-cache/src/main/scala/sbt/util/BasicCacheImplicits.scala @@ -26,6 +26,6 @@ trait BasicCacheImplicits extends HashedVirtualFileRefFormats { self: BasicJsonP def singleton[T](t: T): SingletonCache[T] = SingletonCache.basicSingletonCache(using asSingleton(t)) - implicit lazy val virtualFileRefIsoString: IsoString[VirtualFileRef] = + given virtualFileRefIsoString: IsoString[VirtualFileRef] = IsoString.iso(_.id, VirtualFileRef.of) } diff --git a/util-cache/src/main/scala/sbt/util/CacheStore.scala b/util-cache/src/main/scala/sbt/util/CacheStore.scala index 9d3ea5a0f..4a8c400b8 100644 --- a/util-cache/src/main/scala/sbt/util/CacheStore.scala +++ b/util-cache/src/main/scala/sbt/util/CacheStore.scala @@ -25,8 +25,7 @@ abstract class CacheStore extends Input with Output { } object CacheStore { - @deprecated("Create your own IsoString[JValue]", "1.4") - implicit lazy val jvalueIsoString: IsoString[JValue] = + @deprecated("Create your own IsoString[JValue]", "1.4") given jvalueIsoString: IsoString[JValue] = IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe) /** Returns file-based CacheStore using standard JSON converter. */ @@ -50,8 +49,7 @@ abstract class CacheStoreFactory { } object CacheStoreFactory { - @deprecated("Create your own IsoString[JValue]", "1.4") - implicit lazy val jvalueIsoString: IsoString[JValue] = + @deprecated("Create your own IsoString[JValue]", "1.4") given jvalueIsoString: IsoString[JValue] = IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe) /** Returns directory-based CacheStoreFactory using standard JSON converter. */ diff --git a/util-cache/src/main/scala/sbt/util/FileInfo.scala b/util-cache/src/main/scala/sbt/util/FileInfo.scala index db43aedc5..a5b65cc05 100644 --- a/util-cache/src/main/scala/sbt/util/FileInfo.scala +++ b/util-cache/src/main/scala/sbt/util/FileInfo.scala @@ -28,16 +28,16 @@ sealed trait PlainFileInfo extends FileInfo { def exists: Boolean } sealed trait HashModifiedFileInfo extends HashFileInfo with ModifiedFileInfo object HashFileInfo { - implicit val format: JsonFormat[HashFileInfo] = FileInfo.hash.format + given format: JsonFormat[HashFileInfo] = FileInfo.hash.format } object ModifiedFileInfo { - implicit val format: JsonFormat[ModifiedFileInfo] = FileInfo.lastModified.format + given format: JsonFormat[ModifiedFileInfo] = FileInfo.lastModified.format } object PlainFileInfo { - implicit val format: JsonFormat[PlainFileInfo] = FileInfo.exists.format + given format: JsonFormat[PlainFileInfo] = FileInfo.exists.format } object HashModifiedFileInfo { - implicit val format: JsonFormat[HashModifiedFileInfo] = FileInfo.full.format + given format: JsonFormat[HashModifiedFileInfo] = FileInfo.full.format } private final case class PlainFile(file: File, exists: Boolean) extends PlainFileInfo @@ -79,7 +79,7 @@ object FileInfo { * Stores byte arrays as hex encoded strings, but falls back to reading an array of integers, * which is how it used to be stored, if that fails. */ - implicit val byteArrayFormat: JsonFormat[Array[Byte]] = new JsonFormat[Array[Byte]] { + given byteArrayFormat: JsonFormat[Array[Byte]] = new JsonFormat[Array[Byte]] { override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Array[Byte] = { jsOpt match { case Some(js) => @@ -115,7 +115,7 @@ object FileInfo { object full extends Style { type F = HashModifiedFileInfo - implicit val format: JsonFormat[HashModifiedFileInfo] = new JsonFormat[HashModifiedFileInfo] { + given format: JsonFormat[HashModifiedFileInfo] = new JsonFormat[HashModifiedFileInfo] { def write[J](obj: HashModifiedFileInfo, builder: Builder[J]) = { builder.beginObject() builder.addField("file", obj.file.toString) @@ -145,7 +145,7 @@ object FileInfo { object hash extends Style { type F = HashFileInfo - implicit val format: JsonFormat[HashFileInfo] = new JsonFormat[HashFileInfo] { + given format: JsonFormat[HashFileInfo] = new JsonFormat[HashFileInfo] { def write[J](obj: HashFileInfo, builder: Builder[J]) = { builder.beginObject() builder.addField("file", obj.file.toString) @@ -177,7 +177,7 @@ object FileInfo { object lastModified extends Style { type F = ModifiedFileInfo - implicit val format: JsonFormat[ModifiedFileInfo] = new JsonFormat[ModifiedFileInfo] { + given format: JsonFormat[ModifiedFileInfo] = new JsonFormat[ModifiedFileInfo] { override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ModifiedFileInfo = jsOpt match { case Some(js) => @@ -229,7 +229,7 @@ object FileInfo { object exists extends Style { type F = PlainFileInfo - implicit val format: JsonFormat[PlainFileInfo] = new JsonFormat[PlainFileInfo] { + given format: JsonFormat[PlainFileInfo] = new JsonFormat[PlainFileInfo] { def write[J](obj: PlainFileInfo, builder: Builder[J]): Unit = { builder.beginObject() builder.addField("file", obj.file.toString) diff --git a/util-cache/src/test/scala/SingletonCacheSpec.scala b/util-cache/src/test/scala/SingletonCacheSpec.scala index ac4c5f33f..fc9fedde5 100644 --- a/util-cache/src/test/scala/SingletonCacheSpec.scala +++ b/util-cache/src/test/scala/SingletonCacheSpec.scala @@ -20,7 +20,7 @@ class SingletonCacheSpec extends AnyFlatSpec { case class ComplexType(val x: Int, y: String, z: List[Int]) object ComplexType { - implicit val format: JsonFormat[ComplexType] = + given format: JsonFormat[ComplexType] = new JsonFormat[ComplexType] { override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ComplexType = { jsOpt match { diff --git a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala index 1b27796f5..6e45ca181 100644 --- a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala +++ b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala @@ -61,7 +61,7 @@ class TrackedSpec extends AnyFlatSpec { "inputChangedW" should "not require the input to have a JsonReader instance" in { case class Input(v: Int) - implicit val writer = new JsonWriter[Input] { + given JsonWriter[Input] = new JsonWriter[Input] { override def write[J](obj: Input, builder: Builder[J]): Unit = builder.writeInt(obj.v) } @@ -139,7 +139,7 @@ class TrackedSpec extends AnyFlatSpec { "outputChangedW" should "not require the input to have a JsonReader instance" in { case class Input(v: Int) - implicit val writer = new JsonWriter[Input] { + given JsonWriter[Input] = new JsonWriter[Input] { override def write[J](obj: Input, builder: Builder[J]): Unit = builder.writeInt(obj.v) }