Skip to content

Commit

Permalink
ensure/document support of Scala 3 in ScalafixTestkitPlugin
Browse files Browse the repository at this point in the history
* setup cross-building like https://github.com/scalacenter/scalafix.g8
* rely on scalafix-testkit to add semanticdbTargetRoot to classpath
  based on scalacOptions
  • Loading branch information
github-brice-jaglin committed May 17, 2021
1 parent 429e618 commit 6425737
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 22 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.9.27+52-6c9eeec9-SNAPSHOT"
def scalafixVersion: String = "0.9.27+78-f41dec8f-SNAPSHOT"

val all = List(
"org.eclipse.jgit" % "org.eclipse.jgit" % "5.11.1.202105131744-r",
Expand Down
18 changes: 1 addition & 17 deletions src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ object ScalafixTestkitPlugin extends AutoPlugin {
scalafixTestkitInputScalaVersion := scalaVersion.value,
resourceGenerators.in(Test) += Def.task {
val props = new java.util.Properties()
val targetrootClasspath = semanticdbOption(
scalafixTestkitInputScalacOptions.value,
"targetroot"
).map(file).toSeq
val values = Map[String, Seq[File]](
"sourceroot" ->
List(baseDirectory.in(ThisBuild).value),
"inputClasspath" ->
(scalafixTestkitInputClasspath.value
.map(_.data) ++ targetrootClasspath),
scalafixTestkitInputClasspath.value.map(_.data),
"inputSourceDirectories" ->
scalafixTestkitInputSourceDirectories.value,
"outputSourceDirectories" ->
Expand All @@ -71,15 +66,4 @@ object ScalafixTestkitPlugin extends AutoPlugin {
List(out)
}
)

private def semanticdbOption(
scalacOptions: Seq[String],
name: String
): Option[String] = {
val flag = s"-P:semanticdb:$name:"
scalacOptions
.filter(_.startsWith(flag))
.lastOption
.map(_.stripPrefix(flag))
}
}
1 change: 0 additions & 1 deletion src/sbt-test/sbt-1.3/testkit/project/build.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import _root_.scalafix.sbt.{BuildInfo => Versions}

lazy val scala3InputOutputVersion = "3.0.0"

inThisBuild(
List(
scalaVersion := Versions.scala212,
crossScalaVersions := List(
Versions.scala213,
Versions.scala212,
Versions.scala211
),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
)

crossScalaVersions := Nil

val rules = project
.disablePlugins(ScalafixPlugin)
.settings(
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % Versions.scalafixVersion
)

lazy val input = project
.settings(
crossScalaVersions := List(scala3InputOutputVersion)
)

lazy val output = project
.settings(
crossScalaVersions := List(scala3InputOutputVersion)
)

lazy val testsScala3 = project
.aggregate(tests)
.settings(
crossScalaVersions := List(scala3InputOutputVersion)
)

lazy val tests = project
.settings(
Expand All @@ -25,7 +46,8 @@ lazy val tests = project
scalafixTestkitOutputSourceDirectories :=
sourceDirectories.in(output, Compile).value,
scalafixTestkitInputSourceDirectories :=
sourceDirectories.in(input, Compile).value,
// https://github.com/sbt/sbt/pull/6511
sourceDirectories.in(input, Compile).value.distinct,
scalafixTestkitInputClasspath :=
fullClasspath.in(input, Compile).value,
scalafixTestkitInputScalacOptions :=
Expand All @@ -34,5 +56,5 @@ lazy val tests = project
scalaVersion.in(input, Compile).value,
mainClass in (Test, run) := Some("fix.IntputOutputSuite")
)
.dependsOn(input, rules)
.dependsOn(rules)
.enablePlugins(ScalafixTestkitPlugin)
1 change: 1 addition & 0 deletions src/sbt-test/sbt-1.5/testkit/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-> tests/test
> tests/test:run --save-expect
> tests/test
> +test

0 comments on commit 6425737

Please sign in to comment.