Fix scala 2 compat with -Xsource:3 and scala-collection-compat

This commit is contained in:
Adrien Piquerez 2024-03-05 13:24:31 +01:00
parent 0458e8063d
commit 369e647008
14 changed files with 35 additions and 46 deletions

View File

@ -55,7 +55,7 @@ Global / excludeLint += scriptedBufferLog
Global / excludeLint += checkPluginCross
ThisBuild / evictionErrorLevel := Level.Info
def commonBaseSettings: Seq[Setting[_]] = Def.settings(
def commonSettings: Seq[Setting[_]] = Def.settings(
headerLicense := Some(
HeaderLicense.Custom(
"""|sbt
@ -68,7 +68,7 @@ def commonBaseSettings: Seq[Setting[_]] = Def.settings(
scalaVersion := baseScalaVersion,
componentID := None,
resolvers += Resolver.typesafeIvyRepo("releases").withName("typesafe-sbt-build-ivy-releases"),
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
testFrameworks += TestFramework("hedgehog.sbt.Framework"),
testFrameworks += TestFramework("verify.runner.Framework"),
Global / concurrentRestrictions += Util.testExclusiveRestriction,
@ -101,20 +101,15 @@ def commonBaseSettings: Seq[Setting[_]] = Def.settings(
Test / publishArtifact := false,
run / fork := true,
)
def commonSettings: Seq[Setting[_]] =
commonBaseSettings :+ {
libraryDependencies ++= {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
Seq(compilerPlugin(kindProjector))
}
}
}
def utilCommonSettings: Seq[Setting[_]] = Def.settings(
baseSettings,
crossScalaVersions := Seq(scala212, scala213, scala3)
crossScalaVersions := Seq(scala212, scala213, scala3),
libraryDependencies += Dependencies.scalaCollectionCompat,
libraryDependencies ++= {
if (scalaBinaryVersion.value == "3") Nil
else Seq(compilerPlugin(kindProjector))
}
)
def minimalSettings: Seq[Setting[_]] =
@ -258,12 +253,12 @@ lazy val bundledLauncherProj =
/* ** subproject declarations ** */
val collectionProj = (project in file("util-collection"))
val collectionProj = project
.in(file("util-collection"))
.dependsOn(utilPosition, utilCore)
.settings(
name := "Collections",
testedBaseSettings,
baseSettings,
libraryDependencies ++= Seq(sjsonNewScalaJson.value),
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) if major <= 12 => Seq()
@ -349,7 +344,8 @@ lazy val utilCore = project
utilMimaSettings
)
lazy val utilLogging = (project in file("internal") / "util-logging")
lazy val utilLogging = project
.in(file("internal") / "util-logging")
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
.dependsOn(utilInterface, utilCore)
.settings(
@ -421,9 +417,9 @@ lazy val utilRelation = (project in file("internal") / "util-relation")
)
// Persisted caching based on sjson-new
lazy val utilCache = (project in file("util-cache"))
lazy val utilCache = project
.in(file("util-cache"))
.settings(
utilCommonSettings,
testedBaseSettings,
name := "Util Cache",
libraryDependencies ++=
@ -1044,7 +1040,7 @@ lazy val sbtClientProj = (project in file("client"))
.enablePlugins(NativeImagePlugin)
.dependsOn(commandProj)
.settings(
commonBaseSettings,
commonSettings,
publish / skip := true,
name := "sbt-client",
mimaPreviousArtifacts := Set.empty,

View File

@ -373,8 +373,6 @@ object ConsoleAppender {
}
private[sbt] def generateName(): String = "out-" + generateId.incrementAndGet
private[this] def ansiSupported: Boolean = Terminal.console.isAnsiSupported
}
// See http://stackoverflow.com/questions/24205093/how-to-create-a-custom-appender-in-log4j2

View File

@ -60,7 +60,7 @@ object ConsoleOut {
def systemOutOverwrite(f: (String, String) => Boolean): ConsoleOut = new ConsoleOut {
val lockObject: PrintStream = System.out
private[this] var last: Option[String] = None
private[this] var current = new java.lang.StringBuffer
private[this] val current = new java.lang.StringBuffer
def print(s: String): Unit = synchronized { current.append(s); () }
def println(s: String): Unit = synchronized { current.append(s); println() }
def println(): Unit = synchronized {
@ -128,7 +128,7 @@ object ConsoleOut {
case c => c
}
def printStreamOut(out: PrintStream): ConsoleOut = new ConsoleOut {
val lockObject = out
val lockObject: AnyRef = out
def print(s: String) = out.print(s)
def println(s: String) = out.println(s)
def println() = out.println()
@ -136,7 +136,7 @@ object ConsoleOut {
override def toString: String = s"PrintStreamConsoleOut($out)"
}
def printWriterOut(out: PrintWriter): ConsoleOut = new ConsoleOut {
val lockObject = out
val lockObject: AnyRef = out
def print(s: String) = out.print(s)
def println(s: String) = { out.println(s); flush() }
def println() = { out.println(); flush() }
@ -144,7 +144,7 @@ object ConsoleOut {
override def toString: String = s"PrintWriterConsoleOut($out)"
}
def bufferedWriterOut(out: BufferedWriter): ConsoleOut = new ConsoleOut {
val lockObject = out
val lockObject: AnyRef = out
def print(s: String) = out.write(s)
def println(s: String) = { out.write(s); println() }
def println() = { out.newLine(); flush() }

View File

@ -143,7 +143,6 @@ object EscHelpers {
*/
def strip(bytes: Array[Byte], stripAnsi: Boolean, stripColor: Boolean): (Array[Byte], Int) = {
val res = Array.fill[Byte](bytes.length)(0)
var i = 0
var index = 0
var state = 0
var limit = 0
@ -205,7 +204,6 @@ object EscHelpers {
def stripColorsAndMoves(s: String): String = {
val bytes = s.getBytes
val res = Array.fill[Byte](bytes.length)(0)
var i = 0
var index = 0
var state = 0
var limit = 0

View File

@ -31,8 +31,6 @@ private[sbt] object JLine3 {
private[this] val forceWindowsJansiHolder = new AtomicBoolean(false)
private[sbt] def forceWindowsJansi(): Unit = forceWindowsJansiHolder.set(true)
private[this] def windowsJansi(): org.jline.terminal.Terminal = {
val support = new JansiSupportImpl
val winConsole = support.isWindowsConsole();
val termType = sys.props.get("org.jline.terminal.type").orElse(sys.env.get("TERM")).orNull
val term = JansiWinSysTerminal.createTerminal(
"console",
@ -220,14 +218,6 @@ private[sbt] object JLine3 {
}
}
}
private def enterRawModeImpl(term: JTerminal): Attributes = {
val prvAttr = term.getAttributes()
val newAttr = new Attributes(prvAttr)
newAttr.setLocalFlags(EnumSet.of(LocalFlag.ICANON, LocalFlag.ECHO, LocalFlag.IEXTEN), false)
newAttr.setInputFlags(EnumSet.of(InputFlag.IXON, InputFlag.ICRNL, InputFlag.INLCR), false)
term.setAttributes(newAttr)
prvAttr
}
// We need to set the ENABLE_PROCESS_INPUT flag for ctrl+c to be treated as a signal in windows
// https://docs.microsoft.com/en-us/windows/console/setconsolemode
private[this] val ENABLE_PROCESS_INPUT = 1

View File

@ -107,7 +107,7 @@ private[sbt] final class ProgressState(
val parts = new String(bytes, "UTF-8").split(System.lineSeparator)
def appendLine(l: String, appendNewline: Boolean): Unit = {
toWrite ++= l.getBytes("UTF-8")
if (!l.getBytes("UTF-8").endsWith("\r")) toWrite ++= clearScreenBytes
if (!l.getBytes("UTF-8").endsWith("\r".getBytes)) toWrite ++= clearScreenBytes
if (appendNewline) toWrite ++= lineSeparatorBytes
}
parts.dropRight(1).foreach(appendLine(_, true))

View File

@ -7,7 +7,6 @@
package sbt.internal.util
import scala.language.experimental.macros
import scala.annotation.tailrec
import scala.reflect.macros.blackbox
import scala.reflect.internal.util.UndefinedPosition

View File

@ -8,6 +8,7 @@
package sbt.internal.util
import Relation._
import scala.collection.compat.*
object Relation {
@ -178,7 +179,7 @@ private final class MRelation[A, B](fwd: Map[A, Set[B]], rev: Map[B, Set[A]])
else new MRelation(add(fwd, from, to), to.foldLeft(rev)((map, t) => add(map, t, from :: Nil)))
def ++(rs: Iterable[(A, B)]) = rs.foldLeft(this: Relation[A, B]) { _ + _ }
def ++(other: Relation[A, B]) =
def ++(other: Relation[A, B]): Relation[A, B] =
new MRelation[A, B](combine(fwd, other.forwardMap), combine(rev, other.reverseMap))
def --(ts: Iterable[A]): Relation[A, B] = ts.foldLeft(this: Relation[A, B]) { _ - _ }

View File

@ -9,6 +9,9 @@ package sbt
package internal
package scripted
import java.{ util => ju }
import java.net.URL
final class FilteredLoader(parent: ClassLoader) extends ClassLoader(parent) {
@throws(classOf[ClassNotFoundException])
override final def loadClass(className: String, resolve: Boolean): Class[_] = {
@ -17,6 +20,6 @@ final class FilteredLoader(parent: ClassLoader) extends ClassLoader(parent) {
else
throw new ClassNotFoundException(className)
}
override def getResources(name: String) = null
override def getResource(name: String) = null
override def getResources(name: String): ju.Enumeration[URL] = null
override def getResource(name: String): URL = null
}

View File

@ -29,5 +29,5 @@ trait BasicStatementHandler extends StatementHandler {
/** Use when a stack trace is not useful */
final class TestFailed(msg: String) extends RuntimeException(msg) {
override def fillInStackTrace = this
override def fillInStackTrace: Throwable = this
}

View File

@ -133,6 +133,7 @@ object Dependencies {
}
)
val scalaPar = "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4"
val scalaCollectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0"
// specify all of log4j modules to prevent misalignment
def log4jModule = (n: String) => "org.apache.logging.log4j" % n % "2.17.1"

View File

@ -29,7 +29,8 @@ object HouseRulesPlugin extends AutoPlugin {
scalacOptions ++= "-Ywarn-dead-code".ifScala2.value.toList,
scalacOptions ++= "-Ywarn-numeric-widen".ifScala2.value.toList,
scalacOptions ++= "-Ywarn-value-discard".ifScala2.value.toList,
scalacOptions ++= "-Ywarn-unused-import".ifScala2x(v => 11 <= v && v <= 12).value.toList
scalacOptions ++= "-Ywarn-unused-import".ifScala2x(v => 11 <= v && v <= 12).value.toList,
scalacOptions ++= "-Xsource:3".ifScala2.value.toList
) ++ Seq(Compile, Test).flatMap(c =>
(c / console / scalacOptions) --= Seq("-Ywarn-unused-import", "-Xlint")
)

View File

@ -21,7 +21,9 @@ object PublishBinPlugin extends AutoPlugin {
override val globalSettings = Seq(publishLocalBin := (()))
override val projectSettings: Seq[Def.Setting[_]] = Def settings (
publishLocalBin := Classpaths.publishTask(publishLocalBinConfig).value,
publishLocalBin := Classpaths
.publishOrSkip(publishLocalBinConfig, publishLocalBin / skip)
.value,
publishLocalBinConfig := Classpaths.publishConfig(
false, // publishMavenStyle.value,
Classpaths.deliverPattern(crossTarget.value),

View File

@ -47,7 +47,7 @@ object SbtLauncherPlugin extends AutoPlugin {
val path = dir.toPath
f => if (f != dir) f -> path.relativize(f.toPath).toString :: Nil else Nil
}
IO.zip(dir.allPaths.get().flatMap(rebase), target)
IO.zip(dir.allPaths.get().flatMap(rebase), target, None)
}
target
}