Skip to content

Commit

Permalink
Merge pull request #369 from bjaglin/actionnable-error
Browse files Browse the repository at this point in the history
better error reporting when semanticdb-scalac is not found
  • Loading branch information
bjaglin authored Sep 11, 2023
2 parents 28a5665 + 4ced96a commit e3c386d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt._

object Dependencies {
val x = List(1) // scalafix:ok
def scalafixVersion: String = "0.11.0+118-1b88e1f8-SNAPSHOT"
def scalafixVersion: String = "0.11.0+132-89b843d2-SNAPSHOT"

val all = List(
"org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.2.202306221912-r",
Expand Down
32 changes: 32 additions & 0 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scalafix.internal.sbt._

import scala.collection.JavaConverters.collectionAsScalaIterableConverter
import scala.util.control.NoStackTrace
import sbt.librarymanagement.ResolveException

object ScalafixPlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements
Expand Down Expand Up @@ -164,6 +165,37 @@ object ScalafixPlugin extends AutoPlugin {
SettingKey[Boolean]("bspEnabled") := false
)
),
update := {
object SemanticdbScalac {
def unapply(id: ModuleID): Option[String] =
if (
id.organization == scalafixSemanticdb.organization &&
id.name.startsWith(scalafixSemanticdb.name)
) Some(id.revision)
else None
}

update.result.value match {
case Value(v) => v
case Inc(inc: Incomplete) =>
Incomplete.allExceptions(inc).toList match {
case (resolveException: ResolveException) :: Nil =>
resolveException.failed.headOption match {
case Some(SemanticdbScalac(rev)) =>
val scalaV = scalaVersion.value
val msg = s"The SemanticDB scalac plugin version ${rev} set up " +
"via `semanticdbVersion` does follow the version recommended " +
"for Scalafix, but is not supported for the outdated Scala " +
s"version ${scalaV}. Please upgrade to a more recent Scala " +
"patch version or uninstall sbt-scalafix."
throw inc.copy(message = Some(msg))
case _ =>
}
case _ =>
}
throw inc
}
},
ivyConfigurations += ScalafixConfig,
scalafixAll := scalafixAllInputTask.evaluated
)
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbt-1.5/testkit/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lazy val scala3Version = "3.0.0"

inThisBuild(
List(
scalaVersion := V.scala212, // don't let tests project fall back to sbt's old default
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
// need for sbt <1.7.0 as includePluginResolvers has no effect, see https://github.com/sbt/sbt/pull/6853
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/basic/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inThisBuild(
List(
scalaVersion := "2.12.14",
scalaVersion := "2.12.18",
libraryDependencies ++= List(
"org.scalameta" %% "testkit" % "4.3.10" % Test,
"org.scalameta" %% "munit" % "0.7.9" % Test,
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/inconfig/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inThisBuild(
List(
scalaVersion := "2.12.14",
scalaVersion := "2.12.18",
libraryDependencies ++= List(
"org.scalameta" %% "testkit" % "4.3.10" % Test,
"org.scalameta" %% "munit" % "0.7.9" % Test,
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/root-validation/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inThisBuild(
List(
scalaVersion := "2.12.14"
scalaVersion := "2.12.18"
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-scalafix/semanticdb-enabled/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inThisBuild(
List(
scalaVersion := "2.12.14",
scalaVersion := "2.12.18",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
Expand Down
22 changes: 22 additions & 0 deletions src/sbt-test/sbt-scalafix/unavailable-semanticdb-scalac/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
inThisBuild(
List(
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalaVersion := "2.13.7" // last semanticdb-scalac published for that scala version is 4.8.4
)
)

lazy val checkLogs =
taskKey[Unit]("Check presence of call to action in update logs")

checkLogs := {
val taskStreams = (update / streams).value
val reader = taskStreams.readText(taskStreams.key)
val logLines = Stream
.continually(reader.readLine())
.takeWhile(_ != null)
.force
assert(
logLines.exists(_.contains("Please upgrade to a more recent Scala patch version or uninstall sbt-scalafix"))
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-scalafix/unavailable-semanticdb-scalac/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-> scalafix
> checkLogs
2 changes: 1 addition & 1 deletion src/sbt-test/skip-java17/scalafixResolvers/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scalaVersion := "2.12.7"
scalaVersion := "2.12.18"

TaskKey[Unit]("check") := {
val expectedRepositories: Seq[String] = Seq(
Expand Down

0 comments on commit e3c386d

Please sign in to comment.