diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7c9ee..6eea18d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,4 +20,4 @@ jobs: java-version: "${{ matrix.java }}" distribution: temurin - uses: coursier/cache-action@v6 - - run: sbt -v scalafmtCheckAll scalafmtSbtCheck "^ test" + - run: sbt -v "+ scalafmtCheckAll" scalafmtSbtCheck "+ test" diff --git a/.scalafmt.conf b/.scalafmt.conf index 90e3ed3..6f91928 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,5 @@ runner.dialect = scala212source3 +project.layout = StandardConvention project.git = true maxColumn = 120 rewrite.rules = [SortImports] diff --git a/build.sbt b/build.sbt index b05feca..60f24a5 100644 --- a/build.sbt +++ b/build.sbt @@ -8,6 +8,17 @@ name := "sbt-jshell" sbtPlugin := true +crossScalaVersions += "3.3.4" + +pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + case "2.12" => + sbtVersion.value + case _ => + "2.0.0-M2" + } +} + sbtPluginPublishLegacyMavenStyle := { sys.env.isDefinedAt("GITHUB_ACTION") || isSnapshot.value } diff --git a/project/plugins.sbt b/project/plugins.sbt index 596a9a7..ba98cd1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,5 @@ Compile / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "src" / "main" / "scala" +Compile / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "src" / "main" / "scala-2" scalacOptions ++= Seq( "-deprecation", diff --git a/src/main/scala-2/sbtjshell/JShellCompat.scala b/src/main/scala-2/sbtjshell/JShellCompat.scala new file mode 100644 index 0000000..1296db1 --- /dev/null +++ b/src/main/scala-2/sbtjshell/JShellCompat.scala @@ -0,0 +1,20 @@ +package sbtjshell + +import sbt.{Configuration, Def, Task} +import sbt.Keys.fullClasspath +import java.io.File + +private[sbtjshell] trait JShellCompat { self: JShellPlugin.type => + import self.autoImport.* + + def jshellFullClasspath(c: Configuration): Def.Setting[?] = { + (c / jshell / fullClasspath) := { + (c / fullClasspath).value.filter(_.data.exists) + } + } + + def jshellFullClasspathValue(c: Configuration): Def.Initialize[Task[Seq[File]]] = + Def.task( + (c / jshell / fullClasspath).value.map(_.data) + ) +} diff --git a/src/main/scala-3/sbtjshell/JShellCompat.scala b/src/main/scala-3/sbtjshell/JShellCompat.scala new file mode 100644 index 0000000..dd5a4e3 --- /dev/null +++ b/src/main/scala-3/sbtjshell/JShellCompat.scala @@ -0,0 +1,20 @@ +package sbtjshell + +import sbt.{Configuration, Def, given} +import sbt.Keys.fullClasspath +import sbt.Keys.fileConverter + +private[sbtjshell] trait JShellCompat { self: JShellPlugin.type => + + def jshellFullClasspath(c: Configuration): Def.Setting[?] = { + (c / autoImport.jshell / fullClasspath) := { + val converter = fileConverter.value + (c / fullClasspath).value.filter(x => converter.toPath(x.data).toFile.exists) + } + } + + def jshellFullClasspathValue(c: Configuration) = Def.task { + val converter = fileConverter.value + (c / autoImport.jshell / fullClasspath).value.map(x => converter.toPath(x.data).toFile) + } +} diff --git a/src/main/scala/sbtjshell/JShellPlugin.scala b/src/main/scala/sbtjshell/JShellPlugin.scala index aaf2483..f2ee9f7 100644 --- a/src/main/scala/sbtjshell/JShellPlugin.scala +++ b/src/main/scala/sbtjshell/JShellPlugin.scala @@ -2,12 +2,14 @@ package sbtjshell import javax.tools.Tool import java.util.ServiceLoader -import sbt._ +// format: off +import sbt.{given, *} +// format: on import sbt.Keys._ import sbt.complete.DefaultParsers._ import scala.collection.JavaConverters._ -object JShellPlugin extends AutoPlugin { +object JShellPlugin extends AutoPlugin with JShellCompat { object autoImport { val jshell = inputKey[Int]("invoke jshell") @@ -30,14 +32,10 @@ object JShellPlugin extends AutoPlugin { override val projectSettings: Seq[Def.Setting[_]] = Def.settings( Seq(Compile, Test).flatMap { c => Def.settings( - (c / jshell / fullClasspath) := { - (c / fullClasspath).value.filter(_.data.exists) - }, + jshellFullClasspath(c), (c / jshell) := { val args = spaceDelimited("").parsed.toList - val path = (c / jshell / fullClasspath).value - .map(_.data.getCanonicalPath) - .mkString(System.getProperty("path.separator")) + val path = jshellFullClasspathValue(c).value.map(_.getCanonicalPath).mkString(java.io.File.pathSeparator) IO.withTemporaryFile("jshell-startup", ".jsh") { temp => val startup = (c / jshell / initialCommands).?.value match {