Merge pull request #7980 from xuwei-k/Try-toIntOption

[2.x] use `toIntOption` instead of `scala.util.Try`
This commit is contained in:
adpi2 2024-12-30 10:00:23 +01:00 committed by GitHub
commit 2eba8e4e8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 5 additions and 8 deletions

View File

@ -22,7 +22,6 @@ import org.jline.terminal.impl.{ AbstractTerminal, DumbTerminal }
import org.jline.terminal.spi.{ SystemStream, TerminalProvider }
import sbt.internal.util.Terminal.hasConsole
import scala.jdk.CollectionConverters.*
import scala.util.Try
import java.util.concurrent.LinkedBlockingQueue
private[sbt] object JLine3 {
@ -279,7 +278,7 @@ private[sbt] object JLine3 {
chars.split(" ").foreach { keyValue =>
keyValue.split(",") match {
case Array(k, v) =>
Try(v.toInt).foreach(i => charMap.get(k).foreach(c => attributes.setControlChar(c, i)))
v.toIntOption.foreach(i => charMap.get(k).foreach(c => attributes.setControlChar(c, i)))
case _ =>
}
}

View File

@ -11,7 +11,6 @@ package sbt.internal.util
import java.io.InputStream
import java.nio.channels.ClosedChannelException
import java.util.concurrent.atomic.AtomicBoolean
import scala.util.Try
private[sbt] object ReadJsonFromInputStream {
def apply(
@ -55,7 +54,7 @@ private[sbt] object ReadJsonFromInputStream {
if (onCarriageReturn) consecutiveLineEndings += 1
onCarriageReturn = false
if (line.startsWith(contentLength)) {
Try(line.drop(contentLength.length).toInt) foreach { len =>
line.drop(contentLength.length).toIntOption foreach { len =>
def doDrainHeaders(): Unit =
inputStream.read match
case `newline` if onCarriageReturn =>

View File

@ -25,7 +25,6 @@ import sbt.io.syntax._
import sbt.librarymanagement._
import sbt.librarymanagement.syntax._
import sbt.nio.file.{ Glob, RecursiveGlob }
import scala.util.Try
object ScriptedPlugin extends AutoPlugin {
@ -77,7 +76,7 @@ object ScriptedPlugin extends AutoPlugin {
scriptedBatchExecution := {
val binVersion = CrossVersionUtil.binarySbtVersion(scriptedSbt.value)
val versionParts =
binVersion.split("\\.").flatMap(p => Try(p.takeWhile(_.isDigit).toInt).toOption).take(2)
binVersion.split("\\.").flatMap(p => p.takeWhile(_.isDigit).toIntOption).take(2)
versionParts match {
case Array(major, minor) => major > 1 || (major == 1 && minor >= 4)
case _ => false

View File

@ -140,7 +140,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
)
private val continuousParser: State => Parser[(Int, Seq[String])] = {
def toInt(s: String): Int = Try(s.toInt).getOrElse(0)
def toInt(s: String): Int = s.toIntOption.getOrElse(0)
// This allows us to re-enter the watch with the previous count.
val digitParser: Parser[Int] =

View File

@ -51,7 +51,7 @@ trait GCMonitorBase {
class GCMonitor(logger: Logger) extends GCMonitorBase with AutoCloseable {
override protected def window =
Try(System.getProperty("sbt.gc.monitor.window", "10").toInt).getOrElse(10).seconds
System.getProperty("sbt.gc.monitor.window", "10").toIntOption.getOrElse(10).seconds
override protected def ratio =
Try(System.getProperty("sbt.gc.monitor.ratio", "0.5").toDouble).getOrElse(0.5)