Skip to content

Commit

Permalink
cross-build to sbt 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Oct 5, 2024
1 parent d2c99b3 commit 50acf94
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 46 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
jvm: temurin:8
- run: rm -rf src/sbt-test/skip-sbt1.4
- run: sbt test scripted
- run: sbt +test +scripted
jdk11:
name: JDK11 tests
runs-on: ubuntu-latest
Expand All @@ -24,7 +24,7 @@ jobs:
with:
jvm: temurin:11
- run: rm -rf src/sbt-test/skip-sbt1.4
- run: sbt test scripted
- run: sbt +test +scripted
jdk17:
name: JDK17 tests
runs-on: ubuntu-latest
Expand All @@ -35,7 +35,7 @@ jobs:
jvm: temurin:17
- run: rm -rf src/sbt-test/skip-java17+
- run: rm -rf src/sbt-test/skip-sbt1.4
- run: sbt test scripted
- run: sbt +test +scripted

jdk21:
name: JDK21 tests
Expand All @@ -46,7 +46,7 @@ jobs:
with:
jvm: temurin:21
- run: rm -rf src/sbt-test/skip-java17+
- run: sbt test scripted
- run: sbt +test +scripted
windows:
name: Windows tests
runs-on: windows-latest
Expand All @@ -55,7 +55,7 @@ jobs:
- uses: coursier/setup-action@v1
- run: rm -r -fo src\sbt-test\skip-sbt1.4
- run: rm -r -fo src\sbt-test\skip-windows
- run: sbt test-skip-windows scripted
- run: sbt +"testOnly -- -l SkipWindows" +scripted
shell: bash
checks:
name: Scalafmt
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: coursier/setup-action@v1
with:
jvm: temurin:8
- uses: olafurpg/setup-gpg@v3
- run: git fetch --unshallow
- name: Publish ${{ github.ref }}
Expand Down
4 changes: 4 additions & 0 deletions bin/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ version=$1
cs resolve \
--sbt-version 1.0 \
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"

cs resolve \
--sbt-version 2.0.0-M2 \
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"
57 changes: 41 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ developers := List(
)
)

commands += Command.command("test-skip-windows") { s =>
"testOnly -- -l SkipWindows" ::
s
}

// Dependencies
resolvers ++= Resolver.sonatypeOssRepos("public")
libraryDependencies ++= Dependencies.all
Expand All @@ -44,29 +39,59 @@ libraryDependencies ++= List(
"org.scalatest" %% "scalatest" % "3.2.19" % Test
)

scalaVersion := "2.12.20"
lazy val scala212 = "2.12.20"
lazy val scala3 = "3.3.4"

scalaVersion := scala212
crossScalaVersions := Seq(scala212, scala3)

// keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049
pluginCrossBuild / sbtVersion := "1.4.0"
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" =>
"1.4.0"
case _ =>
"2.0.0-M2"
}
}

scriptedSbt := {
val jdk = System.getProperty("java.specification.version").toDouble

if (jdk >= 21)
"1.9.0" // first release that supports JDK21
Ordering[String].max(
(pluginCrossBuild / sbtVersion).value,
"1.9.0" // first release that supports JDK21
)
else
(pluginCrossBuild / sbtVersion).value
}

libraryDependencies += compilerPlugin(scalafixSemanticdb)

scalacOptions ++= List("-Ywarn-unused", "-Yrangepos")
libraryDependencies ++= {
scalaBinaryVersion.value match {
case "2.12" =>
List(compilerPlugin(scalafixSemanticdb))
case _ =>
Nil
}
}

scalacOptions ++= List(
"-target:jvm-1.8",
"-Xfatal-warnings",
"-Xlint"
)
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" =>
List(
"-Ywarn-unused",
"-Yrangepos",
"-Xfatal-warnings",
"-Xlint"
)
case _ =>
List(
"-Wunused:all",
"-Werror"
)
}
}

