Skip to content

Commit

Permalink
sbt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Oct 9, 2024
1 parent b36431f commit d47e954
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: scalafmt
run: ./sbt scalafmtSbtCheck scalafmtCheckAll
run: ./sbt scalafmtSbtCheck "+ scalafmtCheckAll"
test:
name: Test
strategy:
Expand All @@ -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"
21 changes: 20 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/main/scala-2/xerial/sbt/SonatypeCompat.scala
Original file line number Diff line number Diff line change
@@ -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]
}
9 changes: 9 additions & 0 deletions src/main/scala-3/xerial/sbt/SonatypeCompat.scala
Original file line number Diff line number Diff line change
@@ -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]
}
2 changes: 1 addition & 1 deletion src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/xerial/sbt/sonatype/SonatypeService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -17,6 +17,7 @@ class SonatypeService(
val profileName: String,
cacheToken: Option[String]
) extends LogSupport
with SonatypeCompat
with AutoCloseable {
import SonatypeService.*

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d47e954

Please sign in to comment.