Skip to content

Commit ea8ff83

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

File tree

49 files changed

+398
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+398
-283
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-M4 \
12+
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"

build.sbt

+39-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,49 @@ libraryDependencies ++= List(
4442
"org.scalatest" %% "scalatest" % "3.2.19" % Test
4543
)
4644

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

4951
// 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"
52+
pluginCrossBuild / sbtVersion := {
53+
scalaBinaryVersion.value match {
54+
case "2.12" =>
55+
"1.4.0"
56+
case _ =>
57+
"2.0.0-M4" // bin/test-release.sh
58+
}
59+
}
5160

5261
scriptedSbt := {
5362
val jdk = System.getProperty("java.specification.version").toDouble
5463

5564
if (jdk >= 21)
56-
"1.9.0" // first release that supports JDK21
65+
Ordering[String].max(
66+
(pluginCrossBuild / sbtVersion).value,
67+
"1.9.0" // first release that supports JDK21
68+
)
5769
else
5870
(pluginCrossBuild / sbtVersion).value
5971
}
6072

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-
)
73+
scalacOptions ++= {
74+
scalaBinaryVersion.value match {
75+
case "2.12" =>
76+
List(
77+
"-Ywarn-unused",
78+
"-Xlint",
79+
"-Xfatal-warnings"
80+
)
81+
case _ =>
82+
List(
83+
"-Wunused:all",
84+
"-Werror"
85+
)
86+
}
87+
}
7088

7189
// Scripted
7290
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,30 @@
1+
package scalafix.internal.sbt
2+
3+
import java.io.File
4+
import java.nio.file.Path
5+
6+
import sbt.Attributed
7+
import sbt.Keys
8+
import sbt.ModuleID
9+
10+
import xsbti.FileConverter
11+
12+
object Compat {
13+
14+
def toPath(
15+
attributed: Attributed[File]
16+
)(implicit conv: FileConverter): Path =
17+
toFile(attributed).toPath()
18+
19+
def toFile(
20+
attributed: Attributed[File]
21+
)(implicit conv: FileConverter): File = {
22+
val _ = conv // avoid unused warning
23+
attributed.data
24+
}
25+
26+
def extractModuleID(
27+
attributed: Attributed[File]
28+
): Option[ModuleID] =
29+
attributed.get(Keys.moduleID.key)
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package scalafix.internal.sbt
2+
3+
import java.io.File
4+
import java.nio.file.Path
5+
6+
import sbt.Attributed
7+
import sbt.Classpaths
8+
import sbt.Keys
9+
import sbt.ModuleID
10+
11+
import xsbti.FileConverter
12+
import xsbti.HashedVirtualFileRef
13+
14+
object Compat {
15+
16+
def toPath(
17+
attributed: Attributed[HashedVirtualFileRef]
18+
)(using conv: FileConverter): Path =
19+
conv.toPath(attributed.data)
20+
21+
def toFile(
22+
attributed: Attributed[HashedVirtualFileRef]
23+
)(using conv: FileConverter): File =
24+
toPath(attributed).toFile()
25+
26+
def extractModuleID(
27+
attributed: Attributed[HashedVirtualFileRef]
28+
): Option[ModuleID] =
29+
attributed
30+
.get(Keys.moduleIDStr)
31+
.map(Classpaths.moduleIdJsonKeyFormat.read)
32+
}

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

0 commit comments

Comments
 (0)