Skip to content

Commit 4060b04

Browse files
committed
cross-build against sbt 2.0.0-M4
1 parent 2d04dfd commit 4060b04

File tree

34 files changed

+391
-308
lines changed

34 files changed

+391
-308
lines changed

.github/workflows/ci.yml

+24-55
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,31 @@ on:
55
- main
66
pull_request:
77
jobs:
8-
jdk8:
9-
name: JDK8 tests
8+
ubuntu:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
jvm: ["8", "11", "17", "21", "23"]
13+
scala: ["2.12", "3.6"]
14+
name: Ubuntu / JDK${{ matrix.jvm }} / Scala ${{ matrix.scala }}
1015
runs-on: ubuntu-latest
1116
steps:
1217
- uses: actions/checkout@v4
1318
- uses: coursier/setup-action@v1
1419
with:
1520
apps: sbt
16-
jvm: temurin:8
17-
- run: rm -rf src/sbt-test/skip-sbt1.4
18-
- run: sbt test scripted
19-
jdk11:
20-
name: JDK11 tests
21-
runs-on: ubuntu-latest
22-
steps:
23-
- uses: actions/checkout@v4
24-
- uses: coursier/setup-action@v1
25-
with:
26-
apps: sbt
27-
jvm: temurin:11
28-
- run: rm -rf src/sbt-test/skip-sbt1.4
29-
- run: sbt test scripted
30-
jdk17:
31-
name: JDK17 tests
32-
runs-on: ubuntu-latest
33-
steps:
34-
- uses: actions/checkout@v4
35-
- uses: coursier/setup-action@v1
36-
with:
37-
apps: sbt
38-
jvm: temurin:17
39-
- run: rm -rf src/sbt-test/skip-java17+
40-
- run: rm -rf src/sbt-test/skip-sbt1.4
41-
- run: sbt test scripted
42-
43-
jdk21:
44-
name: JDK21 tests
45-
runs-on: ubuntu-latest
46-
steps:
47-
- uses: actions/checkout@v4
48-
- uses: coursier/setup-action@v1
49-
with:
50-
apps: sbt
51-
jvm: temurin:21
52-
- run: rm -rf src/sbt-test/skip-java17+
53-
- run: sbt test scripted
54-
jdk23:
55-
name: JDK23 tests
56-
runs-on: ubuntu-latest
57-
steps:
58-
- uses: actions/checkout@v4
59-
- uses: coursier/setup-action@v1
60-
with:
61-
apps: sbt
62-
jvm: temurin:23
63-
- run: rm -rf src/sbt-test/skip-java17+
64-
- run: sbt test scripted
21+
jvm: temurin:${{ matrix.jvm }}
22+
- if: matrix.jvm == '8' || matrix.jvm == '11' || matrix.jvm == '17'
23+
run: rm -rf src/sbt-test/skip-sbt1.4
24+
- if: matrix.jvm == '17' || matrix.jvm == '21' || matrix.jvm == '23'
25+
run: rm -rf src/sbt-test/skip-java17+
26+
- run: sbt ++${{ matrix.scala }} test scripted
6527
windows:
66-
name: Windows tests
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
scala: ["2.12", "3.6"]
32+
name: Windows / Scala ${{ matrix.scala }}
6733
runs-on: windows-latest
6834
steps:
6935
- uses: actions/checkout@v4
@@ -72,12 +38,15 @@ jobs:
7238
apps: sbt
7339
- run: rm -r -fo src\sbt-test\skip-sbt1.4
7440
- run: rm -r -fo src\sbt-test\skip-windows
75-
- run: sbt test-skip-windows scripted
41+
- run: sbt ++${{ matrix.scala }} test-skip-windows scripted
7642
shell: bash
77-
checks:
78-
name: Scalafmt
43+
formatting:
44+
name: Scalafmt and Scalafix
7945
runs-on: ubuntu-latest
8046
steps:
8147
- uses: actions/checkout@v4
8248
- uses: coursier/setup-action@v1
49+
with:
50+
apps: sbt
8351
- run: ./bin/scalafmt --test
52+
- run: sbt scalafixAll --check

.scalafix.conf

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
rules = [
2-
DisableSyntax
3-
]
4-
DisableSyntax.keywords = [
5-
var
6-
null
2+
ExplicitResultTypes,
3+
OrganizeImports,
4+
RemoveUnused
75
]
6+
7+
OrganizeImports {
8+
groups = [
9+
"re:javax?\\."
10+
"scala."
11+
"sbt."
12+
"*"
13+
]
14+
targetDialect = Scala3
15+
}
16+
17+
RemoveUnused {
18+
imports = false
19+
}

