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 Feb 16, 2025
1 parent 037b18d commit 8730207
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 59 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
apps: sbt
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 @@ -26,7 +26,7 @@ jobs:
apps: sbt
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 @@ -38,7 +38,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 @@ -50,7 +50,7 @@ jobs:
apps: sbt
jvm: temurin:21
- run: rm -rf src/sbt-test/skip-java17+
- run: sbt test scripted
- run: sbt +test +scripted
jdk23:
name: JDK23 tests
runs-on: ubuntu-latest
Expand All @@ -61,7 +61,7 @@ jobs:
apps: sbt
jvm: temurin:23
- 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 @@ -72,7 +72,7 @@ jobs:
apps: sbt
- 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
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-SNAPSHOT \
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"
56 changes: 40 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,58 @@ libraryDependencies ++= List(
"org.scalatest" %% "scalatest" % "3.2.19" % Test
)

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

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-SNAPSHOT"
}
}

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",
"-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 @@ -113,10 +113,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 @@ -160,21 +160,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
30 changes: 12 additions & 18 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import coursierapi.Repository
import sbt.KeyRanks.Invisible
import sbt.Keys.*
import sbt.*
import sbt.Result.*
import sbt.internal.sbtscalafix.JLineAccess
import sbt.internal.util.complete.Parser
import sbt.plugins.JvmPlugin
Expand Down Expand Up @@ -243,7 +244,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 @@ -265,7 +266,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 @@ -352,7 +353,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 All @@ -376,13 +377,8 @@ object ScalafixPlugin extends AutoPlugin {

}

private def scalafixAllInputTask(): Def.Initialize[InputTask[Unit]] = {
// workaround https://github.com/sbt/sbt/issues/3572 by invoking directly what Def.inputTaskDyn would via macro
InputTask.createDyn(InputTask.initParserAsInput(scalafixParser))(
Def.task(shellArgs =>
scalafixAllTask(shellArgs, thisProject.value, resolvedScoped.value)
)
)
private def scalafixAllInputTask(): Def.Initialize[InputTask[Unit]] = Def.inputTaskDyn { // needs a compat for sbt 1.x
scalafixAllTask(scalafixParser.parsed, thisProject.value, resolvedScoped.value)
}

private def scalafixAllTask(
Expand Down Expand Up @@ -420,11 +416,8 @@ object ScalafixPlugin extends AutoPlugin {

private def scalafixInputTask(
config: Configuration
): Def.Initialize[InputTask[Unit]] = {
// workaround https://github.com/sbt/sbt/issues/3572 by invoking directly what Def.inputTaskDyn would via macro
InputTask.createDyn(InputTask.initParserAsInput(scalafixParser))(
Def.task(shellArgs => scalafixTask(shellArgs, config))
)
): Def.Initialize[InputTask[Unit]] = Def.inputTaskDyn { // needs a compat for sbt 1.x
scalafixTask(scalafixParser.parsed, config)
}

private def scalafixTask(
Expand Down Expand Up @@ -633,7 +626,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 @@ -673,7 +666,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 @@ -697,7 +690,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 8730207

Please sign in to comment.