Skip to content

Commit

Permalink
Merge pull request #259 from BillyAutrey/scala-3-compat-fixes
Browse files Browse the repository at this point in the history
Scala 3/sbt 2 prep
  • Loading branch information
mkurz authored Oct 17, 2024
2 parents 0c486a8 + c915b62 commit 2d95306
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
java: 17, 11, 8
scala: 2.12.20
cmd: |
sbt ++$MATRIX_SCALA test ^scripted
sbt ++$MATRIX_SCALA test scripted
finish:
name: Finish
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
persist-credentials: false

- name: Check project is formatted
uses: jrouly/scalafmt-native-action@v3
uses: jrouly/scalafmt-native-action@v4
with:
arguments: '--list --mode diff-ref=origin/main'
5 changes: 5 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ align.tokens."+" = [
]
}
]
fileOverride {
"glob:**/scala-3/**" {
runner.dialect = scala3
}
}
18 changes: 18 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ developers += Developer(
url("https://github.com/playframework")
)

lazy val scala212 = "2.12.20"
lazy val scala3 = "3.3.4"
ThisBuild / crossScalaVersions := Seq(scala212)

libraryDependencies ++= Seq(
"org.webjars" % "webjars-locator-core" % "0.59",
"org.specs2" %% "specs2-core" % "4.20.8" % "test",
Expand All @@ -26,3 +30,17 @@ Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}

(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.10.2"
case _ => "2.0.0-M2"
}
}

scalacOptions := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) => Seq("-Xsource:3")
case _ => Seq.empty
}
}
31 changes: 31 additions & 0 deletions src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.typesafe.sbt

import sbt.*
import sbt.Keys.Classpath
import xsbti.FileConverter

import java.nio.file.{ Path => NioPath }

private[sbt] object PluginCompat {
type FileRef = java.io.File
type Out = java.io.File

def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
a.data
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
cp.map(_.data.toPath()).toVector
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
cp.map(_.data).toVector
def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to[Set]
def classpathToFiles(classpath: Classpath)(implicit conv: FileConverter): Seq[FileRef] =
classpath.files
def toKey(settingKey: SettingKey[String]): AttributeKey[String] = settingKey.key
def toNioPath(f: File)(implicit conv: FileConverter): NioPath =
f.toPath
def toFile(f: File)(implicit conv: FileConverter): File = f
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
}
33 changes: 33 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.typesafe.sbt

import java.nio.file.{ Path => NioPath }
import java.io.{ File => IoFile }
import sbt.*
import sbt.Keys.Classpath
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile }

private[sbt] object PluginCompat:
type FileRef = HashedVirtualFileRef
type Out = VirtualFile

def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
conv.toPath(a.data)
inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
toNioPath(a).toFile
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] =
cp.map(toNioPath).toVector
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
toNioPaths(cp).map(_.toFile)
def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to(Set)
inline def classpathToFiles(classpath: Classpath)(using conv: FileConverter): Seq[File] =
toFiles(classpath.to(Seq))
inline def toKey(settingKey: SettingKey[String]): StringAttributeKey = StringAttributeKey(settingKey.key.label)
def toNioPath(hvf: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
conv.toPath(hvf)
def toFile(hvf: HashedVirtualFileRef)(using conv: FileConverter): File =
toNioPath(hvf).toFile
inline def toFileRef(file: File)(using conv: FileConverter): FileRef =
conv.toVirtualFile(file.toPath)
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
end PluginCompat
Loading

0 comments on commit 2d95306

Please sign in to comment.