Skip to content

Commit

Permalink
sbt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Oct 6, 2024
1 parent e9011a5 commit 3f14b3d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Compile / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "src" / "main" / "scala"
Compile / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "src" / "main" / "scala-2.12"

scalacOptions ++= Seq(
"-deprecation",
Expand Down
20 changes: 20 additions & 0 deletions src/main/scala-2.12/sbtjshell/JShellCompat.scala
Original file line number Diff line number Diff line change
@@ -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)
)
}
21 changes: 21 additions & 0 deletions src/main/scala-3/sbtjshell/JShellCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sbtjshell

import sbt.{Configuration, Def, given }
import sbt.Keys.fullClasspath
import sbt.Keys.fileConverter

private[sbtjshell] trait JShellCompat { self: JShellPlugin.type =>
import self.autoImport.*

def jshellFullClasspath(c: Configuration): Def.Setting[?] = {
(c / 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 / jshell / fullClasspath).value.map(x => converter.toPath(x.data).toFile)
}
}
14 changes: 6 additions & 8 deletions src/main/scala/sbtjshell/JShellPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package sbtjshell

import javax.tools.Tool
import java.util.ServiceLoader
import sbt._
import sbt.{_, given}
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")
Expand All @@ -30,14 +30,12 @@ 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("<arg>").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 {
Expand Down

0 comments on commit 3f14b3d

Please sign in to comment.