Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error reporting when semanticdb-scalac is not found #369

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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