From d47e954bcb19f0c8e6e2fc5c7107441d8bec926d Mon Sep 17 00:00:00 2001 From: kenji yoshida <6b656e6a69@gmail.com> Date: Thu, 10 Oct 2024 02:49:20 +0900 Subject: [PATCH] sbt 2 --- .github/workflows/test.yml | 4 ++-- build.sbt | 21 ++++++++++++++++++- .../scala-2/xerial/sbt/SonatypeCompat.scala | 10 +++++++++ .../scala-3/xerial/sbt/SonatypeCompat.scala | 9 ++++++++ .../xerial/sbt/sonatype/SonatypeClient.scala | 2 +- .../xerial/sbt/sonatype/SonatypeService.scala | 6 +++--- 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/main/scala-2/xerial/sbt/SonatypeCompat.scala create mode 100644 src/main/scala-3/xerial/sbt/SonatypeCompat.scala diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7c3232..6062da4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: scalafmt - run: ./sbt scalafmtSbtCheck scalafmtCheckAll + run: ./sbt scalafmtSbtCheck "+ scalafmtCheckAll" test: name: Test strategy: @@ -40,4 +40,4 @@ jobs: distribution: "${{ matrix.distribution }}" java-version: "${{ matrix.java }}" - name: sbt scripted test - run: ./sbt compile scripted + run: ./sbt "+ Test/compile" "+ test" "+ scripted" diff --git a/build.sbt b/build.sbt index a852758..8e2f18f 100755 --- a/build.sbt +++ b/build.sbt @@ -14,6 +14,17 @@ * limitations under the License. */ +crossScalaVersions += "3.3.4" + +pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + case "2.12" => + (pluginCrossBuild / sbtVersion).value + case _ => + "2.0.0-M2" + } +} + addCommandAlias("format", "scalafmtAll; scalafmtSbt") Global / onChangedBuildSource := ReloadOnSourceChanges @@ -61,7 +72,15 @@ lazy val sbtSonatype = testFrameworks += new TestFramework("wvlet.airspec.Framework"), buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion), buildInfoPackage := "org.xerial.sbt.sonatype", - scalacOptions ++= Seq("-Ywarn-unused-import", "-nowarn"), + scalacOptions ++= Seq("-nowarn"), + scalacOptions += { + scalaBinaryVersion.value match { + case "2.12" => + "-Ywarn-unused-import" + case _ => + "-Wunused:imports" + } + }, libraryDependencies ++= Seq( "org.sonatype.spice.zapper" % "spice-zapper" % versions.sonatypeZapperClient, "org.wvlet.airframe" %% "airframe-http" % versions.airframe diff --git a/src/main/scala-2/xerial/sbt/SonatypeCompat.scala b/src/main/scala-2/xerial/sbt/SonatypeCompat.scala new file mode 100644 index 0000000..6a8b58a --- /dev/null +++ b/src/main/scala-2/xerial/sbt/SonatypeCompat.scala @@ -0,0 +1,10 @@ +package xerial.sbt.sonatype + +import scala.reflect.runtime.universe.TypeTag +import wvlet.airframe.codec.MessageCodec +import wvlet.airframe.codec.MessageCodecFactory + +private[sonatype] trait SonatypeCompat { self: SonatypeService => + implicit def codecInstance[A: TypeTag]: MessageCodec[A] = + MessageCodecFactory.defaultFactoryForJSON.of[A] +} diff --git a/src/main/scala-3/xerial/sbt/SonatypeCompat.scala b/src/main/scala-3/xerial/sbt/SonatypeCompat.scala new file mode 100644 index 0000000..7598c4b --- /dev/null +++ b/src/main/scala-3/xerial/sbt/SonatypeCompat.scala @@ -0,0 +1,9 @@ +package xerial.sbt.sonatype + +import wvlet.airframe.codec.MessageCodec +import wvlet.airframe.codec.MessageCodecFactory + +private[sonatype] trait SonatypeCompat { self: SonatypeService => + inline given codecInstance[A]: MessageCodec[A] = + MessageCodecFactory.defaultFactoryForJSON.of[A] +} diff --git a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala index 06e453f..ede6dba 100644 --- a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala +++ b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala @@ -124,7 +124,7 @@ class SonatypeClient( // init * (multiplier ^ n) = max // n = log(max / init) / log(multiplier) val retryCountUntilMaxInterval = (math.log(maxInterval.toDouble / initInterval) / math.log(1.5)).toInt.max(1) - val numRetry = (timeoutMillis / maxInterval).ceil.toInt + val numRetry = (timeoutMillis / maxInterval).toDouble.ceil.toInt Retry.withBackOff( maxRetry = retryCountUntilMaxInterval + numRetry, initialIntervalMillis = initInterval, diff --git a/src/main/scala/xerial/sbt/sonatype/SonatypeService.scala b/src/main/scala/xerial/sbt/sonatype/SonatypeService.scala index 3b1d36e..aa089c0 100644 --- a/src/main/scala/xerial/sbt/sonatype/SonatypeService.scala +++ b/src/main/scala/xerial/sbt/sonatype/SonatypeService.scala @@ -4,7 +4,7 @@ import java.io.File import org.xerial.sbt.sonatype.BuildInfo import sbt.io.IO import scala.util.Try -import wvlet.airframe.codec.MessageCodecFactory +import wvlet.airframe.codec.MessageCodec import wvlet.log.LogSupport import xerial.sbt.sonatype.SonatypeClient.* import xerial.sbt.sonatype.SonatypeException.{MISSING_PROFILE, MISSING_STAGING_PROFILE, MULTIPLE_TARGETS, UNKNOWN_STAGE} @@ -17,6 +17,7 @@ class SonatypeService( val profileName: String, cacheToken: Option[String] ) extends LogSupport + with SonatypeCompat with AutoCloseable { import SonatypeService.* @@ -121,8 +122,7 @@ class SonatypeService( myProfiles } - private def withCache[A: scala.reflect.runtime.universe.TypeTag](label: String, fileName: String, a: => A): A = { - val codec = MessageCodecFactory.defaultFactoryForJSON.of[A] + private def withCache[A](label: String, fileName: String, a: => A)(implicit codec: MessageCodec[A]): A = { val cachedir = (Vector("sbt", "sonatype") ++ cacheToken).mkString("-") val cacheRoot = new File(s"target/${cachedir}") val cacheFile = new File(cacheRoot, fileName)