Skip to content

Commit 2d95306

Browse files
authored
Merge pull request #259 from BillyAutrey/scala-3-compat-fixes
Scala 3/sbt 2 prep
2 parents 0c486a8 + c915b62 commit 2d95306

File tree

22 files changed

+218
-85
lines changed

22 files changed

+218
-85
lines changed

.github/workflows/build-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
java: 17, 11, 8
2121
scala: 2.12.20
2222
cmd: |
23-
sbt ++$MATRIX_SCALA test ^scripted
23+
sbt ++$MATRIX_SCALA test scripted
2424
2525
finish:
2626
name: Finish

.github/workflows/format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
persist-credentials: false
1919

2020
- name: Check project is formatted
21-
uses: jrouly/scalafmt-native-action@v3
21+
uses: jrouly/scalafmt-native-action@v4
2222
with:
2323
arguments: '--list --mode diff-ref=origin/main'

.scalafmt.conf

+5
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ align.tokens."+" = [
2424
]
2525
}
2626
]
27+
fileOverride {
28+
"glob:**/scala-3/**" {
29+
runner.dialect = scala3
30+
}
31+
}

build.sbt

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ developers += Developer(
1111
url("https://github.com/playframework")
1212
)
1313

14+
lazy val scala212 = "2.12.20"
15+
lazy val scala3 = "3.3.4"
16+
ThisBuild / crossScalaVersions := Seq(scala212)
17+
1418
libraryDependencies ++= Seq(
1519
"org.webjars" % "webjars-locator-core" % "0.59",
1620
"org.specs2" %% "specs2-core" % "4.20.8" % "test",
@@ -26,3 +30,17 @@ Global / onLoad := (Global / onLoad).value.andThen { s =>
2630
dynverAssertTagVersion.value
2731
s
2832
}
33+
34+
(pluginCrossBuild / sbtVersion) := {
35+
scalaBinaryVersion.value match {
36+
case "2.12" => "1.10.2"
37+
case _ => "2.0.0-M2"
38+
}
39+
}
40+
41+
scalacOptions := {
42+
CrossVersion.partialVersion(scalaVersion.value) match {
43+
case Some((2, major)) => Seq("-Xsource:3")
44+
case _ => Seq.empty
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.typesafe.sbt
2+
3+
import sbt.*
4+
import sbt.Keys.Classpath
5+
import xsbti.FileConverter
6+
7+
import java.nio.file.{ Path => NioPath }
8+
9+
private[sbt] object PluginCompat {
10+
type FileRef = java.io.File
11+
type Out = java.io.File
12+
13+
def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
14+
a.data.toPath
15+
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
16+
a.data
17+
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
18+
cp.map(_.data.toPath()).toVector
19+
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
20+
cp.map(_.data).toVector
21+
def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to[Set]
22+
def classpathToFiles(classpath: Classpath)(implicit conv: FileConverter): Seq[FileRef] =
23+
classpath.files
24+
def toKey(settingKey: SettingKey[String]): AttributeKey[String] = settingKey.key
25+
def toNioPath(f: File)(implicit conv: FileConverter): NioPath =
26+
f.toPath
27+
def toFile(f: File)(implicit conv: FileConverter): File = f
28+
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
29+
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
30+
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.typesafe.sbt
2+
3+
import java.nio.file.{ Path => NioPath }
4+
import java.io.{ File => IoFile }
5+
import sbt.*
6+
import sbt.Keys.Classpath
7+
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile }
8+
9+
private[sbt] object PluginCompat:
10+
type FileRef = HashedVirtualFileRef
11+
type Out = VirtualFile
12+
13+
def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
14+
conv.toPath(a.data)
15+
inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
16+
toNioPath(a).toFile
17+
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] =
18+
cp.map(toNioPath).toVector
19+
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
20+
toNioPaths(cp).map(_.toFile)
21+
def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to(Set)
22+
inline def classpathToFiles(classpath: Classpath)(using conv: FileConverter): Seq[File] =
23+
toFiles(classpath.to(Seq))
24+
inline def toKey(settingKey: SettingKey[String]): StringAttributeKey = StringAttributeKey(settingKey.key.label)
25+
def toNioPath(hvf: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
26+
conv.toPath(hvf)
27+
def toFile(hvf: HashedVirtualFileRef)(using conv: FileConverter): File =
28+
toNioPath(hvf).toFile
29+
inline def toFileRef(file: File)(using conv: FileConverter): FileRef =
30+
conv.toVirtualFile(file.toPath)
31+
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
32+
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
33+
end PluginCompat

0 commit comments

Comments
 (0)