🌐 AI搜索 & 代理 主页
Skip to content

Commit 2113d40

Browse files
committed
Use directories to locate repl history
1 parent 43de571 commit 2113d40

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

build.sbt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ val asmDep = "org.scala-lang.modules" % "scala-asm"
4343
val jlineDep = "org.jline" % "jline" % versionProps("jline.version")
4444
val jnaDep = "net.java.dev.jna" % "jna" % versionProps("jna.version")
4545
val jlineDeps = Seq(jlineDep, jnaDep)
46+
val directories = "dev.dirs" % "directories" % "26"
4647
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
4748
val diffUtilsDep = "io.github.java-diff-utils" % "java-diff-utils" % "4.12"
4849
val compilerInterfaceDep = "org.scala-sbt" % "compiler-interface" % "1.9.5"
@@ -491,6 +492,7 @@ lazy val compiler = configureAsSubproject(project)
491492
// These are only needed for the POM:
492493
// TODO: jline dependency is only needed for the REPL shell, which should move to its own jar
493494
libraryDependencies ++= jlineDeps,
495+
libraryDependencies += directories,
494496
buildCharacterPropertiesFile := (Compile / resourceManaged).value / "scala-buildcharacter.properties",
495497
Compile / resourceGenerators += generateBuildCharacterPropertiesFile.map(file => Seq(file)).taskValue,
496498
// this a way to make sure that classes from interactive and scaladoc projects
@@ -548,6 +550,7 @@ lazy val compiler = configureAsSubproject(project)
548550
|org.jline.terminal.spi;resolution:=optional
549551
|org.jline.utils;resolution:=optional
550552
|org.jline.builtins;resolution:=optional
553+
|dev.dirs;resolution:=optional
551554
|scala.*;version="$${range;[==,=+);$${ver}}"
552555
|*""".stripMargin.linesIterator.mkString(","),
553556
"Class-Path" -> "scala-reflect.jar scala-library.jar"
@@ -590,6 +593,7 @@ lazy val replFrontend = configureAsSubproject(project, srcdir = Some("repl-front
590593
.settings(publish / skip := true)
591594
.settings(
592595
libraryDependencies ++= jlineDeps,
596+
libraryDependencies += directories,
593597
name := "scala-repl-frontend",
594598
Compile / scalacOptions ++= Seq("-Xlint"),
595599
)
@@ -1105,6 +1109,7 @@ lazy val scalaDist = Project("scalaDist", file(".") / "target" / "scala-dist-dis
11051109
}.taskValue,
11061110
Compile / managedResourceDirectories := Seq((Compile / resourceManaged).value),
11071111
libraryDependencies ++= jlineDeps,
1112+
libraryDependencies += directories,
11081113
apiURL := None,
11091114
fixPom(
11101115
"/project/name" -> <name>Scala Distribution Artifacts</name>,
@@ -1267,6 +1272,7 @@ lazy val dist = (project in file("dist"))
12671272
.settings(
12681273
bspEnabled := false,
12691274
libraryDependencies ++= jlineDeps,
1275+
libraryDependencies += directories,
12701276
mkBin := mkBinImpl.value,
12711277
mkQuick := Def.task {
12721278
val cp = (testP / IntegrationTest / fullClasspath).value
@@ -1280,12 +1286,11 @@ lazy val dist = (project in file("dist"))
12801286
target := (ThisBuild / target).value / projectFolder.value,
12811287
Compile / packageBin := {
12821288
val targetDir = (ThisBuild / buildDirectory).value / "pack" / "lib"
1283-
val jlineJAR = findJar((Compile / dependencyClasspath).value, jlineDep).get.data
1284-
val jnaJAR = findJar((Compile / dependencyClasspath).value, jnaDep).get.data
1285-
val mappings = Seq(
1286-
(jlineJAR, targetDir / "jline.jar"),
1287-
(jnaJAR, targetDir / "jna.jar"),
1288-
)
1289+
val dcp = (Compile / dependencyClasspath).value
1290+
val jars = List("jline.jar" -> jlineDep, "jna.jar" -> jnaDep, "directories.jar" -> directories)
1291+
val mappings = jars.map {
1292+
case (filename, dep) => (findJar(dcp, dep).get.data, targetDir / filename)
1293+
}
12891294
IO.copy(mappings, CopyOptions() withOverwrite true)
12901295
targetDir
12911296
},

project/Osgi.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import VersionUtil.versionProperties
1010

1111
/** OSGi packaging for the Scala build, distilled from sbt-osgi.
1212
*
13-
* We don't use sbt-osgi (yet) because it does not allow a crucial bit of
14-
* configuration that we need: Setting the classpath for BND. In sbt-osgi this is always
15-
* `fullClasspath in Compile` whereas we want `products in Compile in packageBin`. */
13+
* We don't use sbt-osgi (yet) because it does not allow a crucial bit of
14+
* configuration that we need: Setting the classpath for BND. In sbt-osgi this is always
15+
* `fullClasspath in Compile` whereas we want `products in Compile in packageBin`.
16+
*/
1617
object Osgi {
1718
val bundle = TaskKey[File]("osgiBundle", "Create an OSGi bundle.")
1819
val bundleName = SettingKey[String]("osgiBundleName", "The Bundle-Name for the manifest.")

src/repl-frontend/scala/tools/nsc/interpreter/shell/ShellConfig.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import scala.sys.Prop._
2121
import scala.tools.nsc.{Properties, GenericRunnerSettings, Settings}
2222
import scala.tools.nsc.Properties._
2323

24+
import dev.dirs.ProjectDirectories
2425

2526
object ShellConfig {
26-
import scala.tools.nsc.Properties
2727

2828
val EDITOR = Properties.envOrNone("EDITOR")
2929
val InterruptedString = Properties.shellInterruptedString
@@ -65,7 +65,14 @@ trait ShellConfig {
6565
// This property is used in TypeDebugging. Let's recycle it.
6666
val colorOk = Properties.coloredOutputEnabled
6767

68-
val historyFile = s"$userHome/.scala_history_jline3"
68+
val datadir =
69+
try {
70+
val projectdirs = ProjectDirectories.from("org", "scala-lang", "repl2")
71+
projectdirs.dataLocalDir
72+
} catch {
73+
case _: UnsupportedOperationException => userHome
74+
}
75+
val historyFile = s"$datadir/.scala_history"
6976

7077
private val info = bool("scala.repl.info")
7178
private val debug = bool("scala.repl.debug")

0 commit comments

Comments
 (0)