Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt 2 #196

Merged
merged 1 commit into from
Oct 18, 2024
Merged

sbt 2 #196

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
runner.dialect = scala212source3
project.layout = StandardConvention
project.git = true
maxColumn = 120
rewrite.rules = [SortImports]
Expand Down
15 changes: 13 additions & 2 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 Expand Up @@ -103,9 +114,9 @@ releaseProcess := Seq[ReleaseStep](
updateReadmeProcess,
tagRelease,
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := false"),
releaseStepCommandAndRemaining("^ publishSigned"),
releaseStepCommandAndRemaining("+ publishSigned"),
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := true"),
releaseStepCommand("sonatypeBundleRelease"),
releaseStepCommandAndRemaining("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
updateReadmeProcess,
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"

scalacOptions ++= Seq(
"-deprecation",
Expand Down
19 changes: 19 additions & 0 deletions src/main/scala-2/sbtjshell/JShellCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sbtjshell

import sbt.{Configuration, Def, Task}
import sbt.Keys.fullClasspath
import java.io.File

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

def jshellFullClasspath(c: Configuration): Def.Setting[?] = {
(c / autoImport.jshell / fullClasspath) := {
(c / fullClasspath).value.filter(_.data.exists)
}
}

def jshellFullClasspathValue(c: Configuration): Def.Initialize[Task[Seq[File]]] =
Def.task {
(c / autoImport.jshell / fullClasspath).value.map(_.data)
}
}
22 changes: 22 additions & 0 deletions src/main/scala-3/sbtjshell/JShellCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sbtjshell

import sbt.{Configuration, Def, Task, given}
import sbt.Keys.fullClasspath
import sbt.Keys.fileConverter
import java.io.File

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.Initialize[Task[Seq[File]]] =
Def.task {
val converter = fileConverter.value
(c / autoImport.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,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")
Expand All @@ -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("<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