diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffade04d..c0f1b20a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 +test-skip-windows +scripted shell: bash checks: name: Scalafmt diff --git a/bin/test-release.sh b/bin/test-release.sh index ff2a97c1..ef261b4c 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -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" diff --git a/build.sbt b/build.sbt index 7a4ec6e2..b53b36a6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,4 @@ +import org.msgpack.value.NilValue inThisBuild( List( Test / parallelExecution := false, @@ -44,29 +45,57 @@ 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" -// 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" +scalaVersion := scala212 +crossScalaVersions := Seq(scala212, scala3) + +pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + // keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049 + 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", + "-target:jvm-1.8", + "-Xfatal-warnings", + "-Xlint" + ) + case _ => + Nil + } +} // Scripted enablePlugins(ScriptedPlugin) diff --git a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala index f2ed4605..b393b660 100644 --- a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala +++ b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala @@ -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) } @@ -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) } diff --git a/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala b/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala index a088b278..3a63af1b 100644 --- a/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala +++ b/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala @@ -25,7 +25,7 @@ class SemanticRuleValidator(ifNotFound: SemanticdbNotFound) { invalidArguments.foreach { invalidArgument => errors += invalidArgument.getMessage } - errors + errors.toSeq } } } diff --git a/src/main/scala/scalafix/sbt/ScalafixEnable.scala b/src/main/scala/scalafix/sbt/ScalafixEnable.scala index 8e071a57..46fd8687 100644 --- a/src/main/scala/scalafix/sbt/ScalafixEnable.scala +++ b/src/main/scala/scalafix/sbt/ScalafixEnable.scala @@ -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) diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index efd6d978..676fb9f9 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -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 => @@ -264,7 +264,7 @@ object ScalafixPlugin extends AutoPlugin { } }, ivyConfigurations += ScalafixConfig, - scalafixAll := scalafixAllInputTask.evaluated, + scalafixAll := scalafixAllInputTask().evaluated, (scalafixScalaBinaryVersion: @nowarn) := scalaVersion.value.split('.').take(2).mkString(".") ) @@ -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 } @@ -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 @@ -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) } @@ -696,7 +696,8 @@ object ScalafixPlugin extends AutoPlugin { } } - val ruleTargetDiffs = interface.rulesThatWillRun + val ruleTargetDiffs = interface + .rulesThatWillRun() .map(rule => diffTargets(rule.name) _) .toList accumulateAndRunForStaleTargets(ruleTargetDiffs)