bin/test-release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ version=$1
66
cs resolve \
77
--sbt-version 1.0 \
88
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"
9+
10+
cs resolve \
11+
--sbt-version 2.0.0-SNAPSHOT \
12+
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"

build.sbt

+41-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
inThisBuild(
2-
List(
3-
Test / parallelExecution := false,
4-
scalafixDependencies := List(
5-
// Custom rule published to Maven Central https://github.com/scalacenter/example-scalafix-rule
6-
"ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"
7-
)
8-
)
1+
// dogfooding
2+
semanticdbEnabled := true
3+
scalafixDependencies := List(
4+
// Custom rule published to Maven Central https://github.com/scalacenter/example-scalafix-rule
5+
"ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"
96
)
10-
onLoadMessage := s"Welcome to sbt-scalafix ${version.value}"
7+
8+
onLoadMessage := s"Welcome to sbt-scalafix ${version.value} built with Scala ${scalaVersion.value}"
119
moduleName := "sbt-scalafix"
1210

1311
// Publish settings
@@ -44,29 +42,51 @@ libraryDependencies ++= List(
4442
"org.scalatest" %% "scalatest" % "3.2.19" % Test
4543
)
4644

47-
scalaVersion := "2.12.20"
45+
lazy val scala212 = "2.12.20"
46+
lazy val scala3 =
47+
"3.6.4" // update also in bin/test-release.sh & .github/workflows/ci.yml
48+
49+
scalaVersion := scala212
50+
crossScalaVersions := Seq(scala212, scala3)
4851

4952
// keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049
50-
pluginCrossBuild / sbtVersion := "1.4.0"
53+
pluginCrossBuild / sbtVersion := {
54+
scalaBinaryVersion.value match {
55+
case "2.12" =>
56+
"1.4.0"
57+
case _ =>
58+
"2.0.0-SNAPSHOT"
59+
}
60+
}
5161

5262
scriptedSbt := {
5363
val jdk = System.getProperty("java.specification.version").toDouble
5464

5565
if (jdk >= 21)
56-
"1.9.0" // first release that supports JDK21
66+
Ordering[String].max(
67+
(pluginCrossBuild / sbtVersion).value,
68+
"1.9.0" // first release that supports JDK21
69+
)
5770
else
5871
(pluginCrossBuild / sbtVersion).value
5972
}
6073

61-
libraryDependencies += compilerPlugin(scalafixSemanticdb)
62-
63-
scalacOptions ++= List("-Ywarn-unused", "-Yrangepos")
64-
65-
scalacOptions ++= List(
66-
"-target:jvm-1.8",
67-
"-Xfatal-warnings",
68-
"-Xlint"
69-
)
74+
scalacOptions ++= {
75+
scalaBinaryVersion.value match {
76+
case "2.12" =>
77+
List(
78+
"-Ywarn-unused",
79+
"-Xlint",
80+
"-Xfatal-warnings"
81+
)
82+
case _ =>
83+
List(
84+
"-Wunused:all",
85+
"-Werror",
86+
"-Wconf:msg=scalafixScalaBinaryVersion.*deprecated:silent"
87+
)
88+
}
89+
}
7090

7191
// Scripted
7292
enablePlugins(ScriptedPlugin)

project/Dependencies.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ object Dependencies {
77
val all = List(
88
"org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.3.202401111512-r",
99
"ch.epfl.scala" % "scalafix-interfaces" % scalafixVersion,
10-
"io.get-coursier" % "interface" % "1.0.28"
10+
"io.get-coursier" % "interface" % "1.0.28",
11+
"org.scala-lang.modules" %% "scala-collection-compat" % "2.13.0"
1112
)
1213
}

project/plugins.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resolvers ++= Resolver.sonatypeOssRepos("public")
22
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2")
33

4-
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
4+
// dogfooding
55
Compile / unmanagedSourceDirectories ++= {
66
val root = (ThisBuild / baseDirectory).value.getParentFile / "src" / "main"
77
List(
88
root / "scala",
9-
root / "scala-sbt-1.0"
9+
root / "scala-2.12"
1010
)
1111
}
1212
libraryDependencies ++= Dependencies.all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package scalafix.internal.sbt
2+
3+
import java.nio.file.Path
4+
5+
import sbt.*
6+
7+
object Compat {
8+
9+
def toPath(
10+
attributed: Attributed[File]
11+
): Path =
12+
attributed.data.toPath()
13+
14+
def toFile(
15+
attributed: Attributed[File]
16+
): File =
17+
attributed.data
18+
19+
def extractModuleID(
20+
attributed: Attributed[File]
21+
): Option[ModuleID] =
22+
attributed.get(Keys.moduleID.key)
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package scalafix.internal.sbt
2+
3+
import sbt.*
4+
import java.nio.file.Path
5+
6+
import xsbti.FileConverter
7+
import xsbti.HashedVirtualFileRef
8+
9+
object Compat {
10+
11+
def toPath(
12+
attributed: Attributed[HashedVirtualFileRef]
13+
)(using conv: FileConverter): Path =
14+
conv.toPath(attributed.data)
15+
16+
def toFile(
17+
attributed: Attributed[HashedVirtualFileRef]
18+
)(using conv: FileConverter): File =
19+
toPath(attributed).toFile()
20+
21+
def extractModuleID(
22+
attributed: Attributed[HashedVirtualFileRef]
23+
): Option[ModuleID] =
24+
attributed
25+
.get(Keys.moduleIDStr)
26+
.map(Classpaths.moduleIdJsonKeyFormat.read)
27+
}

src/main/scala/scalafix/internal/sbt/BlockingCache.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package scalafix.internal.sbt
22

3-
import java.{util => ju}
4-
53
import java.lang.ref.SoftReference
4+
import java.util as ju
65

76
/** A basic thread-safe cache with arbitrary eviction on GC pressure. */
87
class BlockingCache[K, V] {

src/main/scala/scalafix/internal/sbt/CoursierRepoResolvers.scala

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package scalafix.internal.sbt
22

3-
import coursierapi.{Credentials, IvyRepository, MavenRepository, Repository}
4-
import org.apache.ivy.plugins.resolver.IBiblioResolver
3+
import java.net.MalformedURLException
4+
import java.nio.file.Paths
5+
6+
import scala.jdk.CollectionConverters.*
7+
58
import sbt.librarymanagement.{Configuration as _, MavenRepository as _, *}
69
import sbt.util.Logger
710

8-
import java.net.MalformedURLException
9-
import java.nio.file.Paths
10-
import scala.collection.JavaConverters.*
11+
import coursierapi.Credentials
12+
import coursierapi.IvyRepository
13+
import coursierapi.MavenRepository
14+
import coursierapi.Repository
15+
import org.apache.ivy.plugins.resolver.IBiblioResolver
1116

1217
// vendor from sbt-coursier/lmcoursier.internal.Resolvers
1318
object CoursierRepoResolvers {
@@ -122,7 +127,7 @@ object CoursierRepoResolvers {
122127

123128
private object IBiblioRepository {
124129

125-
private def stringVector(v: java.util.List[_]): Vector[String] =
130+
private def stringVector(v: java.util.List[?]): Vector[String] =
126131
Option(v).map(_.asScala.toVector).getOrElse(Vector.empty).collect {
127132
case s: String => s
128133
}

src/main/scala/scalafix/internal/sbt/DependencyRule.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package scalafix.internal.sbt
22

3-
import sbt.ModuleID
43
import scala.util.matching.Regex
54

5+
import sbt.ModuleID
6+
67
case class DependencyRule(
78
ruleName: String,
89
dependency: ModuleID

src/main/scala/scalafix/internal/sbt/Implicits.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scalafix.internal.sbt
22

3-
import sbt.librarymanagement._
3+
import sbt.librarymanagement.*
4+
45
import scalafix.sbt.InvalidArgument
56

67
trait Implicits {

src/main/scala/scalafix/internal/sbt/JGitCompletions.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package scalafix.internal.sbt
22

3+
import java.nio.file.Path
4+
5+
import scala.jdk.CollectionConverters.*
6+
import scala.util.Try
7+
38
import org.eclipse.jgit.api.Git
49
import org.eclipse.jgit.lib.Constants.DOT_GIT
510
import org.eclipse.jgit.lib.RefDatabase
@@ -9,10 +14,6 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder
914
import org.eclipse.jgit.util.FS
1015
import org.eclipse.jgit.util.GitDateFormatter
1116

12-
import java.nio.file.Path
13-
import scala.collection.JavaConverters._
14-
import scala.util.Try
15-
1617
class JGitCompletion(cwd: Path) {
1718
private val isGitRepository =
1819
RepositoryCache.FileKey

src/main/scala/scalafix/internal/sbt/LoggingOutputStream.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package scalafix.internal.sbt
22

3-
import java.io.{ByteArrayOutputStream, OutputStream}
3+
import java.io.ByteArrayOutputStream
4+
import java.io.OutputStream
45

5-
import sbt.{Level, Logger}
6+
import sbt.Level
7+
import sbt.Logger
68

79
/** Split an OutputStream into messages and feed them to a given logger at a
810
* specified level. Not thread-safe.

0 commit comments

Comments
 (0)