// Scripted
enablePlugins(ScriptedPlugin)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Arg {
.map(uri => java.nio.file.Paths.get(uri).toFile)
.flatMap {
case classDirectory if classDirectory.isDirectory =>
classDirectory.**(RegularFileFilter).get
classDirectory.**(RegularFileFilter).get()
case jar =>
Seq(jar)
}
Expand Down Expand Up @@ -109,10 +109,10 @@ class ScalafixInterface private (
scalafixArguments.run().toSeq

def availableRules(): Seq[ScalafixRule] =
scalafixArguments.availableRules().asScala
scalafixArguments.availableRules().asScala.toSeq

def rulesThatWillRun(): Seq[ScalafixRule] =
try scalafixArguments.rulesThatWillRun().asScala
try scalafixArguments.rulesThatWillRun().asScala.toSeq
catch {
case e: ScalafixException => throw new InvalidArgument(e.getMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SemanticRuleValidator(ifNotFound: SemanticdbNotFound) {
invalidArguments.foreach { invalidArgument =>
errors += invalidArgument.getMessage
}
errors
errors.toSeq
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/main/scala/scalafix/sbt/ScalafixEnable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ object ScalafixEnable {
} else {
val latestAvailable =
tail.lastOption.getOrElse(earliestAvailable)
Seq(
semanticdbVersion := {
val v = latestAvailable.toString
sLog.value.info(
s"Setting semanticdbVersion to $v in project " +
s"${project.ref.project} since the version " +
s"${recommendedSemanticdbV} tracked by scalafix " +
s"${BuildInfo.scalafixVersion} is no longer " +
s"published for scala " +
s"${project.scalaVersion0.toString} - " +
s"consider bumping scala"
)
v
}
)
Seq(
semanticdbVersion := {
val v = latestAvailable.toString
sLog.value.info(
s"Setting semanticdbVersion to $v in project " +
s"${project.ref.project} since the version " +
s"${recommendedSemanticdbV} tracked by scalafix " +
s"${BuildInfo.scalafixVersion} is no longer " +
s"published for scala " +
s"${project.scalaVersion0.toString} - " +
s"consider bumping scala"
)
v
}
)
}
}
} :+ (semanticdbEnabled := true)
Expand Down
13 changes: 7 additions & 6 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ object ScalafixPlugin extends AutoPlugin {
}

update.result.value match {
case Value(v) => v
case Value(v: UpdateReport) => v
case Inc(inc: Incomplete) =>
Incomplete.allExceptions(inc).toList match {
case (resolveException: ResolveException) :: Nil =>
Expand All @@ -264,7 +264,7 @@ object ScalafixPlugin extends AutoPlugin {
}
},
ivyConfigurations += ScalafixConfig,
scalafixAll := scalafixAllInputTask.evaluated,
scalafixAll := scalafixAllInputTask().evaluated,
(scalafixScalaBinaryVersion: @nowarn) :=
scalaVersion.value.split('.').take(2).mkString(".")
)
Expand Down Expand Up @@ -351,7 +351,7 @@ object ScalafixPlugin extends AutoPlugin {
val invocationDepsExternal = parsed.map(_.dependency)
val projectDepsInternal0 = projectDepsInternal.filter {
case directory if directory.isDirectory =>
directory.**(AllPassFilter).get.exists(_.isFile)
directory.**(AllPassFilter).get().exists(_.isFile)
case file if file.isFile => true
case _ => false
}
Expand Down Expand Up @@ -632,7 +632,7 @@ object ScalafixPlugin extends AutoPlugin {
}

private lazy val checkIfTriggeredSectionExists: Boolean = {
val confInArgs = interface.args
val confInArgs: Option[Path] = interface.args
.collect { case Arg.Config(conf) => conf }
.flatten
.lastOption
Expand Down Expand Up @@ -672,7 +672,7 @@ object ScalafixPlugin extends AutoPlugin {
Tracked.diffInputs(
streams.cacheDirectory / "targets-by-rule" / rule,
cachingStyle
)(targets) { changeReport: ChangeReport[File] =>
)(targets) { (changeReport: ChangeReport[File]) =>
doForStaleTargets(changeReport.modified -- changeReport.removed)
}

Expand All @@ -696,7 +696,8 @@ object ScalafixPlugin extends AutoPlugin {
}
}

val ruleTargetDiffs = interface.rulesThatWillRun
val ruleTargetDiffs = interface
.rulesThatWillRun()
.map(rule => diffTargets(rule.name) _)
.toList
accumulateAndRunForStaleTargets(ruleTargetDiffs)
Expand Down

0 comments on commit 50acf94

Please sign in to comment.